6.6 KiB
Configure your microphone and speakers - Raspberry Pi
For dis part of di lesson, you go add microphone and speakers to your Raspberry Pi.
Hardware
Raspberry Pi need microphone.
Di Pi no get microphone wey dey inside am, so you go need add external microphone. You fit do am in different ways:
- USB microphone
- USB headset
- USB all in one speakerphone
- USB audio adapter and microphone wey get 3.5mm jack
- ReSpeaker 2-Mics Pi HAT
💁 Bluetooth microphones no dey work well for Raspberry Pi, so if you get bluetooth microphone or headset, you fit get wahala to pair am or capture audio.
Raspberry Pi get 3.5mm headphone jack. You fit use am connect headphones, headset or speaker. You fit also add speakers using:
- HDMI audio through monitor or TV
- USB speakers
- USB headset
- USB all in one speakerphone
- ReSpeaker 2-Mics Pi HAT wey get speaker wey you fit attach, either to di 3.5mm jack or di JST port
Connect and configure di microphone and speakers
Di microphone and speakers need make you connect and configure dem.
Task - connect and configure di microphone
-
Connect di microphone using di correct method. For example, connect am through one of di USB ports.
-
If you dey use di ReSpeaker 2-Mics Pi HAT, you fit remove di Grove base hat, then put di ReSpeaker hat for di place.
You go need Grove button later for dis lesson, but one dey inside dis hat, so di Grove base hat no dey necessary.
Once you don fit di hat, you go need install some drivers. Check di Seeed getting started instructions for driver installation instructions.
⚠️ Di instructions dey use
gitto clone repository. If you no getgitfor your Pi, you fit install am by running dis command:sudo apt install git --yes -
Run dis command for your Terminal either for di Pi, or connect am using VS Code and remote SSH session to see info about di microphone wey you connect:
arecord -lYou go see list of microphones wey dey connect. E go look like dis:
pi@raspberrypi:~ $ arecord -l **** List of CAPTURE Hardware Devices **** card 1: M0 [eMeet M0], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0If you get only one microphone, you go see only one entry. Configuration of microphones fit hard for Linux, so e better make you use only one microphone and unplug any other one.
Write down di card number, you go need am later. For di output wey dey above, di card number na 1.
Task - connect and configure di speaker
-
Connect di speakers using di correct method.
-
Run dis command for your Terminal either for di Pi, or connect am using VS Code and remote SSH session to see info about di speakers wey you connect:
aplay -lYou go see list of speakers wey dey connect. E go look like dis:
pi@raspberrypi:~ $ aplay -l **** List of PLAYBACK Hardware Devices **** card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones] Subdevices: 8/8 Subdevice #0: subdevice #0 Subdevice #1: subdevice #1 Subdevice #2: subdevice #2 Subdevice #3: subdevice #3 Subdevice #4: subdevice #4 Subdevice #5: subdevice #5 Subdevice #6: subdevice #6 Subdevice #7: subdevice #7 card 1: M0 [eMeet M0], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0You go always see
card 0: Headphonesbecause na di headphone jack wey dey inside di Pi. If you add extra speakers, like USB speaker, you go see am for di list too. -
If you dey use extra speaker, and no be speaker or headphones wey connect to di headphone jack wey dey inside di Pi, you need configure am as di default. To do dis, run dis command:
sudo nano /usr/share/alsa/alsa.confDis go open configuration file for
nano, wey be terminal-based text editor. Use di arrow keys for your keyboard scroll down until you see dis line:defaults.pcm.card 0Change di value from
0to di card number of di card wey you wan use from di list wey come back from di call toaplay -l. For example, for di output wey dey above, e get second sound card wey becard 1: M0 [eMeet M0], device 0: USB Audio [USB Audio], wey dey use card 1. To use dis one, I go update di line to be:defaults.pcm.card 1Set dis value to di correct card number. You fit use di arrow keys for your keyboard navigate to di number, then delete and type di new number like normal when you dey edit text files.
-
Save di changes and close di file by pressing
Ctrl+x. Pressyto save di file, thenreturnto select di file name.
Task - test di microphone and speaker
-
Run dis command to record 5 seconds of audio through di microphone:
arecord --format=S16_LE --duration=5 --rate=16000 --file-type=wav out.wavAs dis command dey run, make noise into di microphone like talk, sing, beat box, play instrument or anything wey you like.
-
After 5 seconds, di recording go stop. Run dis command to play di audio:
aplay --format=S16_LE --rate=16000 out.wavYou go hear di audio wey dey play back through di speakers. Adjust di output volume for your speaker if e dey necessary.
-
If you need adjust di volume of di microphone port wey dey inside di Pi, or adjust di gain of di microphone, you fit use di
alsamixerutility. You fit read more about dis utility for di Linux alsamixer man page -
If you get errors to play di audio, check di card wey you set as di
defaults.pcm.cardfor dialsa.conffile.
Disclaimer:
Dis dokyument don dey translet wit AI translet service Co-op Translator. Even as we dey try make am correct, abeg make you sabi say translet wey machine do fit get mistake or no dey accurate. Di original dokyument for im native language na di one wey you go take as di correct source. For important mata, e good make you use professional human translet. We no go fit take blame for any misunderstanding or wrong interpretation wey fit happen because you use dis translet.
