![](/img/trans.png)
[英]Speech_Recognition with python on computer speakers - OSError: [Errno -9998] Invalid number of channels
[英]Python SpeechRecognition - OSError: [Errno -9998] Invalid number of channels
我已经编程好几年了,但对 Python 还很陌生,我正在使用https://pypi.org/project/SpeechRecognition/在 Raspberry Pi 上实现一些语音识别,并将麦克风 output 方向传输到 Wit.ai。
我一直在使用 PocketSphinx 不断监听“唤醒词”,在我的 ubuntu VM 上,下面的代码运行良好
class Recognition:
def detection(self):
speech = LiveSpeech(lm=False, keyphrase='alexa', kws_threshold=1e-20)
print('Listening for wake word.');
for phrase in speech:
return self.start()
def start(self):
recognizer = sr.Recognizer()
print('Heard wake word, listening and streaming audio.')
with sr.Microphone(device_index=2) as source:
audio = recognizer.listen(source)
try:
content = recognizer.recognize_wit(audio, key=WIT_AI_KEY)
print(content)
except sr.UnknownValueError:
print("Unable to understand audio")
except sr.RequestError as e:
print("Error from Wit.ai: {}".format(e))
Recognition().detection()
但是在我的 Raspberry Pi 上运行它时,一旦触发了“唤醒词”,我就会从 PyAudio 收到以下错误: OSError: [Errno -9998] Invalid number of channels
如果我直接运行Recognition.start()
,只要我从Microphone()
中删除device_index
,它似乎就可以正常工作?
有谁知道这可能是什么原因? 就好像我删除了device_index
并仍然从一开始就运行Recognition().detection()
我得到一个IOError: No Default Input Device Available
请注意,在我的 Raspberry Pi 上通过arecord
录制时,音频输入/麦克风似乎录制得非常好。
对于将来遇到此问题的任何人来说,使用LiveSpeech
和SpeechRecognition
python 模块以及它们拥有自己的PyAudio
实例似乎是一个问题。
我不得不更改代码以初始化我自己的PyAudio
实例,然后使用与PocketSphinx
一起发送的Decoder
作为唤醒词,然后直接继续相同的stream
直接requests
Wit.ai。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.