我正在制作一个虚拟助手(就像windows中的cortana ),但就在导入语音识别并对其进行设置后,它显示了一个错误"Pyaudio not found,check installation“,或者更详细地说,这就是我在运行它时得到的全部错误。:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py", line 108, in get_pyaudio
import pyaudio
ModuleNotFoundError: No module named 'pyaudio'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\machine_learning\raw_ai\Virtual assistant.py", line 59, in <module>
take()
File "C:\machine_learning\raw_ai\Virtual assistant.py", line 31, in take
with sr.Microphone() as source:
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
self.pyaudio_module = self.get_pyaudio()
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py", line 110, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation以下是我的代码(它可以完美地运行到wish函数,但当我试图说话或甚至不说话时,它只会退出上面的错误代码):
import pyttsx3
import datetime
import speech_recognition as sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wish():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour <= 12:
speak("Good morning !")
elif hour > 12 and hour <= 5:
speak("Good Aftrenoon !")
else:
speak("Good night")
speak("How may I help you ?")
def take():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening.....")
r.pause_threshold(1)
audio = r.listen(source)
try:
print("Recognisizing...")
query = r.recognize_google(audio, Language = 'en-in')
print(f"User said : {query}\n")
except Exception as e:
print("Come Again ?")
return "None"
return query
if __name__ == "__main__":
wish()
take()发布于 2021-07-04 18:31:56
要安装Pyaudio,您必须执行以下操作
pip install pipwin
pipwin install PyAudio这对我很有效。希望它也适用于你
https://stackoverflow.com/questions/64640167
复制相似问题