Reputation: 1052
I am starting a work which needs to convert audio into text. I am using the speechrecognition library of python. I saw a tutorial on github on how to use it. The program is not bale to recognise my voice through microphone.
I am using python 2.7 on ubuntu 16.04.
Code:
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
# recognize speech using Sphinx
try:
print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
Output on terminal:
shivam@shivam-HP-Pavilion-15-Notebook-PC:~/Python/audio$ python temp.py
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_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
Say something!
After, "Say something!", it keeps on blinking but my voice is not recognised.
Upvotes: 4
Views: 3861
Reputation: 11443
I couldn't get PocketSphinx
module installed , running into issues.
But if I switch recognize_sphinx
with recognize_google
, its working for me.
Here is your modified code.
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
# recognize speech using Sphinx
try:
#print("Sphinx thinks you said " + r.recognize_sphinx(audio))
print("Sphinx thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
Output
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 something!
Sphinx thinks you said hello
>>>
Hope this is useful.
Upvotes: 1