我搜索了Google的所有可用文档,但我找不到Python中音频流上的流语音识别示例.
目前,我在Django中使用Python语音识别来获取用户的音频,然后收听音频.然后我可以保存文件并运行谷歌语音识别或直接从创建的音频实例.
有人可以指导我如何在音频流上执行流式语音识别吗?
我已经在 python 中安装并设置了 pocketsphinx 和 sphinxbase 包。我还为 github 获取了语音识别代码,并根据要求更改了数据和模式目录,但是当我尝试通过“python test.py”运行它时仍然无法通过语音进行流式传输这里是代码:
#!/usr/bin/env python
import os
import sphinxbase as sb
import pocketsphinx as ps
MODELDIR = '/usr/lib/python2.7/site-packages/speech_recognition/pocketsphinx-data'
DATADIR='/usr/lib/python2.7/site-packages/speech_recognition/pocketsphinx-data'
# Create a decoder with certain model
config = ps.Decoder.default_config()
config.set_string('-hmm', "/usr/lib/python2.7/site-packages/speech_recognition/pocketsphinx-data/en-US/acoustic-model")
config.set_string('-lm', os.path.join(MODELDIR, 'en-US/language-model.lm.bin'))
config.set_string('-dict', os.path.join(MODELDIR, 'en-US/pronounciation-dictionary.dict'))
decoder = ps.Decoder(config)
# Decode streaming data.
decoder.start_utt()
stream = open(os.path.join(DATADIR, 'en-US/goforward.raw'), 'rb')
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
else:
break
decoder.end_utt()
stream.close()
print('Best hypothesis segments:', [seg.word for seg in decoder.seg()])
Run Code Online (Sandbox Code Playgroud)
请告诉我如何执行它。