I installed pocketsphinx using pip command
pip install pocketsphinx
i referred the link pocketsphinx installation
then i add a test.py and add code like this
from pocketsphinx import LiveSpeech
for phrase in LiveSpeech():
print(phrase)
then i run my file using python test.py command
but showing error
for phrase in LiveSpeech():
File "/home/pi/Sphinix/newvenv/lib/python3.7/site-packages/pocketsphinx/__init__.py", line 206, in __init__
self.ad = Ad(self.audio_device, self.sampling_rate)
File "/home/pi/Sphinix/newvenv/lib/python3.7/site-packages/sphinxbase/ad_pulse.py", line 122, in __init__
this = _ad_pulse.new_Ad(audio_device, sampling_rate)
RuntimeError: new_Ad returned -1
i tried
import pyaudio
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
print(p.get_device_info_by_index(i))
i got the result
{'index': 0, 'structVersion': 2, 'name': 'USB PnP Sound Device: Audio (hw:2,0)', 'hostApi': 0, 'maxInputChannels': 1, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.008684807256235827, 'defaultLowOutputLatency': -1.0, 'defaultHighInputLatency': 0.034829931972789115, 'defaultHighOutputLatency': -1.0, 'defaultSampleRate': 44100.0}
{'index': 1, 'structVersion': 2, 'name': 'dmix', 'hostApi': 0, 'maxInputChannels': 0, 'maxOutputChannels': 2, 'defaultLowInputLatency': -1.0, 'defaultLowOutputLatency': 0.021333333333333333, 'defaultHighInputLatency': -1.0, 'defaultHighOutputLatency': 0.021333333333333333, 'defaultSampleRate': 48000.0}
then i tried
from pocketsphinx import LiveSpeech
for phrase in LiveSpeech(audio_device=1):
print(phrase)
again showing
for phrase in LiveSpeech(audio_device=1):
File "/home/pi/Sphinix/newvenv/lib/python3.7/site-packages/pocketsphinx/__init__.py", line 206, in __init__
self.ad = Ad(self.audio_device, self.sampling_rate)
File "/home/pi/Sphinix/newvenv/lib/python3.7/site-packages/sphinxbase/ad_pulse.py", line 122, in __init__
this = _ad_pulse.new_Ad(audio_device, sampling_rate)
TypeError: in method 'new_Ad', argument 1 of type 'char const *'
How can i fix this.. ?
Let us see your output: If everything works your output should be list of phrases which you speak in text for your code above But throws an error. This is a clear indication that your LiveSpeech recognizer did not recognize. In order for this to work your LiveSpeech requires a MIC.in your case, It is clear that your audio device is being used by other processes. You can identify which service is using your audio device and terminate its process to release the audio device so that your code can use it.
You can use this command to find the process:
Once you release the sound card from the process using it, you should be able to run the code.