[Raspberry Pi] Using PyAudio & External Audio Card for Recording

So, I had a project to work on, and my sole purpose was to record Audio using a Raspberry Pi and then encrypt it using Advance Encryption Standard.

Literally speaking, when I bought the Raspberry Pi for the first time i had no idea that there is no audio recording feature available in Raspberry Pi, I therefore, had to buy an external USB Audio card, which was capable of both Recording and Playback of audio files.

Here is the complete process to set up the environment for the first time for Audio recording,

After starting the Raspberry Pi, you are supposed to upgrade it to the latest version,

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install rpi-update
sudo rpi-update
sudo apt-get install python-dev

The reason is that, there is an issue with the Pi’s USB port that meant it could become overwhelmed with data which causes popping and bubbling noises to be included in your recordings, this can be fixed with an update of the Pi’s firmware.

The next step is to install PyAudio libraries,

$ sudo apt-get install git
$ git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
$ sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
$ sudo apt-get python-dev
$ sudo python pyaudio/setup.py install


Inside, PyAudio directory, there are certain example programs available to record or to play the Audio files, but at this point, you wouldn't be able to play or record anything since you haven't set your external audio card as default.

Now, Our next step is to do set our USB sound card to default.

This can be done by editing the "/etc/modprobe.d/alsa-base.conf" file, and setting the index value for usb card to 0.

The file can be edited using ed /etc/modprobe.d/alsa-base.conf

options snd-card-usb-caiaq index=0


Your device is now capable of performing both Audio Recording and Playback, the example programs are available inside PyAudio directory, You can modify the recording time and other parameters like, sampling time, buffer size from the example programs.

If you have any query than share it in the comment section below.
I shall be explaining the example programs and how to increase the recording quality in the next post.


Thank you.

5 comments:

  1. When are you gonna post next time? Also may I know what kind of mic did you use ? Thanks

    ReplyDelete
  2. Hello mate, I am busy with the Project that I am working on and I will pos soon. btw, What do you want to know ? I shall be glad to help.
    P.S, I used this sound card, http://gujranwala.olx.com.pk/usb-sound-card-iid-562538506

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. http://gujranwala.olx.com.pk/usb-sound-card-iid-562538506 is a 404 error. Can you just say the name of the card? Thanks.

    ReplyDelete


























































































































































  5. Hello,

    While installing opencv on raspberry pi, when the 'upgrade' step completed, I rebooted the module. Now it is showing the "Recorder 1 (raspberry) " on screen. and now it is not showing anything on screen. How to deal with this?! Please help.

    ReplyDelete