I am trying to run the following python program but i am getting some errors. The program is intended to convert livespeech to text and it is using an acoustic model which I have trained using CMUSphinx.
The code:
#!/usr/bin/env python import os import speech_recognition as sr from pocketsphinx import AudioFile hmm = '/home/ridwan/sphinx/other2/model_parameters/other2.ci_cont' #folder of the acoustic model lm = '/home/ridwan/sphinx/other2/etc/other2.lm.DMP' #language model dict = '/home/ridwan/sphinx/other2/etc/other2.dic' #the phonetic dictionary #model_path = get_model_path() #data_path = get_data_path() r = sr.Recognizer() with sr.Microphone() as source: print("Please wait. Calibrating microphone...") # listen for 5 seconds and create the ambient noise energy level r.adjust_for_ambient_noise(source, duration=5) print("Say something!") audio = r.listen(source) config = { 'verbose': False, 'audio_file': audio, 'buffer_size': 2048, 'no_search': False, 'full_utt': False, 'hmm': hmm, 'lm': lm, 'dict': dict } audio = AudioFile(**config) for phrase in audio: print(phrase)
The Traceback:
Traceback (most recent call last): File "main2.py", line 15, in <module> with sr.Microphone() as source: File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 79, in __init__ self.pyaudio_module = self.get_pyaudio() File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 113, in get_pyaudio raise AttributeError("PyAudio 0.2.11 or later is required (found version {})".format(pyaudio.__version__)) AttributeError: PyAudio 0.2.11 or later is required (found version 0.2.10)
But I have already installed PyAudio 0.2.11. When I do pip install pyaudio
, I get the following:
Requirement already satisfied: pyaudio in /usr/local/lib/python3.5/dist-packages (0.2.11)
Advertisement
Answer
Your error message indicates that it is using a pyaudio installed in python2.7, but your error message at the bottom is referencing a pyaudio in python3. Try using python3 explicitly to call the program. You can ensure that by doing the following:
- Change the shebang line at the top of the file to tell the shell what to use to execute the script:
#!/usr/bin/env python3
- invoke it directly on the command line when calling the script:
$ python3 myscript.py
These will fix your issue and use the correct version of python to run the program.