循环语音识别

时间:2020-06-08 18:37:30

标签: python speech-recognition

尝试获取以下代码以继续运行,并向我提供输出,直到我为其指定关键字为止。无法弄清楚,它所做的只是给我我所说的内容,然后当我停止讲话时,它会打印并停止执行。

def get_audio():
    while True:
        r = sr.Recognizer()
        with sr.Microphone() as source:
            audio = r.listen(source)
            said = ""

            try:
                said = r.recognize_google(audio)
                print(said)
            except Exception as e:
                print("Exception: " + str(e))

        return said.lower()

0 个答案:

没有答案