DarkCoderRises
DarkCoderRises

Reputation: 142

Does not stop recording in speech recognition python

I was trying the example code for the first time

import speech_recognition as sr
r = sr.Recognizer(language = "en-US"  )
r.pause_threshold = 0.6 
with sr.Microphone() as source:    
    audio = r.adjust_for_ambient_noise(source)
    print "Speak Now"
    audio = r.listen(source, timeout=1)                   # listen for the first phrase and extract it into audio data

try:
    print("You said " + r.recognize(audio))    # recognize speech using Google Speech Recognition
except LookupError:                            # speech is unintelligible
    print("Could not understand audio")
except IndexError:
    print("No internet")
except KeyError:
    print("quota maxed out")

But i am getting this

ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
ALSA lib dlmisc.c:252:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_pcm_equal.so
ALSA lib dlmisc.c:252:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_pcm_equal.so
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
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
Speak now

and it is then struck there only

What should i do?

Upvotes: 0

Views: 1398

Answers (1)

knivez
knivez

Reputation: 9

First, make sure your input isn't muted. Second, you may need JACK.

sudo apt-get install jackd

Or... your mic may not be detecting sound via Alsa and one of the various audio frameworks [GStreamer, PulseAudio, Phonon, OSS, etc]. You'll need to see which combination you're using. Mine was Alsa/PulseAudio/JACK. You didn't mention your distro, so yours may be different. You can then adjust your input port/s which should solve the issue.

After having the same issue and ensuring my input wasn't muted, I downloaded the Pulse Audio volume control:

sudo apt-get install pavucontrol

What you want to be able to do is set the input device ports. Again, depending on your distro and hardware, this may vary from: Internal/external mics, analog/digital options or OSS. Those are some examples of what was in my Input Device Options. The mic then detected my voice. I received the same exact err messages as you, but the program output was what was expected.

If you read this: Speech Recognition 2.0.1 You'll see your same code snippet and how to keep those warnings from displaying. The article will also explain everything you'll need to have installed. Such as JACK [jackd].

This article helped me to narrow down the problem: How it works: Linux audio explained It also helped me not to dare attempt fixing this issue from the terminal.

Hope this helps you or others. Good luck.

Upvotes: 1

Related Questions