我编写了以下代码,以便从麦克风获取输入:
import speech_recognition as sr
import pyaudio
#import playsound
import webbrowser
from gtts import gTTS
def get_audio():
r = sr.Recognizer()
with sr.Microphone as source:
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio)
print(said)
except Exception:
print("Error")
return(said)
get_audio()
但是它引发了以下错误:
line 12, in get_audio
with sr.Microphone as source:
AttributeError: __enter__
Process finished with exit code 1
我已经安装了pyaudio(必需版本)和wheel文件,但是问题仍然存在...请帮助我摆脱这种情况...