I am running the following code in Python 2.7 with pyAudio installed.
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source: # use the default microphone as the audio source
audio = r.listen(source) # 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")
The output gives a blinking pointer. That's it.
Speech recognition engine/API support: Quickstart: pip install SpeechRecognition. See the “Installing” section for more details. To quickly try it out, run python -m speech_recognition after installing. The library reference documents every publicly accessible object in the library.
0 Speech recognition using the speech_recognition module in python 0 Microphone is not Listening 0 speech_recognition not recognizing my voice or anything of that sort 1 IndexError: index 14708 is out of bounds for axis 0 with size 295
Referance Tuesday, March 28, 2017 Easy Speech Recognition in Python with PyAudio and Pocketsphinx Share Improve this answer Follow answered Nov 27 '17 at 14:34 cinsdikicicinsdikici
Because you have to tell your Python program that you want to take speech input or voice input from which particular microphone. If you still don’t know how to find the device ID please read my previous tutorial,
The possible reason could be that the recognizer_instance.energy_threshold
property is probably set to a value that is too high to start off with. You should decrease this threshold, or call recognizer_instance.adjust_for_ambient_noise(source, duration = 1)
. You can learn more about it at Speech Recognition
I have solved the same problem for me with the following (noise suppression), The "listen" function has problems with environment noise. So the running code is only blinking waiting.
Use this ambient noise suppression/adjustment;
r.adjust_for_ambient_noise(source, duration=5)
Referance Tuesday, March 28, 2017 Easy Speech Recognition in Python with PyAudio and Pocketsphinx
try to add
r.adjust_for_ambient_noise(source,duration=1)
where r is recogniser instance, like this
import speech_recognition as sr
r=sr.Recognizer()
print(sr.Microphone.list_microphone_names())
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source,duration=1)
# r.energy_threshold()
print("say anything : ")
audio= r.listen(source)
try:
text = r.recognize_google(audio)
print(text)
except:
print("sorry, could not recognise")
have you tried replacing
print("You said " + r.recognize(audio))
except LookupError:
print("Could not understand audio")
with
text = r.recognize_google(audio)
print("You said : {}".format(text))
text = r.recognize_google(audio)
except:
print("Sorry could not recognize your voice")
ensure pyaudio.h is installed by running the below command
sudo apt-get install portaudio19-dev python-pyaudio python3-pyaudio
check the input volume of your microphone. It is by default set to 0 in ubuntu (in my case). Since your program got stuck on the line audio = r.listen(source)
, which simply means that the microphone is not able to listen to any voice input. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With