Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

How do I give the time duration of listening to python speech recognition library?

I am working on RPi 4 and got the code working but the listening time, from my microphone, of my speech recognition object is really long almost like 10 seconds. I want to decrease this time. I looked at the speech recognition library documentation but it does not mention the function anywhere.

Python editor gives me the following prompt of the listen() function;

self:Recogniser, source, timeout = None,phrase_time_limit = None snowboy_configuration =None

So I tried calling the function like:

audio = r.listen(source,None,3)

Or

 audio = r.listen(source,3,3)

hoping it will listen for 3 seconds, but it's not working that way.

Following is my code:

import speech_recognition as sr

r = sr.Recognizer()

speech = sr.Microphone(2)

#print(sr.Microphone.list_microphone_names())

while 1:

             with speech as source:
                 print("say something!…")
                 audio = r.adjust_for_ambient_noise(source)
                 audio = r.listen(source,None,3)
                 print("the audio has been recorded")
             # Speech recognition using Google Speech Recognition
             try:
                 print("api is enabled")
                 recog = r.recognize_google(audio, language = 'en-US')
                 # for testing purposes, we're just using the default API key
                 # to use another API key, use r.recognize_google(audio)
                 # instead of r.recognize_google(audio)

                 print("You said: " + recog)
             except sr.UnknownValueError:
                 print("Google Speech Recognition could not understand audio")
             except sr.RequestError as e:
                 print("Could not request results from Google Speech Recognition service; {0}".format(e))

How do I decrease the time duration of listening?

question from:https://stackoverflow.com/questions/65641455/how-do-i-give-the-time-duration-of-listening-to-python-speech-recognition-librar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...