라즈베리 파이 arecord - lajeubeli pai arecord

arecord 및 aplay 사용방법

12 Aug 2017 | 라즈베리파이 리눅스

alsa-utils 설치

사운드를 녹음하는 arecord와 사운드를 재생하는 aplay 프로그램은 alsa-utils에 포함되어 있습니다.

sudo apt-get install alsa-utils

명령어로 두 프로그램을 설치할 수 있습니다.

arecord 사용법

arecord는 다음과 같이 사용할 수 있습니다.

arecord -t raw -c 1 -D plughw:1,0 -f S16_LE -d 5 -r 16000 test.pcm

-t 옵션은 타입으로 다음과 같은 타입을 가집니다.

  • voc
  • wav
  • raw
  • au

-c 옵션은 채널 개수를 의미합니다.

-D 옵션은 디바이스 이름을 의미하며, 위 예제에서는 plughw:1,0이라는 디바이스 이름을 사용했지만, 라즈베리파이에서는 보통 default라는 이름으로 세팅되어 있습니다.

-f 옵션은 포맷(format)을 의미하며 보통 S16_LE 값을 사용하면 됩니다.

-d는 ‘duration’을 의미합니다. 위와 같이 사용하면 5초 동안 녹음합니다.

-r 옵션은 ‘sample-rate’ 값입니다.

aplay 사용법

위에서 녹음한 파일을 재생할 때는 다음과 같은 옵션으로 재생하면 됩니다.

aplay -t raw -c 1 -f S16_LE -r 16000 test.pcm

옵션이 의미하는 바는 arecord와 같습니다.

만약 pcm 파일이 아닌 일반 wav 파일이면 그냥

으로 실행해도 됩니다. wav 파일 안에 헤더 정보가 들어있기 때문입니다.

At least with the CM-Headphone type adapter, you can also record audio.

 arecord --device=hw:1,0 --format S16_LE --rate 44100 -c1 test.wav

Will record signed 16-bit (S16_LE) audio at 44100 Hz (--rate 44100) mono (-c1) audio to test.wav. We've noted that any audio input will be echoed out the speakers as well

You can have a little VU meter show up if you add to the-V mono command line. Press control-C to quit

라즈베리 파이 arecord - lajeubeli pai arecord

Once you're done recording you can play back with

aplay --device=plughw:1,0 test.wav

This guide was first published on Sep 17, 2013. It was last updated on Sep 17, 2013.

This page (Recording Audio) was last updated on Oct 26, 2022.

Text editor powered by tinymce.

Recording audio with the Raspberry Pi opens up a wide variety of audio-based applications like voice recognition, voice control, and security systems.

라즈베리 파이 arecord - lajeubeli pai arecord

In this tutorial, we will walk through the steps of setting up a USB microphone on the Raspberry Pi, then see how to record audio from the microphone.

How to Connect a Microphone to the Raspberry Pi

There are four ways you can connect a microphone to the Raspberry Pi:

  • External sound card
  • Bluetooth
  • USB

External Sound Card

The first option is to connect a microphone through the microphone jack on an external sound card like the Audio Injector Sound Card. This is a Raspberry Pi HAT that sits on top of the Raspberry Pi. The microphone can be connected to the sound card with standard RCA plugs. This method will give the best audio quality.

Bluetooth

The second way to connect a microphone to the Raspberry Pi is with Bluetooth. Bluetooth microphones are the most seamless way to add a microphone as they don’t require a physical connection. Compatibility issues and unpredictable audio quality are downsides to using Bluetooth microphones. But the convenience of having a wireless microphone might make them worthwhile.

USB

USB microphones are probably the most reliable way to record audio with a Raspberry Pi. They are mostly plug and play, and work without any additional hardware or software. The sound quality of USB microphones can range from poor to professional quality. It all depends on the quality of your microphone. For example, a Blue Yeti USB microphone (around $100) records much higher quality sound than a generic USB microphone ($15).

How to Record Audio From the Microphone

Setting up a USB microphone using the Raspberry Pi Desktop is easy. Once you connect the microphone to the Raspberry Pi, the microphone will be detected automatically.

Recording Audio From the Desktop

To record audio from the desktop, open the Audio Device Settings by going to Preferences > Audio Device Settings. There you can change the microphone amplification with a handy slide controller. Press the red record button to start recording audio:

라즈베리 파이 arecord - lajeubeli pai arecord

Recording Audio From the Command Line

To record audio from the command line, first check the USB microphone’s connection by entering the following command:

lsusb

You should see an output similar to this:

라즈베리 파이 arecord - lajeubeli pai arecord

Bus 001 Device 002 is the USB microphone. With other Raspberry Pi models, this could show 2 to 5 devices.

To see the list of audio input devices, enter:

arecord -l

This output should be shown:

라즈베리 파이 arecord - lajeubeli pai arecord

So the microphone matches with card 1 and device 0. This will be mapped in the following with plughw:1,0.

Finally, we can start recording audio by entering the following command:

arecord -D plughw:1,0 --duration=60 test.wav

The term --duration=60 sets the duration of the recording in seconds. In this case the Raspberry Pi will record audio for 60 seconds. The recorded audio will be saved to the file “test.wav”.

The following output should appear:

라즈베리 파이 arecord - lajeubeli pai arecord

Alsamixer

Sometimes the volume of the recording will be low. In these cases, Alsamixer can helps us manage the microphone volume with a simple interface.

To open Alsamixer, type the following into the Raspberry Pi terminal:

alsamixer

You’ll see the default console:

라즈베리 파이 arecord - lajeubeli pai arecord

Now,  you have to switch to the correct audio device by pressing F6:

라즈베리 파이 arecord - lajeubeli pai arecord

In my case, the correct sound card is the one marked as bcm2835 ALSA:

라즈베리 파이 arecord - lajeubeli pai arecord

Now you can use the up and down arrow keys to change the volume of the microphone as needed. Press ESC to save and exit.

Hope this has helped you figure out how to record audio on the Raspberry Pi! Leave a comment below if you have questions about anything.

라즈베리 파이 arecord - lajeubeli pai arecord