speech recognition python code not working

后端 未结 13 1755
傲寒
傲寒 2020-12-15 10:23

I am running the following code in Python 2.7 with pyAudio installed.

import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:             


        
13条回答
  •  無奈伤痛
    2020-12-15 11:13

    try this code:

    r = sr.Recognizer()
    
    with sr.Microphone() as source:
            r.adjust_for_ambient_noise(source=source)
            audio = r.listen(source,timeout=3)
            
    
        
        data = ''
        try :
            data = r.recognize_google(audio)
            print(data)
    
        except sr.UnknownValueError:
            print(" Error")
            
        except sr.RequestError as e:
            print("Request Error")
    

    or add timeout and r.adjust_for_ambient_noise(source=source) to your code as above.please can anyone help me with this

提交回复
热议问题