-1

I'm trying to make a basic speech Recognition assistant. I have Python version 3.8.16 of Collab. I have installed as well as imported 'pyaudio' as follows:

!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

But the following error occurs in Collab. This code works fine in the local system i.e on Visual studio. But I need to run it on 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.
---------------------------------------------------------------------------

Here is my complete code:

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)) 

I have run all other installation methods for 'Pyaudio' on Collab as given in the previous Stack Overflow but can't find any way to resolve it. What should I do?

wovano
  • 4,543
  • 5
  • 22
  • 49

1 Answers1

0

PyAudio is a wrapper around PortAudio. You need to install it first.

!sudo apt install portaudio19-dev
!pip install pyaudio
import pyaudio
Paweł Kowalski
  • 524
  • 3
  • 9
  • @ZainabFatima, please don't ask follow-up questions in comments. See [here](https://meta.stackoverflow.com/questions/266767/what-is-the-the-best-way-to-ask-follow-up-questions). If you have a new question, ask a new question. – wovano Dec 16 '22 at 13:26
  • Actually you don't use pyaudio in your code at all... – Paweł Kowalski Dec 16 '22 at 13:46