web-dev-qa-db-fra.com

AttributeError: Impossible de trouver PyAudio; vérifier l'installation ... impossible d'utiliser la reconnaissance vocale

J'essaie de faire un assistant de reconnaissance vocale de base. Lorsque j'exécute le code, il me dit:

Traceback (most recent call last):
  File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\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:/Users/Mo.haytham/.PyCharmCE2018.3/config/scratches/ALPHA_BASIC.py", line 22, in <module>
    hear()
  File "C:/Users/Mo.haytham/.PyCharmCE2018.3/config/scratches/ALPHA_BASIC.py", line 13, in hear
    with sr.Microphone() as sourse:
  File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:\Users\Mo.haytham\AppData\Local\Programs\Python\Python37\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 

J'ai essayé de pip install pyaudio mais cette erreur apparaît:

Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... error
    ERROR: Complete output from command 'c:\users\mo.haytham\appdata\local\programs\python\python37\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\MO2D8C~1.HAY\\AppData\\Local\\Temp\\pip-install-o2
10x3zl\\pyaudio\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\MO2
D8C~1.HAY\AppData\Local\Temp\pip-record-hr7kket1\install-record.txt' --single-version-externally-managed --compile:
    ERROR: running install
    running build
    running build_py
    creating build
    creating build\lib.win-AMD64-3.7
    copying src\pyaudio.py -> build\lib.win-AMD64-3.7
    running build_ext
    building '_portaudio' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.Microsoft.com/downloads/
    ----------------------------------------
ERROR: Command "'c:\users\mo.haytham\appdata\local\programs\python\python37\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'C:\\Users\\MO2D8C~1.HAY\\AppData\\Local\\Temp\\pip-install-o210x3zl\\pyaudio\\setup.p
y'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\MO2D8C~1.HAY\AppData\Local\
Temp\pip-record-hr7kket1\install-record.txt' --single-version-externally-managed --compile" failed with error code 1 in C:\Users\MO2D8C~1.HAY\AppData\Local\Temp\pip-install-o210x3zl\pyaudio\
def hear():
    import speech_recognition as sr
    ear = sr.Recognizer()
    with sr.Microphone() as sourse:
        print("listening...")
        audio = ear.listen(sourse)
        try:
            text = ear.recognize_google(audio)
            print(text)
        except:
            print("i didn't get that...")

hear()
3
Mo .haytham

Vous obtenez une erreur d'installation de pyaudio car vous n'avez pas d'outils de construction c ++ pour installer pyaudio.

Pour installer Mircosoft visual C++ 14.0, considérez ce lien https://stackoverflow.com/a/49986365/82274

puis, installez pyaudio.

si vous utilisez un ordinateur portable jupyter sur anaconda Prompt,

conda install pyaudio

si vous utilisez le cahier jupyter en utilisant cmd puis sur la cellule jupyter,

import sys
!{sys.executable} -m pip install pyaudio

si vous exécutez python sur cmd alors,

pip3 install pyaudio #for python3
0
Aashish Mamgain

Sudo apt-get installer libportaudio-dev (essayez d'abord avec cela) Sudo apt-get installez portaudio19-dev (utilisez-le à la place) installez plus tard pyaudio (python -m pip installez PyAudio)

0
Nikhil08

Si vous êtes un utilisateur ubuntu 18.04, suivez ces étapes

Sudo apt-get install portaudio19-dev python-pyaudio

Ensuite

pip install PyAudio
0
rupesh

Il semble qu'il vous manque certains fichiers requis pour construire pyaudio.

Depuis votre journal des erreurs,

Microsoft Visual C++ 14.0 est requis. Obtenez-le avec "Microsoft Visual C++ Build> Tools": https://visualstudio.Microsoft.com/downloads/

Vous devrez installer Microsoft Visual C++ Build Tools

0
Kevin Beeman