【问题标题】:Having trouble with speech to text in Python在 Python 中语音转文本时遇到问题
【发布时间】:2020-05-15 04:52:26
【问题描述】:
import speech_recognition as sr

rec = sr.Recognizer()
with sr.Microphone as source:
    print('say something')
    audio = rec.listen(source)
    voice_data = rec.recognize_google(audio)
    print(voice_data)

这是我在网上观看的大量教程中显示的代码,我安装了 SpeechRecognizer 和 pyAudio(使用 whl 文件,而不是使用 pip,我不知道它是否有区别)。

当我尝试运行它时,它给了我关于 pydevd.py 中某些内容的错误,最后给了我:

以 sr.Microphone 作为来源:

属性错误:进入

我该如何解决这个问题?

【问题讨论】:

    标签: python python-3.x speech-recognition pyaudio


    【解决方案1】:

    我通过将与捕获音频无关的语句移出 with 语句来使其工作,这应该适合你:

    import speech_recognition as sr
    
    rec = sr.Recognizer()
    
    print('say something')
    with sr.Microphone() as source:
        audio = rec.listen(source)
        voice_data = rec.recognize_google(audio)
    
    print(voice_data)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 1970-01-01
      相关资源
      最近更新 更多