speech-recognition - pocketsphinx - 如何从关键字识别切换到语法模式

标签 speech-recognition speech-to-text cmusphinx pocketsphinx

我正在使用 pocketsphinx 和树莓派来实现家庭自动化。我用支持的命令编写了一个简单的 JSGF 语法文件。现在,我想在命令之前使用激活短语,例如“嘿计算机”,以避免错误检测,并且仅在说出激活短语后才执行语音识别。

如果我没有理解错的话,pocketsphinx 支持两种语音识别模式:关键字识别模式和语言模型/JSGF 语法模式。

pocketsphinx FAQ在解决如何拒绝不合语法的单词的问题时,它说:

If you want to recognize several commands, you can use keyword spotting mode or keyword activation mode combined with the switch to grammar to perform actual operation.

我的问题是,从关键字识别模式到语法模式的“切换”到底是如何实现的? (我应该做什么来实现它?)。与此相关,“关键字发现模式”和“关键字激活模式”有什么区别?

谢谢!

最佳答案

引用自 tutorial :

开发者可以配置多个具有不同语法和语言模型的“搜索”对象,并在运行时切换它们,为用户提供交互体验。

有不同的可能的搜索模式:

  • 关键字 - 有效地查找关键短语并忽略其他语音。 允许配置检测阈值
  • 语法 - 识别语音 根据 JSGF 语法。与关键词语法不同,搜索不会 忽略语法中不存在的单词,但尝试识别它们。
  • ngram/lm - 使用语言模型识别自然语音。
  • allphone - 使用语音语言模型识别音素。

每个搜索都有一个名称,并且可以通过名称引用,名称是特定于应用程序的。函数 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()

关于speech-recognition - pocketsphinx - 如何从关键字识别切换到语法模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39069614/

相关文章:

android - 如何在我的 Android 应用程序中添加继续语音识别?

speech-recognition - 如何在帧上分割语音数据并计算 MFCC

java - 使用 cmu sphinx 进行语音识别 - 无法正常工作

python - pocketsphinx python gstreamer 音频速率

linux - HTK:HCompV ReadString:字符串太长

ios - 连续语音识别1分钟后无需重启

c# - 在 WPF 应用程序中激活 Dragon Naturally Speaking Full-Text Control 功能

Azure Batch 转录 : Error when downloading the recording URI. 状态代码:冲突(下载失败)

node.js - 使用node js将语音保存到本地文本

java - 如何使用 java 检测 wav 文件中是否存在单词/音频静音?