Install Respeaker 4 Mic array and PyAudio script for audio recording - mmlabox/TeamAudio GitHub Wiki
Getting the Respeaker 4-Mic Array up and running on the Raspberry pi 4
The ReSpeaker 4-Mic Array is a quad-microphone expansion board for Raspberry Pi designed for AI and voice applications. We have used it to build and try out different frameworks and scripts to get the Speaker Diarization and Speaker Recognition working and optimized for the project.
Here is a quick walkthrough how to get it up and running on the Raspberry pi 4.
First you need to get your Raspberry pi up and running. We used the NOOBS (New OutOfBoxSoftware) operating system for my Raspberry pi. Follow this link to get it up and running[1]. When your OS is working you need to download and install seeed voice card source code and then install all linux kernel drivers.
Use these commands in the terminal:
- $ git clone https://github.com/respeaker/seeed-voicecard
- $ cd seeed-voicecard
- $ sudo ./install.sh
- $ sudo reboot
If a driver won’t compile with the latest kernel because of new patches, You might have to use the following command:
- $ sudo ./install.sh --compat-kernel
Check that the sound card name matches the source code seeed-voicecard. Use following command:
- $ arecord -L
Note the values displayed after the command may vary between different devices, but in our case it worked fine.
Now the ReSpeaker 4 Mic Array should be working and you are able to record sound.
Try to install Audacity to record sound and confirm your ReSpeaker works and is able to record sound and you may listen to the recording with Audacity.
- $ sudo apt update
- $ sudo apt install audacity
- $ audacity // run audacity
If problems occur with playing the recorded sound try following:
My device had problems to play the sound I recorded, I solved it by choosing File-> Export -> Export as MP3 in the Audacity interface. You can then listen to the Audio-file to confirm the recording worked.
PyAudio installation
To record sound we used the PyAudio library which has Python bindings for PortAudio, the cross-platform audio I/O library. With PyAudio, we use Python to play and record audio on a Raspberry pi 4.
- Note all packages and libraries related to this script needed to be installed with sudo command (admin privileges) since running a script containing keyboard library requires it.
To install pyAudio use the following commands depending your python version:
- $ sudo apt-get install python-pyaudio
- $ sudo apt-get install python3-pyaudio
Script to record audio on respeaker
To record an audio file (.wav) and save it with Python, pyAudio[2] and keyboard[3] has been used. PyAudio makes it possible to record audios with Python, and keyboard library is used to detect keyboard inputs from a user. This script has been created to work on Raspberry Pi with a ReSpeaker, but running it on a Mac or Windows computer should also work.
Installing keyboard Use the following command to install keyboard library and run the script, use the correct command depending your python version:
-
Python version 2
-
$ sudo pip install keyboard
-
$ sudo python app.py
-
Python version 3
-
$ sudo pip3 install keyboard
-
$ sudo python3 app.py
Quick install guide for the Script using the terminal:
-
$ git clone https://github.com/belismau/audio-recorder
-
$ cd audio-recorder
-
$ sudo pip install keyboard
-
$ sudo apt-get install python-pyaudio
-
Run script:
-
$ sudo python app.py
References
- [1] https://crosstalksolutions.com/getting-started-with-raspberry-pi-4/
- [2] https://people.csail.mit.edu/hubert/pyaudio/docs/
- [3] https://www.geeksforgeeks.org/keyboard-module-in-python/