android - Pocketsphinx - 完善热词检测

标签 android voice-recognition cmusphinx pocketsphinx pocketsphinx-android

我重新访问了 CMU Sphinx最近并尝试为 Android 设置一个基本的热词检测器,从 tutorial 开始并调整 sample application .

我遇到了各种问题,尽管深入研究了他们的文档,但我一直无法解决这些问题,直到我无法阅读更多...

为了复制它们,我做了一个基本项目,旨在检测关键字wakeup youwakeup me .

我的字典:

me M IY
wakeup W EY K AH P
you Y UW

我的语言模型:

\data\
ngram 1=5
ngram 2=5
ngram 3=4

\1-grams:
-0.9031 </s> -0.3010
-0.9031 <s> -0.2430
-1.2041 me -0.2430
-0.9031 wakeup -0.2430
-1.2041 you -0.2430

\2-grams:
-0.3010 <s> wakeup 0.0000
-0.3010 me </s> -0.3010
-0.6021 wakeup me 0.0000
-0.6021 wakeup you 0.0000
-0.3010 you </s> -0.3010

\3-grams:
-0.6021 <s> wakeup me
-0.6021 <s> wakeup you
-0.3010 wakeup me </s>
-0.3010 wakeup you </s>

\end\

以上两个都是使用 suggested tool 创建的.

还有我的关键短语文件:

wakeup you /1e-20/
wakeup me /1e-20/

改编上面链接的示例应用程序,这是我的代码:

public class PocketSphinxActivity extends Activity implements RecognitionListener {

    private static final String CLS_NAME = PocketSphinxActivity.class.getSimpleName();

    private static final String HOTWORD_SEARCH = "hot_words";

    private volatile SpeechRecognizer recognizer;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        setContentView(R.layout.main);

        new AsyncTask<Void, Void, Exception>() {
            @Override
            protected Exception doInBackground(Void... params) {
                Log.i(CLS_NAME, "doInBackground");

                try {

                    final File assetsDir = new Assets(PocketSphinxActivity.this).syncAssets();

                    recognizer = defaultSetup()
                            .setAcousticModel(new File(assetsDir, "en-us-ptm"))
                            .setDictionary(new File(assetsDir, "basic.dic"))
                            .setKeywordThreshold(1e-20f)
                            .setBoolean("-allphone_ci", true)
                            .setFloat("-vad_threshold", 3.0)
                            .getRecognizer();

                    recognizer.addNgramSearch(HOTWORD_SEARCH, new File(assetsDir, "basic.lm"));
                    recognizer.addKeywordSearch(HOTWORD_SEARCH, new File(assetsDir, "hotwords.txt"));
                    recognizer.addListener(PocketSphinxActivity.this);

                } catch (final IOException e) {
                    Log.e(CLS_NAME, "doInBackground IOException");
                    return e;
                }

                return null;
            }

            @Override
            protected void onPostExecute(final Exception e) {
                Log.i(CLS_NAME, "onPostExecute");

                if (e != null) {
                    e.printStackTrace();
                } else {
                    recognizer.startListening(HOTWORD_SEARCH);
                }
            }
        }.execute();
    }

    @Override
    public void onBeginningOfSpeech() {
        Log.i(CLS_NAME, "onBeginningOfSpeech");
    }

    @Override
    public void onPartialResult(final Hypothesis hypothesis) {
        Log.i(CLS_NAME, "onPartialResult");

        if (hypothesis == null)
            return;

        final String text = hypothesis.getHypstr();
        Log.i(CLS_NAME, "onPartialResult: text: " + text);

    }

    @Override
    public void onResult(final Hypothesis hypothesis) {
        // unused
        Log.i(CLS_NAME, "onResult");
    }

    @Override
    public void onEndOfSpeech() {
        // unused
        Log.i(CLS_NAME, "onEndOfSpeech");
    }


    @Override
    public void onError(final Exception e) {
        Log.e(CLS_NAME, "onError");
        e.printStackTrace();
    }

    @Override
    public void onTimeout() {
        Log.i(CLS_NAME, "onTimeout");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(CLS_NAME, "onDestroy");

        recognizer.cancel();
        recognizer.shutdown();
    }
}

注意:- 我是否应该更改我选择的关键短语(和其他相关文件)以使其更加不同并且我在安静的环境中测试实现,应用的设置和阈值工作非常成功。

问题

  1. 当我说叫醒你叫醒我时,两者都会被检测到。

我无法确定如何对结束音节应用增加的权重。

  1. 当我说只是唤醒时,通常(但不总是)两者都会被检测到。

我无法确定如何避免这种情况的发生。

  1. 在针对背景噪音进行测试时,误报过于频繁。

我不能降低我正在使用的基本阈值,否则在正常情况下无法始终如一地检测到关键短语。

  1. 如果长时间针对背景噪音进行测试(5 分钟应该足以复制),立即返回安静的环境并说出关键短语,则不会检测到任何结果。

成功并重复检测关键短语需要一段不确定的时间——就好像测试是在安静的环境中开始的。

我找到了一个 potentially related question ,但链接不再有效。我想知道我是否应该更频繁地重置识别器,以便以某种方式重置背景噪声,使其不被平均到检测阈值?

  1. 最后,我想知道我对有限关键词的要求是否允许我减小声学模型的大小?

在我的应用程序中打包时的任何开销当然都是有益的。

最后(老实说!),特别希望 @NikolayShmyrev会发现这个问题,有没有计划完全通过 gradle 包装基本的 Android 实现/sdk?

我感谢那些走到这一步的人......

最佳答案

My language model:

您不需要语言模型,因为您不使用它。

I can't lower the base thresholds I am using, otherwise the keyphrases are not detected consistently under normal conditions.

1e-20 是一个合理的阈值,您可以提供错误检测的样本记录,让我更好地了解发生了什么。

When testing against background noise for a long period (5 minutes should be sufficient to replicate), returning immediately to a quiet environment and uttering the keyphrases, results in no detection.

这是预期的行为。总的来说,长背景噪声使识别器更难快速适应音频参数。如果您的任务是在嘈杂的地方识别单词,最好使用某种硬件降噪功能,例如具有降噪功能的蓝牙耳机。

Finally, I wonder if my requirements for limited keyphrases, would allow me to reduce the size of the acoustic model?

现在不可能了。如果你只是为了发现你可以尝试 https://snowboy.kitt.ai

关于android - Pocketsphinx - 完善热词检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39310163/

相关文章:

离线Android语音 Activity 检测

android - 使用 PocketSphinx 识别多个关键字

cmusphinx - 如果 sphinx 完全不准确怎么办?

Android:从电话号码中检索联系人姓名

android - 使用 usbmanager api 将 USB 命令发送到热敏打印机

java - 当我更改微调器选择时,为什么我的应用程序崩溃了?

android - 如何使用语音命令绕过 android 主屏幕锁定来激活应用程序?请给我一些指导方针

android - 从 Firebase 存储中获取图像

azure - 如何在Azure中进行语音识别并立即完成

machine-learning - 将 CMU Sphinx 的置信度得分转换为概率时的偏差