android - Android 中的语音命令关键字监听器

标签 android voice-recognition google-voice

我想在我的应用程序中添加语音命令监听器。服务应该监听预定义的关键字,如果说出关键字,它应该调用一些方法。

语音命令识别(激活命令)无需向 Google 语音服务器发送请求即可工作。

我如何在 Android 上执行此操作?

感谢您发布一些有用的资源。

最佳答案

您可以使用 Pocketsphinx 来完成此任务。检查Pocketsphinx android demo例如,如何在离线状态下有效地收听关键字并对特定命令使用react,例如关键字“oh mighty computer”。这样做的代码很简单:

您创建一个识别器并添加关键字识别搜索:

recognizer = SpeechRecognizerSetup.defaultSetup()
        .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
        .setDictionary(new File(modelsDir, "lm/cmu07a.dic"))
        .setKeywordThreshold(1e-40f)
        .getRecognizer();

recognizer.addListener(this);
recognizer.addKeyphraseSearch("keywordSearch", "oh mighty computer");
recognizer.startListening("keywordSearch);

并定义一个监听器:

@Override
public void onPartialResult(Hypothesis hypothesis) {
    if (hypothesis == null)
          return;
    String text = hypothesis.getHypstr();
    if (text.equals(KEYPHRASE)) {
      //  do something and restart listening
      recognizer.cancel();
      doSomething();
      recognizer.startListening("keywordSearch");
    }
} 

您可以调整关键字阈值以获得最佳检测/误报匹配。为达到理想的检测准确度,关键字应至少包含 3 个音节,最好是 4 个音节。

关于android - Android 中的语音命令关键字监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24321893/

相关文章:

android - 包权限的含义(邀请所有android开发者贡献)

c# - 发音评分(语音正确性)

android - 非常简单的语音/语音识别算法

android - 在 Android 中实现 Google 语音操作

javascript - Webkit Speech api - 一般问题

android - "react-native link"Android 失败 "no such file or directory"

android - 获取 map 的标记作为 View

Android 谷歌地图 apk 显示灰色瓷砖

mobile - TensoFlow可以学习非结构化数据吗?

android - 语音识别API,Google Voice会做这个吗?