How to set default microphone on Raspberry Pi 3B with Raspbian Stretch? - audio

So far I have not found any guides on how to set the default USB microphone for Stretch and so I've followed all of the guides for Wheezy and Jessie and they do not work.
Typing in the command arecord sound.wav does not record anything from the microphone. However, if I were to type in this command it would work arecord -f cd -D hw:1,0 -d 10 sound.wav.
Here is what appears when I enter in arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Headset [Plantronics Headset], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
I've edited this file /usr/share/alsa/alsa.conf and set the values to this
defaults.ctl.card 1
defaults.pcm.card 1
I've also edited the /etc/asoundrc file and changed it to this:
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm "hw:0,0"
}
capture.pcm {
type plug
slave.pcm "hw:1,0"
}
}
ctl.!default {
type hw
card 0
}
and this:
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
and it still does not work.

I've been having headaches with this one for about a day, but I finally made it work.
Your .asoundrc should actually look like this:
pcm.!default {
type asym
playback.pcm "plughw:0"
capture.pcm "plughw:1"
}
ctl.!default {
type hw
card 1
}
Otherwise your settings are ok, but I think this command is wrong:
arecord sound.wav
The proper command for testing the mic (or at least the one that works for me) is this:
arecord -D plughw:1,0 --duration=3 test.wav && aplay test.wav
This is setup for a 3 seconds recording and after recording stops it automatically plays back to you (assuming your audio also works).
This part plughw:1,0 points to your mic, which I see is set to card 1.
I you have created this file /etc/modprobe.d/alsa-base.conf during your tests please delete it and reboot your pi.
sudo rm -f /etc/modprobe.d/alsa-base.conf
Also if you have tried this for the AlexaPi project, make sure the service is stopped before you try your mic and audio.
sudo systemctl stop AlexaPi.service

Related

.asoundrc ALSA configuration for webcam

I'm an ALSA beginner in the process of setting up my .asoundrc to record audio from my webcam.
Here is what I did to determine that my hardware is actually working:
I'm able to output sound using the following basic .asoundrc
defaults.pcm.!card Generic
defaults.pcm.!device 0
defaults.pcm.!ctl Generic
And I successfully recorded a test from my webcam with the following command
arecord --device=hw:0,0 --duration=5 --format=S16_LE /tmp/test.wav
Then, using a rudimentary knowledge of ALSA configuration, I wrote the following .asoundrc
pcm.!default {
type asym
playback.pcm {
type hw
card Generic
device 0
}
capture.pcm {
type hw
card 0
device 0
}
}
However, this results in no sound output or recording functionality. Please help me understand why this is not working.
output of aplay -l
output of arecord -l

amixer controls won't get anything on my development board

I am trying to set volume on the minilinux system with amixer controls in development board,but it won't get anything.
~ # amixer
~ #
~ # amixer controls
~ #
I have tried to create a plugin by create this file in "/etc/asound.conf"as this How_to_use_softvol_to_control_the_master_volumesaid ,by type in this
pcm.softvol {
type softvol
slave {
pcm "hw:0,0"
}
control {
name "softctl"
card 0
}
}
but when testing it ,give me this error:
/etc # speaker-test -D softvol -c 2 &
/etc #
speaker-test 1.1.5
Playback device is softvol
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM softvol
Playback open error: -2,No such file or directory
when I changed the asound.conf to something like this:
pcm.softvol {
type hw
card 0
device 0
}
then exac " speaker-test -D softvol -c 2 & " the headphone have that pink noise.
This is really weird that I can play and record excpet control the volume. New to this,no idea what to do next.

raspberry pi / aplay / default sound card

I purchased a the "Sound Blaster Play! 2" soundcard for my raspberry pi 3. The OS is raspbian jessie.
The audio on my raspberry pi works when I run
$ aplay /usr/share/sounds/alsa/Front_Center.wav -D sysdefault:CARD=S2
But only when I use -D. When I use
$ aplay /usr/share/sounds/alsa/Front_Center.wav
it shows:
aplay: set_params:1239: Channels count non available
I need this for node-speaker.
Here is the output of the ALSA Information script: http://www.alsa-project.org/db/?f=bdefa248fdedb34929d492e65ea941f2af40dcb2
OK, I found the solution..
My new ~/.asoundrc:
pcm.!default {
type plug
slave {
pcm "hw:0,0"
}
}
ctl.!default {
type hw
card 0
}
instead of
pcm.!default {
type hw
card 0
}
ctl.!default {
type hw
card 0
}
does the magic :)

alsa tool arecord not recognizing plughw:1,0 on Arch Linux

Edit: All of this was probably caused by a terribly configured microphone (or a faulty one, I changed laptops and now use Ubuntu instead of Arch Linux, so I actually don't have any idea). To record to a wav file, all I do now is run:
arecord -d $DURATION -f cd -t wav $OUTPUT_FILE_PATH
...replacing $DURATION with the duration of the recording in seconds, and $OUTPUT_FILE_PATH with the path to the desired file to write. I omitted the -D sysdefault argument as it caused problems for me (as with most things, your mileage may vary, so if the command doesn't work for you, try playing with several variables until it works).
Goes without saying, but all of this requires alsa-utils to be installed.
(The original question is left below, for those that still want to see it.)
Tl;dr version: arecord not recognizing plughw:1,0 , nor hw:1,0 , nor anything without the -D option
Whole story: I'm trying to make a simple voice assistant using a Bash script (I don't find Python/Perl easy for me to use, but that's just me). Dialogs are made in Zenity/KDialog. Voice recognition isn't included yet, so one has to type in the phrase/command. For now the program is represented in Spanish, but I plan to have an English version as well.
Doing my research, I found: http://blog.oscarliang.net/raspberry-pi-voice-recognition-works-like-siri/
But it doesn't work correctly on my machine.
[owner#arch-hp-2000-notebook-pc ~]$ ~/test-speech-input
“Recording… Press Ctrl+C to Stop.”
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM “plughw:1,0″
arecord: main:722: audio open error: No such file or directory
“Processing…”
^C
[owner#arch-hp-2000-notebook-pc ~]$
It apparently has to do with the arecord -D "plughw:1,0" -q -f cd -t wav part.
Output of arecord -l:
[owner#arch-hp-2000-notebook-pc ~]$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Generic_1 [HD-Audio Generic], device 0: ALC269VC Analog [ALC269VC Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
Output of arecord -L:
[owner#arch-hp-2000-notebook-pc ~]$
null
Discard all samples (playback) or generate zero samples (capture)
pulse
PulseAudio Sound Server
default
Default ALSA Output (currently PulseAudio Sound Server)
sysdefault:CARD=Generic_1
HD-Audio Generic, ALC269VC Analog
Default Audio Device
front:CARD=Generic_1,DEV=0
HD-Audio Generic, ALC269VC Analog
Front speakers
surround21:CARD=Generic_1,DEV=0
HD-Audio Generic, ALC269VC Analog
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Generic_1,DEV=0
HD-Audio Generic, ALC269VC Analog
4.0 Surround output to Front and Rear speakers
surround41:CARD=Generic_1,DEV=0
HD-Audio Generic, ALC269VC Analog
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Generic_1,DEV=0
HD-Audio Generic, ALC269VC Analog
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Generic_1,DEV=0
HD-Audio Generic, ALC269VC Analog
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Generic_1,DEV=0
HD-Audio Generic, ALC269VC Analog
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
[owner#arch-hp-2000-notebook-pc ~]$
Following the first part of the answer by #CharlesDuffy (thanks for the help):
[owner#arch-hp-2000-notebook-pc ~]$ ~/test-speech-input
Recording… Press Ctrl+C to Stop.
Processing…
You Said: [owner#arch-hp-2000-notebook-pc ~]$
Following the new answer, also by #CharlesDuffy (although this system is all AMD I think, no intel):
[owner#arch-hp-2000-notebook-pc ~]$ test-speech-input
Recording… Press Ctrl+C to Stop.
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM CARD=Generic_1
arecord: main:722: audio open error: No such file or directory
Processing…
You Said: [owner#arch-hp-2000-notebook-pc ~]$
Following the newest answer by #CharlesDuffy:
[owner#arch-hp-2000-notebook-pc ~]$
Recording… Press Ctrl+C to Stop.
ALSA lib pcm_dsnoop.c:614:(snd_pcm_dsnoop_open) unable to open slave
arecord: main:722: audio open error: No such file or directory
Processing…
^C
[owner#arch-hp-2000-notebook-pc ~]$
Double-checked the volume of the internal mic, and it seemed to have selected a non-existent mic. Switching to the real mic yielded the same results.
I'm lost right now. Any other ideas? Is there any other command-line voice recording tool that might work or that might be easier to use (at least for me)?
Machine: HP 2000 Notebook PC, Arch Linux, uname -a returns Linux HOST_NAME 4.1.2-2-ARCH #1 SMP PREEMPT Wed Jul 15 08:30:32 UTC 2015 x86_64 GNU/Linux
The plughw:1,0 suggestion is specific to Raspberry Pi hardware, and doesn't necessarily apply elsewhere.
The first thing I'd suggest is removing the -D DEVICE argument entirely.
If that doesn't work, I'd suggest trying:
-D sysdefault
...for your basic on-board audio, as listed by arecord -L.

How do I configure JACK audio server to automatically use a specific card?

I'm running Ubuntu 12.04 studio on a HP Pavilion dm1 4200sg netbook. It's pretty much a fresh install. I try to start jackd server by running
jackd -R -d alsa
and it fails with output:
JACK server starting in realtime mode with priority 10
control device hw:0
control device hw:0
audio_reservation_init
Acquire audio card Audio0
creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
control device hw:0
ALSA: Cannot open PCM device alsa_pcm for playback. Falling back to capture-only mode
Cannot initialize driver
JackServer::Open() failed with -1
Failed to open server
Running aplay -l gives the following output:
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: SB [HDA ATI SB], device 0: STAC92xx Analog [STAC92xx Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
I find that by running
jackd -R -d alsa -d hw:1
jackd starts successfully. I would like to configure my machine so that hw:1 is the default option (i.e. to make the original 'jackd -R -d alsa' command work). Can anyone help me to do this?
I've tried editing ~/.asoundrc to be
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
but this doesn't seem to work. I'm well out of my comfort zone here and any help would be appreciated. Thanks!
I've found a workaround. It doesn't configure JACK server but alters the order the sound cards are listed.
I first entered into the terminal:
sudo lshw -c multimedia
which showed which modules the two cards were using. They were both using 'snd-hda-intel'.
I then entered into the terminal:
cat /proc/asound/card0/id
cat /proc/asound/card1/id
Which gave ids 'Generic' and 'SB' for cards 0 and 1, respectively.
I then added the following two lines to the end of the file '/etc/modprobe.d/alsa-base.conf'
options snd-hda-intel id=SB index=0
options snd-hda-intel id=Generic index=1
After rebooting the machine, card 'SB' was loaded into position 0 and
jackd -R -d alsa
correctly started.
First, in a terminal window, run this command:
cat /proc/asound/cards.
You’ll see output a bit like this:
0 [SB ]: HDA-Intel - HDA ATI SB
HDA ATI SB at 0xfcef8000 irq 16
1 [DSP ]: H-DSP - Hammerfall DSP
RME Hammerfall DSP + Digiface at 0xfcff0000, irq 20
2 [NVidia ]: HDA-Intel - HDA NVidia
HDA NVidia at 0xfe57c000 irq 32
The “name” of each soundcard is in square brackets.
With this information, you can now refer to a particular device as, for example hw:DSP now you can execute the command:
jackd -d alsa -d hw:DSP
And thats all, taken from:
http://www.jackaudio.org/faq/device_naming.html
EDIT: added code tags
First, open up alsa-base.conf:
sudo gedit /etc/modprobe.d/alsa-base.conf
Find the following line:
"options snd-hda-intel index=-2"
And change it to:
"#options snd-hda-intel index=-2"
Restart your machine and try again. You may have to set the proper sound device (alsa) for your programs.

Resources