【问题标题】:How to recieve microphone input with Speech Recognition in python properly如何在python中正确接收带有语音识别的麦克风输入
【发布时间】:2020-12-24 12:45:42
【问题描述】:

我在下面有一个 python 程序。我想接受麦克风输入并从输入中获取文本。当我运行程序时,它总是在第 9 行“audio_text = r.listen(source)”处停止并且不会继续。即使我已经停止说话,它似乎仍在等待麦克风输入停止。我知道我的麦克风可以正常工作,因为我录制了一个文件并使用 aplay 播放它。有谁知道为什么我的程序会卡在那条线上?

import speech_recognition as sr

print("Program has started!")

r = sr.Recognizer()

with sr.Microphone() as source:
    print("Talk")
    audio_text = r.listen(source)
    print("Time over, thanks")
    
    try:
        # using google speech recognition
        print("Text: "+r.recognize_google(audio_text))
    except:
         print("Sorry, I did not get that")

我在 Raspberry pi os 上运行它并使用 python3。

【问题讨论】:

    标签: python raspberry-pi speech-recognition


    【解决方案1】:

    如果您的麦克风没有停止收听,请尝试添加这些行以停止录音

      Stop_listening=r.listen_in_background(source,callback)
      Stop_listening(wait_to_stop=True)
    

    【讨论】:

    • 感谢您的建议。我试过了,但它仍然没有用。我找到了用于我的程序的替代解决方案。我不是直接从麦克风录制并使用实时音频,而是通过麦克风录制短间隔的音频。然后我使用音频文件生成文本。还是谢谢你。 :)
    猜你喜欢
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 2021-10-03
    • 2023-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    相关资源
    最近更新 更多