audio - 我要在此代码中添加些什么,以使音频通过Arduino在PC扬声器中播放?

标签 audio io processing arduino javasound

我正在Arduino上运行此代码。使用Arduino,是否可以将音频传递到PC扬声器?

//This imports the audio class
#include <PCM.h>

//This is the sound being played
const unsigned char sound1[] PROGMEM = {129, 127, 126, 127, 128, 128, 128, 12};

//constant variables
const int knockSensor = A0;
const int threshold1 = 10;

//This create a variable
int sensorReading = 0;

void setup() {
    Serial.begin(9600);
}

void loop() {
    sensorReading = analogRead(knockSensor);
    if (sensorReading >= threshold1) {
        Serial.println(threshold1);
        startPlayback(sound1, sizeof(sound1));
    }

    delay(200);
}

最佳答案

假设Arduino板未物理连接到PC,则应通过Serial将Arduino读取的值发送到PC。在PC上运行的程序将通过seria端口获取此值,然后可以使用操作系统以声音形式播放该数据。如果您使用的是Linux,那么将数据写入/ dev / audio会非常容易

关于audio - 我要在此代码中添加些什么,以使音频通过Arduino在PC扬声器中播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9610645/

相关文章:

javascript - 如何调整 meSpeak.js 以获得更好的声音?

php - PHP 中的语音识别?

c++ - 我如何在C++中输入和输出各种文件类型

java - 学校项目,数组索引越界异常: 2

processing - 如何使这个 bool 值正确?

python - 如何设置具有 calysto 处理功能的 Jupyter 笔记本以在 Binder 中运行?

python - 波形文件如何存储多个 channel ?

ios - 在 iOS 上是否有替代 opencore amr 将 wav 转换为 amr 的方法?

c# - 串口未授权访问异常

C - 将结构写入文件 (.pcap)