i installed pyaudio and portaudio but i get error

61 Views Asked by At

in this code for convert speech to text in python

import speech_recognition as sr
# ساخت یک شیء از کلاس Recognizer
recognizer = sr.Recognizer()

# ضبط صدا از میکروفون
with sr.Microphone() as source:
    print("لطفاً گفتار خود را شروع کنید...")
    audio = recognizer.listen(source)



    text = recognizer.recognize_google(audio)
    print(f"متن تشخیص داده شده: {text}")

i get an error: ( mac OS 14 )

Exception has occurred: AttributeError Could not find PyAudio; check installation ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyaudio/_portaudio.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '_PaMacCore_SetupChannelMap'

During handling of the above exception, another exception occurred:

File "/Users/amir/Desktop/Untitled-1.py", line 6, in with sr.Microphone() as source: ^^^^^^^^^^^^^^^ AttributeError: Could not find PyAudio; check installation

but i installed pyaudio

1

There are 1 best solutions below

1
Aliht On

You must install the library in the version of Python you are using

if you are using vscode you can change your python version with:

  1. Hit F1 or ⇧⌘P from your keyboard
  2. >python:Select interpreter
  3. select your version

for example if you are using python3.11, you can install the library with command:

python3.11 -m pip install LIBRARY_NAME