4

I am trying a python script for speech recognition, i have installed the required pyaudio and SpeechRecognition modules in my enivronment.

The program was running fine till yesterday, but now it is stuck in "say something". Below is my code.

import speech_recognition as sr
print "say something1"
r = sr.Recognizer()
print "say something2"
with sr.Microphone() as source:                # use the default microphone as the audio source
    print "say something3"
    audio = r.listen(source,timeout=3)                   # listen for the first phrase and extract it into audio data

print "say something"
try:
    print("You said " + r.recognize(audio))    # recognize speech using Google Speech Recognition
except LookupError:                            # speech is unintelligible
    print("Could not understand audio")

Console o/p :-

say something1
say something2
ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
say something3

Not duplicate of/ Have refferd to :- speech recognition python code not working

1
  • 1
    I am facing the same problem. After asking the same question, I saw this question and this too unanswered :( . Aug 28, 2016 at 6:41

4 Answers 4

2

May be this can solve your problem.

print "say something2"
with sr.Microphone() as source:                # use the default microphone as the audio source
    r.adjust_for_ambient_noise(source)  # here
    print "say something3"
    audio = r.listen(source,timeout=3)   

look at this. https://github.com/Uberi/speech_recognition/issues/191

Last solution work for me . hope same work for your

2

I also had this problem and changing

audio = r.listen(source,timeout=3)

to

audio = r.listen(source,timeout=3, phrase_time_limit=3)

solved it for me.

1

I have had the same problem with me, i ended up installing jack2d and pulseaudio and what not.

That was the problem, I then uninstalled the jack2d by running

sudo apt-get remove --auto-remove jack

Then restarted the system, and then ran

jack_control  stop

Then this will give the voice input to pulse-aduio.

When you run the program, the console should print

ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(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

The last lines state that Jack has stopped and the voice input is being redirected to pulse.

what actually happening here is, the audio resoruce(mic) is being channeled only to either jack or pulse, so I uninstalled jack

Now my program works just fine

5
  • 1
    Are you still stuck in. Say something ?
    – penta
    Aug 28, 2016 at 13:38
  • Yes. I am working from last 10 hours on it but with no result. I will be thankful if you can help me. Aug 28, 2016 at 13:41
  • Sure. Tell me if you have pulse audio, jack2d n other audio programs, if yes. List them to me
    – penta
    Aug 28, 2016 at 13:42
  • I have pulse audio and jack2d installed. Aug 31, 2016 at 21:56
  • then remove jack2d
    – penta
    Sep 1, 2016 at 8:31
1

When I tried your code as it is I got following attribute error.

AttributeError: 'Recognizer' object has no attribute 'recognize'

Upon going through documentation it looks like the Recognizer class don't have a method recognize. you will need to use one of the several recognize_* methods that recognize class offers.
It seems you want to use recognize_google,so when I change your code from

print("You said " + r.recognize(audio))

to

print("You said " + r.recognize_google(audio))

The code is working for me.

I said "hello", which was recognized below.

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
say something1
say something2
say something3
say something
You said hello

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.