樹莓派(USB麥克風和麥克風陣列) 錄音和播放

因pyaudio錄音有各種問題,所以儘量不用它。用arecord。樹莓派只有音頻輸出口,沒有錄入口,需要免驅動的USB麥克風或者麥克風陣列模塊(raspeaker),我用的是後者。
arecord –l
通過如上命令可以得到可用於錄音的設備,比如card x device x
arecord -Dhw:1,0 -d 10 -f cd -r 44100 -c 2 -t wav test.wav
參數解析
-D 指定了錄音設備,0,1 是card 0 device 1的意思,也就是TDM_Capture
-d 指定錄音的時長,單位時秒
-f 指定錄音格式,通過上面的信息知道只支持 cd cdr dat
-r 指定了採樣率,單位時Hz
-c 指定channel 個數
-t 指定生成的文件格式
————————————————
原文鏈接:https://blog.csdn.net/xiongtiancheng/article/details/80577478

由於訓練語料均採用16khz、16bit的單通道WAV格式的語音文件所以以下參數經常用,
使用arecord錄製16khz、16bit語音,測試是否在pi目錄下有語料生成
arecord -D “plughw:1,0” -f S16_LE -d 2 -r 16000 /home/pi/test.wav
測試播放語音功能也可以使用omxplayer:
omxplayer -o local /home/pi/test.wav

以下是個人實踐成果(麥克風陣列):

arecord -d 3 -c 2 -r 44100 -f S16_LE xiaoben.wmv
錄音3s,自動退出進程並在當前目錄下生成xiaoben.wmv文件,然後可以放了:
aplay xiaoben.wmv

如果是USB麥克風的話,需要改一下硬件配置,才能用上句。

To configure the microphone and speaker

Create and open the ~/.asoundrc file by typing the following command in the terminal: sudo nano ~/.asoundrc.
Add these lines to the file and save it (CTRL + O).
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm “hw:0,0”
}
capture.pcm {
type plug
slave.pcm “hw:1,0”
}
}
To ensure the microphone is capturing audio data, run the following command.

sudo apt-get install sox -y && rec test.wav
This command might install some extra audio dependencies. After it finishes, you should see a message indicating that audio is recording. It’s working if you see a running minute counter that is incrementing by the second. It looks similar to the following command.

In: 0.00% 00:00:01 [00:00:00:00] out:0.00M [ | ] clip:0

To exit the sound test, type CTRL + C
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章