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:
JavaScript
x
36
36
1
#!/usr/bin/env python
2
3
import os
4
import speech_recognition as sr
5
from pocketsphinx import AudioFile
6
7
hmm = '/home/ridwan/sphinx/other2/model_parameters/other2.ci_cont' #folder of the acoustic model
8
lm = '/home/ridwan/sphinx/other2/etc/other2.lm.DMP' #language model
9
dict = '/home/ridwan/sphinx/other2/etc/other2.dic' #the phonetic dictionary
10
11
#model_path = get_model_path()
12
#data_path = get_data_path()
13
14
r = sr.Recognizer()
15
with sr.Microphone() as source:
16
print("Please wait. Calibrating microphone...")
17
# listen for 5 seconds and create the ambient noise energy level
18
r.adjust_for_ambient_noise(source, duration=5)
19
print("Say something!")
20
audio = r.listen(source)
21
22
config = {
23
'verbose': False,
24
'audio_file': audio,
25
'buffer_size': 2048,
26
'no_search': False,
27
'full_utt': False,
28
'hmm': hmm,
29
'lm': lm,
30
'dict': dict
31
}
32
33
audio = AudioFile(**config)
34
for phrase in audio:
35
print(phrase)
36
The Traceback:
JavaScript
1
9
1
Traceback (most recent call last):
2
File "main2.py", line 15, in <module>
3
with sr.Microphone() as source:
4
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 79, in __init__
5
self.pyaudio_module = self.get_pyaudio()
6
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/__init__.py", line 113, in get_pyaudio
7
raise AttributeError("PyAudio 0.2.11 or later is required (found version {})".format(pyaudio.__version__))
8
AttributeError: PyAudio 0.2.11 or later is required (found version 0.2.10)
9
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:
JavaScript
1
2
1
#!/usr/bin/env python3
2
- invoke it directly on the command line when calling the script:
JavaScript
1
2
1
$ python3 myscript.py
2
These will fix your issue and use the correct version of python to run the program.