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
476 views
in Technique[技术] by (71.8m points)

Python, Speech Recognition stuck at 'Listening...'

The code is stuck at listening ( audio=r.listen(source) line) and doesn't go beyond it. No error messages or anything else.

My code:

import speech_recognition as sr

def takeCommand():
    '''
    It takes user's voice as input
    '''
    r=sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio=r.listen(source)

try:
    print("Recognizing...")
    query = r.recognize_google(audio, language="en-in")
    print(f"Recognized Command: {query}")

except Exception as e:
    print(e)
    print("I didn't recognize what you said please repeat")
    return "None"

return query


takeCommand()
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I just checked the link you posted in the comment.

There is this code:

with mic as source:
    audio = r.listen(source)

If this code does not work, one reason could be that the microphone picks up too much ambient noise.

The solution may be

with mic as source:
    r.adjust_for_ambient_noise(source)
    audio = r.listen(source)

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

...