ImportError: libportaudio.so.2: 无法打开共享对象文件: raspberry-pi4 中没有这样的文件或目录

Moh*_*ris 4 speech-recognition speech-to-text pyaudio raspberry-pi4 pyaudioanalysis

我的代码:

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")
Run Code Online (Sandbox Code Playgroud)

几乎我检查了所有的可能性

发生了错误

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
Run Code Online (Sandbox Code Playgroud)

在处理上述异常的过程中,又出现了一个异常:


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
Run Code Online (Sandbox Code Playgroud)

小智 12

对于Python3:

sudo apt-get install python3-pyaudio 
Run Code Online (Sandbox Code Playgroud)