python - Pyaudio 没有找到,也无法安装。我的虚拟助手需要它
问题描述
我正在制作一个虚拟助手(如 windows 中的 cortana),但在导入语音识别并进行设置后,它显示错误“Pyaudio 未找到,检查安装”,或者详细地说,这就是我的全部错误在我运行它时得到。:
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
这是我的代码(它运行完美,直到希望函数,但是当我尝试说话或什至不说话时,它只是退出代码并出现上述错误):
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()
解决方案
要安装 Pyaudio,您必须这样做
pip install pipwin
pipwin install PyAudio
这对我有用。希望它也适用于你
推荐阅读
- c# - IdentityServer 4在登录/刷新令牌时获取时间戳
- sql - SQL 查询 SELECT 时间间隔
- macos - 如何从 docker 中手动删除 Kubernetes 集群
- python - 如何打印字典的所有子集?
- c++ - 为什么字符编码转换必须在 C++ 中如此困难?
- regex - 如何使用 zgrep 显示单词列表中所有 ax 大小的单词?
- angular - 将我的项目从 angular v7 迁移到 v8 后,收到与 @angular/fire 相关的警告
- sonarqube - 在 SonarQube 服务器上找不到文件
- apache-kafka - 如果会话窗口在保留期之前结束并且不活动间隙在保留期之后结束,会发生什么情况?
- git - 推送到 git 后恢复提交