【问题标题】:Define a new keyword in pocket sphinx在袖珍狮身人面像中定义一个新关键字
【发布时间】:2016-10-04 10:05:51
【问题描述】:

我对此很陌生。
我想做的是:

  • 从 Speech To Text 引擎获取用户定义的 KEYWORD
  • 正如它所识别的那样,我的应用做了一些事情

我阅读了 PocketSphinix,但找不到我的, 我也觉得很难,所以我更喜欢改变它并使用默认的。

现在我的问题是:如何在 *.gram 文件中定义一个新的关键字“我的手机”?

这是我的代码 - 我拿走了它here:

import android.app.Activity;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.SpeechRecognizer;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.IOException;

import edu.cmu.pocketsphinx.Assets;
import edu.cmu.pocketsphinx.Hypothesis;
import edu.cmu.pocketsphinx.SpeechRecognizerSetup;

/**
 * Created by Mina Joon jooni on 6/4/2016.
 */
public class PracticeActivity  extends Activity implements RecognitionListener, edu.cmu.pocketsphinx.RecognitionListener {

private static final String DIGITS_SEARCH = "digits";
    private edu.cmu.pocketsphinx.SpeechRecognizer recognizer;

    @Override
public void onCreate(Bundle state)
{
    super.onCreate(state);

    setContentView(R.layout.practice);

    ((TextView) findViewById(R.id.caption_text)).setText("Preparing the recognizer");

    try
    {
        Assets assets = new Assets(PracticeActivity.this);
        File assetDir = assets.syncAssets();
        setupRecognizer(assetDir);
    }
    catch (IOException e)
    {
        // oops
    }

    ((TextView) findViewById(R.id.caption_text)).setText("Say up, down, left, right, forwards, backwards");

    reset();
}

@Override
public void onPartialResult(Hypothesis hypothesis)
{//DO STH
}

@Override
public void onResult(Hypothesis hypothesis)
{
    ((TextView) findViewById(R.id.result_text)).setText("");

    if (hypothesis != null)
    {
        String text = hypothesis.getHypstr();
        Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
    }
}

@Override
public void onError(Exception e) {

}

@Override
public void onTimeout() {

}

@Override
public void onReadyForSpeech(Bundle params) {

}

@Override
public void onBeginningOfSpeech()
{
}

@Override
public void onRmsChanged(float rmsdB) {

}

@Override
public void onBufferReceived(byte[] buffer) {

}

@Override
public void onEndOfSpeech()
{
    reset();
}

@Override
public void onError(int error) {

}

@Override
public void onResults(Bundle results) {

}

@Override
public void onPartialResults(Bundle partialResults) {

}

@Override
public void onEvent(int eventType, Bundle params) {

}

private void setupRecognizer(File assetsDir) throws IOException {
    File modelsDir = new File(assetsDir, "models");

    recognizer = SpeechRecognizerSetup.defaultSetup()
            .setAcousticModel(new File(modelsDir, "en-us-ptm"))
            .setDictionary(new File(modelsDir, "cmudict-en-us.dict"))
            .setRawLogDir(assetsDir).setKeywordThreshold(1e-20f)
            .getRecognizer();

    recognizer.addListener(this);

    File digitsGrammar = new File(modelsDir, "grammar/digits.gram");
    recognizer.addKeywordSearch(DIGITS_SEARCH, digitsGrammar);
}

private void reset()
{
    recognizer.stop();
    recognizer.startListening(DIGITS_SEARCH);
}
}

我该如何做第一个?
请帮帮我!

【问题讨论】:

    标签: android keyword pocketsphinx


    【解决方案1】:

    使用

    recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar);
    

    代替

    recognizer.addKeywordSearch(DIGITS_SEARCH, digitsGrammar);
    

    同样根据文件名修改assets.lst。

    【讨论】:

    • 这两行看起来真的很像。我不得不看两次不同之处:以方法的名称.addGrammarSearch.addKeywordSearch。我认为您可以在回答中详细说明这一点。顺便说一句,欢迎来到 SO! ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多