Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOError: [Errno -9997] Invalid sample rate #14

Closed
tiny-tinker opened this issue Jun 7, 2016 · 8 comments
Closed

IOError: [Errno -9997] Invalid sample rate #14

tiny-tinker opened this issue Jun 7, 2016 · 8 comments

Comments

@tiny-tinker
Copy link

Hey guys!
Great stuff! This is pretty much exactly what I was trying to build! But you guys are way further than I ever would have gotten. Er, but I didn't get very far.

I'm running this on a raspberry pi model B with a Cyber Acoustics USB microphone. I can successfully record something using AUDIODEV=hw:1,0 rec t.wav.

Anyway, when attempting the demo with this command:

pi@raspberrypi:~/Downloads/snowboy $ python demo.py ./resources/snowboy.umdl 

I get a bunch of garbage from ALSA that is apparently just warnings. But the last bit dumps this:

Expression 'paInvalidSampleRate' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2048
Expression 'PaAlsaStreamComponent_InitialConfigure( &self->capture, inParams, self->primeBuffers, hwParamsCapture, &realSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2719
Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843
Traceback (most recent call last):
  File "demo.py", line 27, in <module>
    detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
  File "/home/pi/Downloads/snowboy/snowboydecoder.py", line 115, in __init__
    stream_callback=audio_callback)
  File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
IOError: [Errno -9997] Invalid sample rate

I saw this while playing with another voice recognition and I was able to get past it by passing a sample rate. Is there an easy way to pass sample rate to your decoder?

For reference, here is the get_device_count dump:

import pyaudio
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
    print p.get_device_info_by_index(i)

Output: (formatted for reading!)

{
    'defaultSampleRate': 44100.0,
    'defaultLowOutputLatency': 0.005804988662131519,
    'defaultLowInputLatency': -1.0,
    'maxInputChannels': 0 L,
    'structVersion': 2 L,
    'hostApi': 0 L,
    'index': 0,
    'defaultHighOutputLatency': 0.034829931972789115,
    'maxOutputChannels': 2 L,
    'name': u 'bcm2835 ALSA: - (hw:0,0)',
    'defaultHighInputLatency': -1.0
} {
    'defaultSampleRate': 44100.0,
    'defaultLowOutputLatency': 0.005804988662131519,
    'defaultLowInputLatency': -1.0,
    'maxInputChannels': 0 L,
    'structVersion': 2 L,
    'hostApi': 0 L,
    'index': 1,
    'defaultHighOutputLatency': 0.034829931972789115,
    'maxOutputChannels': 2 L,
    'name': u 'bcm2835 ALSA: IEC958/HDMI (hw:0,1)',
    'defaultHighInputLatency': -1.0
} {
    'defaultSampleRate': 48000.0,
    'defaultLowOutputLatency': -1.0,
    'defaultLowInputLatency': 0.007979166666666667,
    'maxInputChannels': 2 L,
    'structVersion': 2 L,
    'hostApi': 0 L,
    'index': 2,
    'defaultHighOutputLatency': -1.0,
    'maxOutputChannels': 0 L,
    'name': u 'Cyber Acoustics USB device: Audio (hw:1,0)',
    'defaultHighInputLatency': 0.032
} {
    'defaultSampleRate': 44100.0,
    'defaultLowOutputLatency': 0.005804988662131519,
    'defaultLowInputLatency': -1.0,
    'maxInputChannels': 0 L,
    'structVersion': 2 L,
    'hostApi': 0 L,
    'index': 3,
    'defaultHighOutputLatency': 0.034829931972789115,
    'maxOutputChannels': 128 L,
    'name': u 'sysdefault',
    'defaultHighInputLatency': -1.0
} {
    'defaultSampleRate': 44100.0,
    'defaultLowOutputLatency': 0.005804988662131519,
    'defaultLowInputLatency': -1.0,
    'maxInputChannels': 0 L,
    'structVersion': 2 L,
    'hostApi': 0 L,
    'index': 4,
    'defaultHighOutputLatency': 0.034829931972789115,
    'maxOutputChannels': 128 L,
    'name': u 'default',
    'defaultHighInputLatency': -1.0
} {
    'defaultSampleRate': 48000.0,
    'defaultLowOutputLatency': 0.021333333333333333,
    'defaultLowInputLatency': -1.0,
    'maxInputChannels': 0 L,
    'structVersion': 2 L,
    'hostApi': 0 L,
    'index': 5,
    'defaultHighOutputLatency': 0.021333333333333333,
    'maxOutputChannels': 2 L,
    'name': u 'dmix',
    'defaultHighInputLatency': -1.0
}
@chenguoguo
Copy link
Collaborator

Hi, regarding changing the sampling rate, Snowboy requires a specific sampling rate which you can see by calling the SampleRate() function. For now it's 16k. You can use different sampling rate for PyAudio, but when you feed the data to Snowboy detector, you will have to convert the data to 16k sampling rate.

As for the "Invalid sample rate" error, there's a long discussion in this thread. It might has something to do with pulseaudio. Some people mentioned that they were able to fix the issue by using a fresh installation of the OS. You can go through the thread to see what's the best fix.

Please do let us know if you end up with a nice solution to the issue!

@tiny-tinker
Copy link
Author

Ok, thanks for the update. For now I started new with a fresh image of Raspbian jesse. If I run into this issue there, I'll dig further. I was doing a lot with installing libraries and messing with the microphone, so maybe something got whacky in that.

@chenguoguo
Copy link
Collaborator

@nomadic-squirrel could you let me know if this was fixed eventually? If yes how did you fix it? Thanks!

@tiny-tinker
Copy link
Author

Yea, I just tested it. I still get the same ALSA warnings, then I get this output:

ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
Listening... Press Ctrl+C to exit
INFO:snowboy:Keyword 1 detected at time: 2016-08-05 18:27:15

And it will detect if I speak directly into the mic. I think I futzed around with my alsa settings and fubard something along the lines. This is a mostly fresh image with just the development libraries and snowboy installed.

So, not terribly helpful, sorry :(

@cjolif
Copy link

cjolif commented Dec 13, 2016

I've got similar error on Raspberry with the C++ sample.

Fail to open PortAudio stream, error message is "Invalid sample rate"
Listening... Press Ctrl+C to exit

and nothing works.

ALSA description of my microphone is:

Name                        = USB PnP Sound Device: Audio (hw:1,0)
Host API                    = ALSA
Max inputs = 1, Max outputs = 0
Default low input latency   =   0.0087
Default low output latency  =  -1.0000
Default high input latency  =   0.0348
Default high output latency =  -1.0000
Default sample rate         = 44100.00
Supported standard sample rates
 for half-duplex 16 bit 1 channel input =
	44100.00, 48000.00

@chenguoguo
Copy link
Collaborator

Snowboy requires a sample rate of 16k, it could be that the 16k sampling rate is not supported by your microphone. If you have other microphones by hand, you can give them a try.

@sriranjanr
Copy link

I am having the same invalid sample rate issue, The sample rate support by my USB mic is 44100. So where and how should I set the sample rate?

@chenguoguo
Copy link
Collaborator

chenguoguo commented May 9, 2018

@sriranjanr There are usually two options:

  1. Try another microphone

  2. Try the arecord demo: https://github.com/Kitt-AI/snowboy/blob/master/examples/Python/demo_arecord.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants