jasperproject / jasper-client

Client code for Jasper voice computing platform
MIT License
4.53k stars 1.01k forks source link

IOError: [Errno Invalid sample rate] -9997 I is the error im getting #595

Open leearthur56 opened 7 years ago

leearthur56 commented 7 years ago

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 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 "jasper/jasper.py", line 151, in app.run() File "jasper/jasper.py", line 121, in run conversation.handleForever() File "/home/pi/jasper/client/conversation.py", line 31, in handleForever threshold, transcribed = self.mic.passiveListen(self.persona) File "/home/pi/jasper/client/mic.py", line 110, in passiveListen frames_per_buffer=CHUNK) File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 747, in open stream = Stream(self, *args, kwargs) File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 442, in init self._stream = pa.open(arguments) IOError: [Errno Invalid sample rate] -9997

ashishmusale commented 7 years ago

I am having the same problem. Did you find the solution?

leearthur56 commented 7 years ago

no i have not :(

G10DRAS commented 7 years ago

why not you try below in ~/.asoundrc file. check which one is your USB Card and replace card value (card 0) accordingly. do the same for internal sound card.


pcm.usb
{
    type hw
    card 0
}

pcm.internal
{
    type hw
    card 1
}

pcm.!default
{
    type asym
    playback.pcm
    {
        type plug
        slave.pcm "internal"
    }
    capture.pcm
    {
        type plug
        slave.pcm "usb"
    }
}

ctl.!default
{
    type asym
    playback.pcm
    {
        type plug
        slave.pcm "internal"
    }
    capture.pcm
    {
        type plug
        slave.pcm "usb"
    }
}
ashishmusale commented 7 years ago

@ArthurLee1 I finally got it working last night. I had to change the RATE in the mic.py. Once I fixed that I started getting overflow error then I had to go in and change the CHUNK size.

I set the RATE to 48000 and chunk to 8132. Now its listening but it doesn't detect voice much. I am going to try the dev branch to see if that improves anything

flipchan commented 7 years ago

hi i also got this error and changed it like u did @ashishmusale and got a overflow error ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm_equal.c:196:(_snd_pcm_equal_open) No slave configuration for equal pcm ALSA lib pcm_equal.c:196:(_snd_pcm_equal_open) No slave configuration for equal pcm 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 WARNING:client.notifier:gmail_address or gmail_password not set in profile, Gmail notifier will not be used Traceback (most recent call last): File "jasper.py", line 151, in app.run() File "jasper.py", line 121, in run conversation.handleForever() File "/root/gits/jasper/client/conversation.py", line 31, in handleForever threshold, transcribed = self.mic.passiveListen(self.persona) File "/root/gits/jasper/client/mic.py", line 121, in passiveListen data = stream.read(CHUNK) File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 605, in read return pa.read_stream(self._stream, num_frames) IOError: [Errno Input overflowed] -9981 INFO: ngram_search_fwdtree.c(429): TOTAL fwdtree 0.00 CPU nan xRT INFO: ngram_search_fwdtree.c(432): TOTAL fwdtree 0.00 wall nan xRT INFO: ngram_search_fwdflat.c(176): TOTAL fwdflat 0.00 CPU nan xRT INFO: ngram_search_fwdflat.c(179): TOTAL fwdflat 0.00 wall nan xRT INFO: ngram_search.c(303): TOTAL bestpath 0.00 CPU nan xRT INFO: ngram_search.c(306): TOTAL bestpath 0.00 wall nan xRT INFO: ngram_search_fwdtree.c(429): TOTAL fwdtree 0.00 CPU nan xRT INFO: ngram_search_fwdtree.c(432): TOTAL fwdtree 0.00 wall nan xRT INFO: ngram_search_fwdflat.c(176): TOTAL fwdflat 0.00 CPU nan xRT INFO: ngram_search_fwdflat.c(179): TOTAL fwdflat 0.00 wall nan xRT INFO: ngram_search.c(303): TOTAL bestpath 0.00 CPU nan xRT INFO: ngram_search.c(306): TOTAL bestpath 0.00 wall nan xRT

i changed it like u did but i still get the same error 89 def passiveListen(self, PERSONA): 90 """ 91 Listens for PERSONA in everyday sound. Times out after LISTEN_TIME, so 92 needs to be restarted. 93 """ 94 95 THRESHOLD_MULTIPLIER = 1.8 96 RATE = 48000 97 CHUNK = 8132 98

ashishmusale commented 7 years ago

sorry, my bad. The chunk value is 8192

flipchan commented 7 years ago

@ashishmusale did u change all RATE = 16000 CHUNK = 1024 in mic.py?

flipchan commented 7 years ago

i think i need some other value if i use 8192 and get: No disturbance detected No disturbance detected No disturbance detected

and when i use 4096 i get the same error

flipchan commented 7 years ago

Cannot connect to server request channel jack server is not running or cannot be started WARNING:client.notifier:gmail_address or gmail_password not set in profile, Gmail notifier will not be used 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 "jasper.py", line 151, in app.run() File "jasper.py", line 121, in run conversation.handleForever() File "/root/gits/jasper/client/conversation.py", line 31, in handleForever threshold, transcribed = self.mic.passiveListen(self.persona) File "/root/gits/jasper/client/mic.py", line 110, in passiveListen frames_per_buffer=CHUNK) File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 747, in open stream = Stream(self, *args, kwargs) File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 442, in init self._stream = pa.open(arguments) IOError: [Errno Invalid sample rate] -9997 INFO: ngram_search_fwdtree.c(429): TOTAL fwdtree 0.00 CPU nan xRT INFO: ngram_search_fwdtree.c(432): TOTAL fwdtree 0.00 wall nan xRT INFO: ngram_search_fwdflat.c(176): TOTAL fwdflat 0.00 CPU nan xRT INFO: ngram_search_fwdflat.c(179): TOTAL fwdflat 0.00 wall nan xRT INFO: ngram_search.c(303): TOTAL bestpath 0.00 CPU nan xRT INFO: ngram_search.c(306): TOTAL bestpath 0.00 wall nan xRT INFO: ngram_search_fwdtree.c(429): TOTAL fwdtree 0.00 CPU nan xRT INFO: ngram_search_fwdtree.c(432): TOTAL fwdtree 0.00 wall nan xRT INFO: ngram_search_fwdflat.c(176): TOTAL fwdflat 0.00 CPU nan xRT INFO: ngram_search_fwdflat.c(179): TOTAL fwdflat 0.00 wall nan xRT INFO: ngram_search.c(303): TOTAL bestpath 0.00 CPU nan xRT INFO: ngram_search.c(306): TOTAL bestpath 0.00 wall nan xRT root@raspberrypi:~/gits/jasper#

ashishmusale commented 7 years ago

@flipchan Yes, I changed all the instances of RATE and CHUNK

flipchan commented 7 years ago

@ashishmusale seem like some kind of wierd error i have tried

42000 #36000 #24000 #48000 #16000 7168 #6144 #5120 #4096 #8192 #1024

and IOError: [Errno Invalid sample rate] -9997

leearthur56 commented 7 years ago

Hi, I also changed all the RATE's and CHUNK's, but it still doesn't work and I am getting this weird message: 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 Traceback (most recent call last): File "jasper/jasper.py", line 151, in app.run() File "jasper/jasper.py", line 121, in run conversation.handleForever() File "/home/pi/jasper/client/conversation.py", line 31, in handleForever threshold, transcribed = self.mic.passiveListen(self.persona) File "/home/pi/jasper/client/mic.py", line 183, in passiveListen transcribed = self.passive_stt_engine.transcribe(f) File "/home/pi/jasper/client/stt.py", line 392, in transcribe r = self._http.post(self.request_url, data=data, headers=headers) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 504, in post return self.request('POST', url, data=data, json=json, kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 461, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 573, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 415, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', error(32, 'Broken pipe'))

Thanks all for helping!

mzlarsson commented 7 years ago

Hi! If your mic doesn't support a sample rate of 16kHz (which seems to be the case in this issue thread) you can fix it by doing some edits in mic.py:

  1. First off, change all the RATE variables to one that your mic does support
  2. Secondly, increase the CHUNK variable in the magnitude in order to make up for the increase in data size. In my case I increased the sample rate from 16000Hz to 44100Hz, so I also increased the chunk size from 1024 to 3072 (since around 3 times more data is generated). For simple usage, one could use the formula (NEW_SAMPLE_RATE/16000) * 1024 to get a rough estimate.
  3. When arriving to this third step, no errors should occur but Jasper will be quite unable to understand what you are trying to say. This is because the samples from the mic are compared with 16kHz preset samples in order to get what you are saying. Since we changed the sample rate, the comparison will therefore be quite inaccurate. In order to fix this, we need to resample all mic input before using it. I wrote a small code part for doing this:
    def resample(self, data, rate):
    (newfragment, state) = audioop.ratecv(data, 2, 1, rate, 16000, None)
    return newfragment

    Change so that you always call this function when you read the data, i.e. change all lines with data = stream.read(CHUNK) to data = self.resample(stream.read(CHUNK), RATE)

This should do the trick! If I have the time I will try to generalize this part and make a pull request, but in the meantime I hope this help you.

presingjos commented 6 years ago

THANK YOU!

This worked perfectly! I was using this microphone from amazon

leearthur56 commented 6 years ago

No problem!

On Sun, Jan 28, 2018 at 8:11 PM, presingjos notifications@github.com wrote:

THANK YOU!

This worked perfectly! I was using this microphone https://www.amazon.com/Kinobo-Microphone-Desktop-Recognition-Software/dp/B00IR8R7WQ/ref=sr_1_4?ie=UTF8&qid=1517188236&sr=8-4&keywords=usb+2.0+microphone from amazon

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jasperproject/jasper-client/issues/595#issuecomment-361114855, or mute the thread https://github.com/notifications/unsubscribe-auth/ARhKK_vz7_ZHmfoGeTYGgXwmi8FPI8qjks5tPRq2gaJpZM4L6FeF .