首页 > 解决方案 > 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()

标签: pythonpython-3.x

解决方案


要安装 Pyaudio,您必须这样做

pip install pipwin
pipwin install PyAudio

这对我有用。希望它也适用于你


推荐阅读