Stay organized with collections
Save and categorize content based on your preferences.
The content on this page is hardware-dependent. Please select from the following:
Before running the sample, you must configure the audio system on the
Raspberry Pi.
Find your recording and playback devices.
Locate your USB microphone in the list of capture hardware devices. Write
down the card number and device number.
arecord -l
Locate your speaker in the list of playback hardware devices. Write down
the card number and device number. Note that the 3.5mm-jack is typically
labeled Analog or bcm2835 ALSA (not bcm2835 IEC958/HDMI).
aplay -l
Create a new file named .asoundrc in the home directory (/home/pi). Make
sure it has the right slave definitions for microphone and speaker; use the
configuration below but replace <card number> and <device number> with
the numbers you wrote down in the previous step. Do this for both pcm.mic
and pcm.speaker.
Press the up arrow key to set the playback volume level to around 70.
Play a test sound (this will be a person speaking). Press Ctrl+C when
done. If you don't hear anything when you run this, check your speaker
connection.
Check the recording by replaying it. If you don't hear anything, you may
need to check the recording volume in alsamixer.
aplay --format=S16_LE --rate=16000 out.raw
If recording and playback are working, then you are done configuring audio.
If not, check that the microphone and speaker are properly connected. If
this is not the issue, then try a different microphone or speaker.
Note that if you have both an HDMI monitor and a 3.5mm jack speaker
connected, you can play audio out of either one. Run the following command:
sudo raspi-config
Go to Advanced options > Audio and select the desired output device.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["\u003cp\u003eThis guide provides instructions to configure audio input and output on a Raspberry Pi for use with the sample.\u003c/p\u003e\n"],["\u003cp\u003eUsers need to identify their microphone and speaker using \u003ccode\u003earecord -l\u003c/code\u003e and \u003ccode\u003eaplay -l\u003c/code\u003e commands to obtain card and device numbers.\u003c/p\u003e\n"],["\u003cp\u003eAn \u003ccode\u003e.asoundrc\u003c/code\u003e file is created in the home directory, requiring specific configurations with obtained card and device numbers for proper audio routing.\u003c/p\u003e\n"],["\u003cp\u003eAudio functionality is verified using \u003ccode\u003ealsamixer\u003c/code\u003e, \u003ccode\u003espeaker-test\u003c/code\u003e, \u003ccode\u003earecord\u003c/code\u003e, and \u003ccode\u003eaplay\u003c/code\u003e commands, with troubleshooting tips for potential issues.\u003c/p\u003e\n"],["\u003cp\u003eHDMI and 3.5mm jack audio output selection can be managed through the Raspberry Pi's configuration settings.\u003c/p\u003e\n"]]],[],null,["The content on this page is hardware-dependent. Please select from the following: \nRaspberry Pi 3 Other platforms\nBefore running the sample, you must configure the audio system on the Raspberry Pi.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n1. Find your recording and playback devices.\n\n 1. Locate your USB microphone in the list of capture hardware devices. Write\n down the card number and device number.\n\n ```\n arecord -l\n ```\n\n \u003cbr /\u003e\n\n 2. Locate your speaker in the list of playback hardware devices. Write down\n the card number and device number. Note that the 3.5mm-jack is typically\n labeled `Analog` or `bcm2835 ALSA` (not `bcm2835 IEC958/HDMI`).\n\n ```\n aplay -l\n ```\n\n \u003cbr /\u003e\n\n2. Create a new file named `.asoundrc` in the home directory (`/home/pi`). Make\n sure it has the right slave definitions for microphone and speaker; use the\n configuration below but replace `\u003ccard number\u003e` and `\u003cdevice number\u003e` with\n the numbers you wrote down in the previous step. Do this for both `pcm.mic`\n and `pcm.speaker`.\n\n pcm.!default {\n type asym\n capture.pcm \"mic\"\n playback.pcm \"speaker\"\n }\n pcm.mic {\n type plug\n slave {\n pcm \"hw:\u003ccard number\u003e,\u003cdevice number\u003e\"\n }\n }\n pcm.speaker {\n type plug\n slave {\n pcm \"hw:\u003ccard number\u003e,\u003cdevice number\u003e\"\n }\n }\n\n3. Verify that recording and playback work:\n\n 1. Adjust the playback volume.\n\n ```\n alsamixer\n ```\n\n \u003cbr /\u003e\n\n Press the up arrow key to set the playback volume level to around 70.\n 2. Play a test sound (this will be a person speaking). Press Ctrl+C when\n done. If you don't hear anything when you run this, check your speaker\n connection.\n\n ```\n speaker-test -t wav\n ```\n\n \u003cbr /\u003e\n\n 3. Record a short audio clip.\n\n ```\n arecord --format=S16_LE --duration=5 --rate=16000 --file-type=raw out.raw\n ```\n\n \u003cbr /\u003e\n\n 4. Check the recording by replaying it. If you don't hear anything, you may\n need to check the recording volume in `alsamixer`.\n\n ```\n aplay --format=S16_LE --rate=16000 out.raw\n ```\n\n \u003cbr /\u003e\n\n If recording and playback are working, then you are done configuring audio.\n If not, check that the microphone and speaker are properly connected. If\n this is not the issue, then try a different microphone or speaker.\n\n Note that if you have both an HDMI monitor and a 3.5mm jack speaker\n connected, you can play audio out of either one. Run the following command: \n\n ```\n sudo raspi-config\n ```\n\n Go to **Advanced options \\\u003e Audio** and select the desired output device.\n\nNext step\n\n[Configure a Developer Project and Account Settings](/assistant/sdk/guides/service/python/embed/config-dev-project-and-account)"]]