【发布时间】:2021-04-10 03:08:56
【问题描述】:
我正在做一个需要 PyAudio 的 Python 项目,代码如下:
import pyttsx3
import speech_recognition as sr
import os
def take_commands():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening')
r.pause_threshold = 0.7
audio = r.listen(source)
try:
print("Recognizing")
Query = r.recognize_google(audio)
print("the query is printed='", Query, "'")
except Exception as e:
print(e)
print("Say that again sir")
return "None"
import time
time.sleep(2)
return Query
def Speak(audio):
engine = pyttsx3.init()
engine.say(audio)
engine.runAndWait()
Speak("Do you want to shutdown your computer sir?")
while True:
command = take_commands()
if "no" in command:
Speak("Thank u sir I will not shut down the computer")
break
if "yes" in command:
# Shutting down
Speak("Shutting the computer")
os.system("shutdown /s /t 30")
break
Speak("Say that again sir")
一开始我无法在Python解释器中添加PyAudio,所以我通过pip install pyaudio和conda install pyaudio安装了它。我遇到了错误,首先但最后我解决了它,最后我能够从 Python 解释器添加 PyAudio。但是,我仍然无法import pyaudio,当我运行我的代码时,我收到了这个错误:
Traceback (most recent call last):
File "C:\Users\moham\PycharmProjects\rich\venv\lib\site-packages\speech_recognition\__init__.py", line 107, 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:\Users\moham\OneDrive\الصور\Screenshots\ig-followers-master\shutdown.py", line 50, in <module>
command = take_commands()
File "C:\Users\moham\OneDrive\الصور\Screenshots\ig-followers-master\shutdown.py", line 17, in take_commands
with sr.Microphone() as source:
File "C:\Users\moham\PycharmProjects\rich\venv\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
self.pyaudio_module = self.get_pyaudio()
File "C:\Users\moham\PycharmProjects\rich\venv\lib\site-packages\speech_recognition\__init__.py", line 109, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
【问题讨论】:
-
我也无法运行 pipwin 虽然我在 cmd 中运行了这个命令“pip install pipwin”
标签: python python-3.x import pycharm pyaudio