Python语音识别卡住了(Mac)

时间:2020-07-06 12:36:17

标签: python speech-recognition speech-to-text

这是我的代码:

import speech_recognition as sr

r = sr.Recognizer()

with sr.Microphone() as source:
    print("Go ahead!")
    audio = r.listen(source)

    try:
        text = r.recognize_google(audio)
        print("Understood: %s" % text)
    except:
        print("Couldnt recognize your voice")

但是,如果我启动程序,它会说吧!但是什么也没发生...是因为我可能不得不以某种方式使用Gran python麦克风吗?我在Mac上 它不会显示错误消息,也不会说无法识别您的声音

2 个答案:

答案 0 :(得分:0)

首先尝试使用Python直至3.6。

然后安装以下内容:

xcode-select --install
brew remove portaudio
brew install portaudio
pip3 install pyaudio

现在它应该可以工作了。另外,为了调试您的代码,请删除块try / except。它将帮助您检查出什么问题。

答案 1 :(得分:0)

问题在于使用集成终端。现在,我尝试在不使用VS代码中集成终端的情况下使用它,并且可以正常工作