我想安装 pyaudio 但出现以下错误。我正在使用 Windows 10。我已经尝试过多个其他答案中给出的解决方案,但它们对我不起作用。我正在遵循 YouTube 上的教程。
代码 :
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import os
r=sr.Recognizer()
engine = pyttsx3.init('sapi5')
voices=engine.getProperty('voices')
engine.setProperty('voice' , voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takecommand():
with sr.Microphone() as source:
print("Listening.....")
r.pause_threshold=1
o=r.listen(source)
try:
print("Wait for few moments")
query=r.recognize_google(o,language="en-in")
print("user said ", query)
except Exception as e :
print(e)
speak("Say that Again Please ")
if __name__ == "__main__":
wishme()
takecommand()
while True :
wishme()
query = takecommand().lower()
if"wikipedia" in query:
speak("Searching in wikipedia")
query=query.replace("wikipedia" ,"")
results=wikipedia.summary(query,sentences=2)
speak("According to wikipedia ")
speak(results)
print(results)
elif"open youtube" in query:
speak("opening Boss")
webbrowser.open("youtube.com")
elif "open google" in query:
speak("opening Boss")
webbrowser.open("google.com")
elif "open code"in query:
speak("opening Boss")
codepath = "C:\\Users\\Murali\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codepath)
elif "open chrome"in query:
speak("opening Boss")
chromepath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
os.startfile(chromepath)
Run Code Online (Sandbox Code Playgroud)
edit1:我也尝试过pip install PyAudio
,但没有成功
小智 9
对于遇到此问题的用户,如果您使用的是 Mac,则需要先通过 Homebrew 安装 portaudio。在他们的文档中,您需要按以下顺序运行命令:
brew install portaudio
pip install pyaudio
Run Code Online (Sandbox Code Playgroud)
请尝试使用以下拼写进行 pip 安装:
pip install PyAudio
Run Code Online (Sandbox Code Playgroud)
如果它不起作用,请从此页面下载文件 PyAudio,然后 cd 进入该目录并使用此命令python setup.py install