Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google api client Speech to text, Python

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")
like image 361
MaltheMusaeus Avatar asked Apr 30 '26 20:04

MaltheMusaeus


1 Answers

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

like image 122
LeKhan9 Avatar answered May 02 '26 11:05

LeKhan9