Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

python - AttributeError: Could not find PyAudio; check installation...can't use speech Recognition

I'm trying to make a basic speech Recognition assistant. When I run the code, it tells me:

Traceback (most recent call last):
  File "C:UsersMo.haythamAppDataLocalProgramsPythonPython37libsite-packagesspeech_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:UsersMo.haythamAppDataLocalProgramsPythonPython37libsite-packagesspeech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:UsersMo.haythamAppDataLocalProgramsPythonPython37libsite-packagesspeech_recognition\__init__.py", line 110, in get_pyaudio
    raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation 

I tried to pip install pyaudio but then this error shows up:

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:usersmo.haythamappdatalocalprogramspythonpython37python.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('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersMO2
D8C~1.HAYAppDataLocalTemppip-record-hr7kket1install-record.txt' --single-version-externally-managed --compile:
    ERROR: running install
    running build
    running build_py
    creating build
    creating buildlib.win-amd64-3.7
    copying srcpyaudio.py -> buildlib.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:usersmo.haythamappdatalocalprogramspythonpython37python.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('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersMO2D8C~1.HAYAppDataLocal
Temppip-record-hr7kket1install-record.txt' --single-version-externally-managed --compile" failed with error code 1 in C:UsersMO2D8C~1.HAYAppDataLocalTemppip-install-o210x3zlpyaudio
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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In Terminal type

pip install pipwin

Then

pipwin install pyaudio

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...