3

My code:

import speech_recognition as sr
r = sr.Recognizer()

with sr.Microphone() as source:
    print("talk")
    audio_text = r.listen(source)
    print("time over")
    
    try:
        text = r.recognize_google(audio_text)
        print("converting the audio text into transript")
        print(text)
    except:
       print("Run again")

almost I checked the all posiblity

Error OCCURED

Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.9/site-packages/speech_recognition/__init__.py", line 108, in get_pyaudio
    import pyaudio
  File "/usr/local/lib/python3.9/dist-packages/pyaudio.py", line 116, in <module>
    import _portaudio as pa
ImportError: libportaudio.so.2: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "/home/pi/Desktop/sample.py", line 6, in <module>
    with sr.Microphone() as source:
  File "/home/pi/.local/lib/python3.9/site-packages/speech_recognition/__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "/home/pi/.local/lib/python3.9/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
Mohamed Faris
  • 31
  • 1
  • 3

2 Answers2

11

For Python3:

sudo apt-get install python3-pyaudio 
Monocito
  • 125
  • 1
  • 1
  • 7
0
sudo apt-get install python-pyaudio

works like a charm if it doesn't try other ideas here

B Shmid
  • 1
  • 2