jot*_*cas 3 speech-recognition speech-to-text cmusphinx pocketsphinx
我正在使用带有树莓派的 Pocketsphinx 来实现家庭自动化。我用支持的命令编写了一个简单的 JSGF 语法文件。现在,我想在命令之前使用诸如“嘿计算机”之类的激活短语,以避免错误检测,并且仅在说出激活短语后才执行语音识别。
如果我没弄错的话,pocketsphinx 支持两种语音识别模式:关键字识别模式和语言模型/JSGF 语法模式。
在解决如何拒绝语法外单词的问题时,pocketsphinx 常见问题解答中说:
如果要识别多个命令,可以使用关键字发现模式或关键字激活模式结合切换到语法进行实际操作。
我的问题是,这种从关键字识别模式到语法模式的“切换”究竟是如何实现的?(我应该怎么做才能实现它?)。与此相关,“关键字发现模式”和“关键字激活模式”有什么区别?
谢谢!
引自教程:
开发者可以配置多个不同语法和语言模型的“搜索”对象,并在运行时进行切换,为用户提供交互体验。
有多种可能的搜索模式:
每个搜索都有一个名称并且可以通过名称引用,名称是特定于应用程序的。该功能ps_set_search允许激活先前按名称添加的搜索。
添加搜索需要指向描述搜索的语法/语言模型。语法的位置特定于应用程序。如果只需要简单的识别,添加单个搜索或仅使用配置选项配置所需的模式就足够了。
搜索的确切设计取决于您的应用程序。例如,您可能希望首先侦听激活关键字,一旦识别出关键字,就切换到 ngram 搜索以识别实际命令。识别命令后,您可以切换到语法搜索以识别确认,然后切换回关键字侦听模式以等待另一个命令。
在 Python 中切换搜索的代码如下所示:
# Init decoder
config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
decoder = Decoder(config)
# Add searches
decoder.set_kws('keyword', 'keyword.list')
decoder.set_lm_file('lm', 'query.lm')
decoder.set_search('keyword')
import pyaudio
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
stream.start_stream()
in_speech_bf = False
decoder.start_utt()
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
if decoder.get_in_speech() != in_speech_bf:
in_speech_bf = decoder.get_in_speech()
if not in_speech_bf:
decoder.end_utt()
# Print hypothesis and switch search to another mode
print 'Result:', decoder.hyp().hypstr
if decoder.get_search() == 'keyword':
decoder.set_search('lm')
else:
decoder.set_search('keyword')
decoder.start_utt()
else:
break
decoder.end_utt()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5396 次 |
| 最近记录: |