如何修复识别器。听着()在python中用于语音识别

2024-09-19 12:32:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用了下面的代码片段,但当通过麦克风输入时,它似乎听不到。你知道吗

import speech_recognition as sr

r = sr.Recognizer()

with sr.Microphone() as source:
    r.adjust_for_ambient_noise(source, duration=10)
    print("Say something ")
    audio = r.listen(source) 

    try:
        test = r.recognize_google(audio)
        #print("you said :" + test)
        print("you said: {}".format(test))
    except:
        print("sorry could not hear you")

Tags: 代码testimportyousourceaswithaudio