擅长:python、mysql、java
<p><code>AttributeError: __enter__</code>表示您正试图使用不支持上下文管理器协议的对象输入上下文管理器块;它没有<code>__enter__</code>方法</p>
<p>具体来说,您正试图在<code>with</code>语句中打开<code>sr.Microphone</code>类。根据<a href="https://github.com/Uberi/speech_recognition/blob/master/reference/library-reference.rst#microphonedevice_index-unionint-none none-sample_rate-int 16000-chunk_size-int 1024 -microphone" rel="nofollow noreferrer">documentation</a>,您需要向上下文管理器提供一个实例<code>sr.Microphone()</code></p>
<pre><code>with sr.Microphone() as source:
...
</code></pre>