Mycroft Community Forum

Cannot launch: Errno -9997 Invalid sample rate

Working on a Fedora 34 Linux server, fully up to date. USB microphone and regular speakers plugged into the headphone jack in front.

mycroft-start audiotest works correctly, recording and playing back my voice.

Yet mycroft does not work, and dies consistently on this error when running mycroft-cli-client:

19:01:35.146 | INFO | 874385 | mycroft.util.audio_utils:find_input_device:196 | Searching for input device: iTalk-02: USB Audio
19:01:35.149 | INFO | 874385 | mycroft.client.speech.listener:create_wake_word_recognizer:328 | Creating wake word engine
19:01:35.149 | INFO | 874385 | mycroft.client.speech.listener:create_wake_word_recognizer:351 | Using hotword entry for hey mycroft
19:01:35.150 | INFO | 874385 | mycroft.client.speech.hotword_factory:load_module:500 | Loading “hey mycroft” wake word via precise
19:01:36.609 | INFO | 874385 | mycroft.client.speech.listener:create_wakeup_recognizer:365 | creating stand up word engine
19:01:36.610 | INFO | 874385 | mycroft.client.speech.hotword_factory:load_module:500 | Loading “wake up” wake word via pocketsphinx
Expression ‘paInvalidSampleRate’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 2043
Expression ‘PaAlsaStreamComponent_InitialConfigure( &self->capture, inParams, self->primeBuffers, hwParamsCapture, &realSr )’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 2713
Expression ‘PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 2837
Exception in thread Thread-14:
Traceback (most recent call last):
File “/usr/lib64/python3.9/threading.py”, line 973, in _bootstrap_inner
self.run()
File “/home/iamsure/mycroft-core/mycroft/client/speech/listener.py”, line 79, in run
with self.mic as source:
File “/home/iamsure/mycroft-core/mycroft/client/speech/mic.py”, line 140, in enter
return self._start()
File “/home/iamsure/mycroft-core/mycroft/client/speech/mic.py”, line 147, in _start
self.stream = MutableStream(self.audio.open(
File “/home/iamsure/mycroft-core/.venv/lib64/python3.9/site-packages/pyaudio.py”, line 750, in open
stream = Stream(self, *args, **kwargs)
File “/home/iamsure/mycroft-core/.venv/lib64/python3.9/site-packages/pyaudio.py”, line 441, in init
self._stream = pa.open(**arguments)
OSError: [Errno -9997] Invalid sample rate

I should note that mycroft-cli-client shows no mic level at the bottom right, despite recording and playback working without issue in the test.

Bumpity bump bump bump

I’ve seen this before. I believe it was fixed after adding the environment variable XDG_RUNTIME_DIR to the systemd config file that starts Mycroft (shown below). It assumes the uid Mycroft is running as is 500 (pi). It allows Mycroft to find the socket to talk to the message bus. I may be wrong, but it might be worth a try.

$ sudo vi mycroft.service
[Unit]
Description=Mycroft AI
After=pulseaudio.service
[Service]
User=pi
WorkingDirectory=/home/pi/
ExecStart=/home/pi/mycroft-core/bin/mycroft-start all
ExecStop=/home/pi/mycroft-core/bin/mycroft-stop
Type=forking
Restart=no
Environment="XDG_RUNTIME_DIR=/run/user/500"
[Install]
WantedBy=multi-user.target

Hope this helps.

-Mike M

Sadly that wasn’t it. I didn’t have a service file yet, and even created it and modified the paths to match and it didn’t start mycroft.

I tried manually exporting the XDG_RUNTIME_DIR and starting mycroft manually and it’s the same result: Error -9997 Invalid sample rate and no Mic level showing.

I stand corrected! That did change something. Now that I matched the userid to mine, pulse was (I think?) able to connect, but pulseaudio still dies with the sample rate and mic level is still blank. :frowning:

Establishing Mycroft Messagebus connection…
Connected to Messagebus!
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
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
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
20:21:00.025 | INFO | 135161 | mycroft.client.speech.listener:create_wake_word_recognizer:328 | Creating wake word engine
20:21:00.026 | INFO | 135161 | mycroft.client.speech.listener:create_wake_word_recognizer:351 | Using hotword entry for hey mycroft
20:21:00.027 | INFO | 135161 | mycroft.client.speech.hotword_factory:load_module:500 | Loading “hey mycroft” wake word via precise
20:21:01.654 | INFO | 135161 | mycroft.client.speech.listener:create_wakeup_recognizer:365 | creating stand up word engine
20:21:01.654 | INFO | 135161 | mycroft.client.speech.hotword_factory:load_module:500 | Loading “wake up” wake word via pocketsphinx
20:21:01.757 | INFO | 135161 | main:on_ready:179 | Speech client is ready.
Expression ‘paInvalidSampleRate’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 2043
Expression ‘PaAlsaStreamComponent_InitialConfigure( &self->capture, inParams, self->primeBuffers, hwParamsCapture, &realSr )’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 2713
Expression ‘PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 2837
Exception in thread Thread-8:

@thekabal - glad it helped somewhat.

I have an early draft of a doc describing an install of a entire music playing stack (and some details of the boombox hardware). Maybe that will clear up further errors.

However, I can’t seem to upload a PDF to Google drive without it borking the content. Anyone can send a request to mike99mac@gmail.com and I’ll send back the PDF. Feedback will be appreciated.

-Mike M

python 3.9 and the pyaudio/portaudio packages are the problems in this case. Apart from that, i wouldn’t suggest using 3.9 at this point in time since you will likely running into more issues.

SGee> Which version of Python and pyaudio/portaudio packages are supported/primarily used by Mycroft?

3.7 is the version of choice. Py 3.8 also works without hickups.

I’ve monitored **arguments not long ago (with 3.9), but i can’t remember what i’ve found. If you want to know whats happening just log those arguments and look around in pyaudio (pretty uncomplicated lib) why it cant work with the sample rate argument.

1 Like

After installing pyenv, setting the global version to 3.8.12, logging out and back in, and running mycroft - IT WORKS.

Solved!

Many, many thanks to @SGee for the solution.

1 Like