Python LiveSpeech PocketSphinx

我的未来我决定 提交于 2019-11-28 02:22:01

问题


pocketsphinx_continuous -adcdev plughw:1,0 -inmic yes -dict 4711.dic -lm 4711.lm

The above command works but the problem arises in running python code.

from pocketsphinx import LiveSpeech
for phrase in LiveSpeech(): print(phrase)

the error that is displayed

Error opening audio device (null) for capture: Connection refused
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pocketsphinx/__init__.py", line 206, in __init__
    self.ad = Ad(self.audio_device, self.sampling_rate)
  File "/usr/local/lib/python2.7/dist-packages/sphinxbase/ad_pulse.py", line 124, in __init__
    this = _ad_pulse.new_Ad(audio_device, sampling_rate)
RuntimeError: new_Ad returned -1

回答1:


You are probably experiencing it with USB microphone (e. g. on RaspberryPi). It tells you, that LiveSpeech doesn't know, which audio device to use for input. Luckily according to https://github.com/bambocher/pocketsphinx-python#default-config there are several configuration options - so you need to specify audio_device.

basically lets do:

for phrase in LiveSpeech(audio_device=3): print(phrase)

where 3 please replace with your desired microphone ID. Now how to get it:

import pyaudio

p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
    print(p.get_device_info_by_index(i))
#otherwise you can do:
print(p.get_default_input_device_info())

There are several topics on how to properly set up USB microphone on RaspberryPi - if its your case, let me know.



来源:https://stackoverflow.com/questions/51780090/python-livespeech-pocketsphinx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!