繁体   English   中英

ModuleNotFoundError:Google Colab 中没有名为“pyaudio”的模块

[英]ModuleNotFoundError: No module named 'pyaudio' in Google Colab

我正在尝试制作一个基本的语音识别助手。 我有 Collab 的 Python 3.8.16 版。 我已经安装并导入了“pyaudio” ,如下所示:

!python --version
!pip install SpeechRecognition
!pip install pyttsx3
!pip3 install pyaudio
!pip install pipwin
!pipwin install pyaudio
!conda install -c anaconda pyaudio

import speech_recognition as sr
import pyttsx3
import pyaudio

但是在Collab中出现如下错误。 此代码在本地系统(即 Visual Studio)中运行良好。 但我需要在 Collab 上运行它。

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-14-67c5e290f749> in <module>
      9 import speech_recognition as sr
     10 import pyttsx3
---> 11 import pyaudio
     12 
     13 # Initialize recognizer class (for recognizing the speech)

ModuleNotFoundError: No module named 'pyaudio'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

这是我的完整代码:

r = sr.Recognizer()
try:
    with sr.Microphone() as mic:
        r.adjust_for_ambient_noise(mic,duration=0.1)
        audio = r.listen(mic)

        text = r.recognize_google(audio)
        text = text.lower()

        print(f"Recognized speech : {text}")
except sr.UnknownValueError:
    print("Could not understand audio")
except sr.RequestError as e:
    print("Could not request results; {0}".format(e)) 

我已经按照之前的 Stack Overflow 中给出的 Collab 上的“Pyaudio”运行了所有其他安装方法,但找不到任何方法来解决它。 我应该怎么办?

PyAudio 是 PortAudio 的包装器。 您需要先安装它。

!sudo apt install portaudio19-dev
!pip install pyaudio
import pyaudio

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM