我的人员助手项目:attributeError:找不到Pyaudio;检查安装

发布于 2025-02-10 18:40:46 字数 3623 浏览 0 评论 0原文

我正在尝试成为一名人员助手。当我运行代码时,代码可以在开始时说些什么,但是当涉及到下面显示的代码行时,会引发错误。 错误

    Traceback (most recent call last):
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\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\Koray\Desktop\Çalışmalar\Python\Jarvis\main.py", line 60, in <module>
    query = takeCommand().lower()
  File "C:\Users\Koray\Desktop\Çalışmalar\Python\Jarvis\main.py", line 33, in takeCommand
    with speech_recognition.Microphone() as source:
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\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

这是我试图安装Pyaudio的

    Collecting pyaudio
  Downloading PyAudio-0.2.11.tar.gz (37 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.10
      copying src\pyaudio.py -> build\lib.win-amd64-3.10
      running build_ext
      building '_portaudio' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyaudio
  Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... error
  error: subprocess-exited-with-error

  × Running setup.py install for pyaudio did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      running install
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.10
      copying src\pyaudio.py -> build\lib.win-amd64-3.10
      running build_ext
      building '_portaudio' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pyaudio

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

,但是出现了此错误:这是我的代码:

def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
    print("Listening...")
    r.pause_threshold = 1
    audio = r.listen(source)

try:
    print("Recognizing...")
    query = r.recognize_google(audio, language='en-US')
    print(f"User said: {query}/n")

except Exception as e:
    speak("Say that again please...")
    return "None"
return query

请帮助我吗?

I'm trying to make a personel assistant. When I run the code, the code works, it says what it should say at the beginning, but when it comes to the line of code I've shown below, it throws an error. Here is that error

    Traceback (most recent call last):
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\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\Koray\Desktop\Çalışmalar\Python\Jarvis\main.py", line 60, in <module>
    query = takeCommand().lower()
  File "C:\Users\Koray\Desktop\Çalışmalar\Python\Jarvis\main.py", line 33, in takeCommand
    with speech_recognition.Microphone() as source:
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\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

I try to pip install pyaudio but then this error show up:

    Collecting pyaudio
  Downloading PyAudio-0.2.11.tar.gz (37 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.10
      copying src\pyaudio.py -> build\lib.win-amd64-3.10
      running build_ext
      building '_portaudio' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyaudio
  Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... error
  error: subprocess-exited-with-error

  × Running setup.py install for pyaudio did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      running install
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.10
      copying src\pyaudio.py -> build\lib.win-amd64-3.10
      running build_ext
      building '_portaudio' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pyaudio

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

This is my code:

def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
    print("Listening...")
    r.pause_threshold = 1
    audio = r.listen(source)

try:
    print("Recognizing...")
    query = r.recognize_google(audio, language='en-US')
    print(f"User said: {query}/n")

except Exception as e:
    speak("Say that again please...")
    return "None"
return query

Please can you help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

通知家属抬走 2025-02-17 18:40:46

有两个可能解决此问题的解决方案

第一个解决方案:

pip install pipwin

然后

pipwin install pyaudio

第二解决方案:

sudo apt-get install portaudio19-dev python-pyaudio

然后

pip install PyAudio

there have two possible solution for solving this problem

1st solution:

pip install pipwin

then

pipwin install pyaudio

2nd solution:

sudo apt-get install portaudio19-dev python-pyaudio

then

pip install PyAudio
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文