speech_recognition module stuck in "say something" - python
<p>I am trying a python script for speech recognition, i have installed the required pyaudio and SpeechRecognition modules in my enivronment.</p>

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

<pre><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")
</code></pre>

<p>Console o/p :-</p>

<pre><code>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
</code></pre>

<p>Not duplicate of/ Have refferd to :- <a href="http://stackoverflow.com/questions/32005310/speech-recognition-python-code-not-working">speech recognition python code not working</a></p>

<p>When I tried your code as it is I got following  <code>attribute</code> error.</p>

<pre><code>AttributeError: 'Recognizer' object has no attribute 'recognize'
</code></pre>

<p>Upon going through <a href="https://pypi.python.org/pypi/SpeechRecognition/" rel="nofollow">documentation</a> it looks like the <code>Recognizer</code> class don't have a method <code>recognize</code>. you will need to use one of the several <code>recognize_*</code> methods that <code>recognize</code> class offers.<br>
It seems you want to  use <code>recognize_google</code>,so when I change your code from</p>

<pre><code>print("You said " + r.recognize(audio))
</code></pre>

<p>to</p>

<pre><code>print("You said " + r.recognize_google(audio))
</code></pre>

<p>The code is working for me.  </p>

<p>I said "hello", which was recognized below.</p>

<pre><code>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.
&gt;&gt;&gt; ================================ RESTART ================================
&gt;&gt;&gt; 
say something1
say something2
say something3
say something
You said hello
</code></pre>

<p>Hope this helps.</p>

python python-2.7 speech-recognition