ALSA issue `OSError: [Errno -9997] Invalid sample rate`

Over the past few days (around 4 days), we’ve received several reports of Mycroft, across multiple devices and distros being unable to understand audio input, often failing with the error;
OSError: [Errno -9997] Invalid sample rate

We don’t know why this is occurring, but @krisgesling has found a solution by editing ./asoundrc, via an Alexa issue:

pcm.!default { type asym playback.pcm 
    { type plug slave.pcm "hw:0" } 
    capture.pcm { type plug slave.pcm "hw:1" } 

Please let us know if this works for you (and big ups @krisgesling)


In case anyone is using it in a multi-user situation, the asound config file can live at either:
~/.asoundrc for a single user; or
/etc/asound.conf as a system wide configuration.


i installed picroft for the first time today and had “error -9997”. my speakers worked but not the microphone (blue snowball). so i tried to edit ./asoundrc (it was empty?) but after that my speakers where not working anymore. it says now ./asoundrc is corrupted.
i checked triple for spelling error but that was not the case, any idea on what went wrong here?

Hi there @Klages, can you please paste the contents of your ./asoundrc file so we can just double check what’s in there?

content of ./asoundrc :
pcm.!default { type asym playback.pcm { type plug slave.pcm "hw:0" } capture.pcm { type plug slave.pcm "hw:1" } }

i did a fresh install 3 times and it was always the same result when i changed this file.

Thanks for confirming. That looks OK to me.
Can you edit the file /etc/.asoundrc file and see if this works instead?

What is the specific error message that you are receiving?

@KathyReid @krisgesling

Good catch.

For future reference, “hw:x,y” is a reference to first the card number, and then the device number. The appropriate values can be found by using aplay -l which outputs a list of audio devices attached to the system.

There is a minor issue with this approach in that it will fail unpredictably for those with USB input devices. This is because each time those devices are plugged in, their values can change. A solution to this is potentially to use a device alias instead. Device aliases can be found by capitalising the appendix to the above aplay function - thus aplay -L. This outputs a list of device aliases, as well as friendly names, and what current HWID is attached to them.

If you want a better solution, you can write udev rules to ensure that a device gets the same HWID every time it is plugged in. This is advanced usage, so I won’t write it up here. Instead, here is some material on the same:

1 Like

Hello, i’m new here and this is my first reply.

This solution worked for me. I had a fresh install on a Pi 3 with a Blue Snowball and got the [Errno -9997]

I used:

sudo nano ~/.asoundrc

–then i copy/pasted the text.

pcm.!default { type asym playback.pcm
{ type plug slave.pcm “hw:0” }
capture.pcm { type plug slave.pcm “hw:1” }

ctrl+x to get out, (y) to confirm, and hit enter.

Did a sudo reboot and it worked.

Thanks a lot! It’s really nice here for a newbie.


Thanks so much for confirming it worked @Gideon, appreciate it

1 Like

Hey everyone I just installed mycroft-core on Arch Linux for the first time and got the same sampling rate error when trying the audiotest module to resolve the error of not getting any mic input.

I’m using an usb headset with a microphone and its the default device for both input and output in pulseaudio.

I tried the fix recommended by this thread but it did not resolve the error for me.

What i did:

create the file ~/.asoundrc with the following content:

pcm.!default { type asym playback.pcm
{ type plug slave.pcm “hw:2” }
capture.pcm { type plug slave.pcm “hw:0” }

I used the numbers 2 and 0 because the output of aplay -l looked the following:

card 2: Audio [HyperX 7.1 Audio], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

Please let me know if I understood the explanation of @krisgesling wrong.

Appreciate any help.

Hi @clados, was the sound playing from your headphones? I think you might want:

    pcm.!default { 
    type asym playback.pcm { type plug slave.pcm “hw:2” }
    capture.pcm { type plug slave.pcm “hw:2” }

This should set card 2 as both your playback and capture device.
If you aren’t getting sound output, try setting your playback to another card, maybe:

    pcm.!default { 
    type asym playback.pcm { type plug slave.pcm “hw:0” }
    capture.pcm { type plug slave.pcm “hw:2” }

The card/device definition that r0tekatze mentioned is a little different. I believe it defaults to device number 0 but you can make it explicit with “hw:2,0”. If you want to read more check out the ALSA Project Documentation, but let us know if this doesn’t work. Some people in the original thread needed to specify additional parameters like audio format.

Hi @Klages, did you have any luck with your microphone?
If you’re still having trouble, let us know what output you get from running aplay -l in your terminal.

I was geting the same error because, for some reason, pulse audio wasn’t installed. I installed it and now the microphone works.

1 Like

Hi, I have been having the same problem, getting the same error, output worked but input didnt. So I did a sudo apt-get install pulseaudio. Input started working but now output doesnt work… I appreciate if you could help. Thanks.

Hi @seferi, can you run alsamixer and try to select your output device there?

Hi, I just wanted to report that I had the same issue when I installed Picroft yesterday. I used the Picroft 2018-9-12 unstable image where I was linked to from the Getting Started Guide.

I could resolve the issue in my case by installing pulseaudio. I do not know if pulseaudio should be installed or not but in case it should be, the Picroft image mentioned above should be checked.

1 Like

Hi there @Binabik, thanks so much for reporting this to us.

We currently have a PR that will include pulseaudio in the file as a requirement so once that is merged, pulseaudio will be a requirement for Picroft.

Hi @KathyReid I run the alsamixer and the volume was all the way down. So I set the volume to maximum and start the mycroft again with ./ cli
But it didn’t work, I tried changing sound cards on alsamixer with F6, didn’t work either. Is there perhaps a way to run the audio setup tool like in the initial setup at the beginning?