I am using Python version 3.4 to develop this program.
Does anyone know how to use the Google API Client Speech Recognition library?
I am not able to execute my program; I expect the output given in the example below.
For example:
user (input): What is 5+5
computer (Google API Speech Recognition library):
5+5 is 10
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
UserSaid = r.listen(source)
try:
print("Google thinks you said:\n" + r.recognize_google(audio))
except:
pass
if UserSaid == 'yes':
print("It worked!!")
else:
print("Not working, yet")
I believe you are missing the recognition step which should take the raw audio bits and convert them to string.
Try this:
r.recognize(UserSaid)
You can also get a list of all possible transcriptions via this:
all_transcriptions = r.recognize(UserSaid, True)
for text in all_transcriptions:
print("Guess -> {}".format(text)
BTW, have you tried the newer Speech to text API? It seems to have a good amount of documentation. Here is a link to a Python API:
https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries
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