【问题标题】:AttributeError: __enter__ while trying to take input from microphoneAttributeError: __enter__ 尝试从麦克风获取输入
【发布时间】:2020-03-09 13:14:39
【问题描述】:

我一直在尝试使用 Speech_recognition 从我的 Python 程序中的麦克风获取输入

我尝试运行这段代码:-

import speech_recognition as sr
import pyaudio
r = sr.Recognizer()
with sr.Microphone as source:
    audio = r.listen(source)
    text = r.recognize_google(audio)
    print(text)

但它没有运行。

上面写着:-

"C:\Users\Bravo Six\AppData\Local\Programs\Python\Python37-32\python.exe" "D:/BROTEEN/Works/Python/VALINI/speech testing.py"
Traceback (most recent call last):
  File "D:/BROTEEN/Works/Python/VALINI/speech testing.py", line 9, in <module>
    with sr.Microphone as source:
AttributeError: __enter__

进程以退出代码 1 结束

我该如何解决这个问题???请帮助我摆脱这种情况!!!

I Ctrl + clicked on the sr.**Microphone**, wherein I saw that it said it throws an attribute error when pyaudio 0.2.11 or later is not installed. So I installed it using cmd, but the problem still sustains... HELP!!!


【问题讨论】:

  • 我的猜测是使用with sr.Microphone() as source,乍一看似乎你只是在使用类而不是麦克风对象
  • 没听懂。我怎么做。我在youtube上关注了很多教程。!!!但问题仍然存在(顺便说一句,我在 Windows 7 上)

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


【解决方案1】:

同样的问题发生在我身上,我通过这样的编码解决了它:

with sr.Microphone() as source:
   #your code here

我希望这有助于解决您的问题。如果您仍有问题,请告诉我。

【讨论】:

    【解决方案2】:

    其实我发现 Windows 7 不能轻易地与speech_recognition 模块配合......所以我刚切换到 Windows 10,现在它像黄油一样流畅!谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-07
      • 2011-08-09
      相关资源
      最近更新 更多