我已经编程好几年了,但对Python语言还很陌生,我使用https://pypi.org/project/SpeechRecognition/在Raspberry Pi上实现了一些语音识别,并将麦克风输出方向流式传输到Wit.ai。
我一直在使用PocketSphinx不断地监听“唤醒词”,在我的ubuntu虚拟机上,下面的代码运行得很好
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()但是当在我的树莓派上运行它时,一旦“唤醒词”被触发,我就会收到来自PyAudio的以下错误:OSError: [Errno -9998] Invalid number of channels
如果我直接运行Recognition.start(),只要我从Microphone()中删除device_index,它似乎就能正常工作
有人知道这可能是什么原因吗?就好像我删除了device_index,但仍然从一开始就运行Recognition().detection()一样,我得到了一个IOError: No Default Input Device Available
只需注意,在我的树莓派上通过arecord录制时,音频输入/麦克风似乎录制得非常好。
发布于 2020-05-13 17:00:45
对于将来遇到这个问题的任何人来说,使用LiveSpeech和SpeechRecognition python模块并拥有自己的PyAudio实例似乎是一个问题。
我必须更改代码来初始化我自己的PyAudio实例,然后使用与PocketSphinx一起发送的用于唤醒单词的Decoder,然后直接将相同的stream直接继续到用于Wit.ai的requests。
https://stackoverflow.com/questions/61739755
复制相似问题