Raspberry Pi: audio processing
Audio Input and Output from USB Microphone + Raspberry Pi
Install the device
Use Logitech Webcam C270 HD as the tested device:- 最大解析埠: 720p/30fps
- 對焦類型: 固定焦距
- 鏡頭技術: 標準
- 內建麥克風: 單聲道
pi@raspberrypi:~/MJPG-streamer/mjpg-streamer $ lsusb
Bus 001 Device 004: ID 046d:0825 Logitech, Inc. Webcam C270
Bus 001 Device 005: ID 0424:7800 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@raspberrypi:~/MJPG-streamer/mjpg-streamer $ lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/3p, 480M
|__ Port 1: Dev 5, If 0, Class=Vendor Specific Class, Driver=lan78xx, 480M
|__ Port 2: Dev 4, If 0, Class=Video, Driver=uvcvideo, 480M
|__ Port 2: Dev 4, If 3, Class=Audio, Driver=snd-usb-audio, 480M
|__ Port 2: Dev 4, If 1, Class=Video, Driver=uvcvideo, 480M
|__ Port 2: Dev 4, If 2, Class=Audio, Driver=snd-usb-audio, 480M
Install audio tools
We will be using the Python library ‘pyaudio’ to record and play audio data from the USB mic.
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo pip3 install pyaudio
sudo pip install numpy
Test
Find the sound device's information
pi@raspberrypi:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 7/7
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: U0x46d0x825 [USB Device 0x46d:0x825], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
pi@raspberrypi:~ $ amixer -c 1 info
Card hw:1 'U0x46d0x825'/'USB Device 0x46d:0x825 at usb-3f980000.usb-1.2, high speed'
Mixer name : 'USB Mixer'
Components : 'USB046d:0825'
Controls : 3
Simple ctrls : 1
Control the volume of a specific sound device
For ex., configure the card#1:
alsamixer -c 1
Record for three seconds and play it
arecord -D plughw:1,0 -d 3 test.wav
aplay test.wav
留言