Voice Recording on Raspberry Pi

 

The purpose of this post is to record audio (e.g. voice) on Raspberry Pi with a microphone. Raspberry Pi doesn’t have mic input by default, so USB microphone or USB soundcard + 3.5 mm jack mic is required.

 

Example Setup

 

Steps
1. Setting Up
1-1. Connect the speakers into 3.5 mm audio jack.
1-2. Connect the USB mic into USB ports.
1-3. Boot up Raspberry Pi Board. If it’s not set up yet, please refer this post.
1-4. Make sure the speaker is working. The command below can be used for speaker output test. To end the test, press Ctrl-C.

speaker-test -t wav

1-5. Check if the mic is recognized as a recording device by this command:

arecord -l

If everything is fine, the result should be something like below.

**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
 Subdevices: 1/1
 Subdevice #0: subdevice #0

This means the USB mic is on “card 1”, “device 0”. This card number and device number will be used when you record.

 

2. Recording
2-1. Now you can start recording by “arecord” command, for example:

arecord -D hw:1,0 -d 5 -f cd test.wav -c 1

-D option specifies recording device. Since the mic is on “card 1”, “device 0” (see step 1-4), the value is “hw:1,0” here. This command creates “test.wav” as a 5-second, CD-quality wave file. Since it’s a mono mic, specify “1” as the number of channels with “-c” option. You can find the details of the options here.

Note:
If you find hundreds of files (test-01.wav, test-02.wav…) after the recording is done, please refer this troubleshooting.

Note:
I found that a hissing noise is introduced when the file is played through 3.5 mm audio jack on Raspberry Pi board, even though the recording quality itself is ok. So you may want to use HDMI sound output or a USB sound card to play the audio file.

 

3. Testing

3-1. Play the recorded file and make sure the recording is done properly.

aplay test.wav

*If the playback volume is too low (or high), you can check and change it with “amixer” command.

Check the current volume.

amixer

Below is an output example. In this case, the current vol is 77%.

$ amixer 
Simple mixer control 'PCM',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback -10239 - 400
  Mono: Playback -2000 [77%] [-20.00dB] [on]

Set the vol to 100%.

amixer set PCM 100%

 

Reference
– USB Audio Cards with a Raspberry Pi
https://cdn-learn.adafruit.com/downloads/pdf/usb-audio-cards-with-a-raspberry-pi.pdf

 

 

Sponsor Link

7 Comments

  1. when i execute the command(arecord -D hw:1,0 -d 5 -f cd test.wav -c 1) i get the following error:
    arecord:main:722:audio open error: device or resource busy

    1. Hi shanma,
      Is “hw:1,0” the correct device in your case? If so, it looks another process is already using it. What’s the output of fuser -fv /dev/snd/*? (reference)

  2. when run the record cmd i get Warning: rate is not accurate (requested = 44100Hz, got = 48000Hz)
    please, try the plug plugin

  3. “If everything is fine, the result should be like below….”
    my “arecord -l” shows nothing. (and my USB webcam + mic is plugged in to a USB slot on my Pi 4).

Comments are closed.