Pix*_*xel 17 android speech-recognition cmusphinx
我已经安装了PocketSphinx演示版,它在Ubuntu和Eclipse下工作正常,但是尽管我尝试了,但我无法弄清楚如何添加多个单词的识别.
我想要的只是代码识别单个单词,然后我可以switch()
在代码中,例如"向上","向下","向左","向右".我不想识别句子,只想单个单词.
对此有任何帮助将不胜感激.我发现其他用户有类似的问题,但到目前为止还没有人知道答案.
令我困惑的一件事是为什么我们需要使用"唤醒"常数?
private static final String KWS_SEARCH = "wakeup";
private static final String KEYPHRASE = "oh mighty computer";
.
.
.
recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
Run Code Online (Sandbox Code Playgroud)
什么wakeup
与任何事情有关?
我已经取得了一些进展(?):使用addGrammarSearch
我能够使用一个.gram
文件列出我的单词,例如up,down,left,right,forwards,backwards
,如果我说的都是那些特定的单词,这似乎很有效.但是,任何其他单词都会导致系统与所述的"最近"单词相称.理想情况下,如果所说的单词不在.gram
文件中,我不希望发生识别...
Pix*_*xel 19
感谢Nikolay的提示(请参阅上面的回答),我开发了以下代码,该代码工作正常,除非它们在列表中,否则无法识别单词.您可以直接在PocketSphinxDemo代码中的主类上复制并粘贴它:
public class PocketSphinxActivity extends Activity implements RecognitionListener
{
private static final String DIGITS_SEARCH = "digits";
private SpeechRecognizer recognizer;
@Override
public void onCreate(Bundle state)
{
super.onCreate(state);
setContentView(R.layout.main);
((TextView) findViewById(R.id.caption_text)).setText("Preparing the recognizer");
try
{
Assets assets = new Assets(PocketSphinxActivity.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)
{
}
@Override
public void onResult(Hypothesis hypothesis)
{
((TextView) findViewById(R.id.result_text)).setText("");
if (hypothesis != null)
{
String text = hypothesis.getHypstr();
makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onBeginningOfSpeech()
{
}
@Override
public void onEndOfSpeech()
{
reset();
}
private void setupRecognizer(File assetsDir)
{
File modelsDir = new File(assetsDir, "models");
recognizer = defaultSetup().setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
.setDictionary(new File(modelsDir, "dict/cmu07a.dic"))
.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);
}
}
Run Code Online (Sandbox Code Playgroud)
你的digits.gram
文件应该是这样的:
up /1e-1/
down /1e-1/
left /1e-1/
right /1e-1/
forwards /1e-1/
backwards /1e-1/
Run Code Online (Sandbox Code Playgroud)
您应该在//
性能的双斜线内试验阈值,其中1e-1
表示0.1(我认为).我认为最大值是1.0
.
现在是下午5点30分,所以我现在可以停止工作了.结果.
Nik*_*rev 14
你可以使用addKeywordSearch
哪些用途来存放关键短语.例如,每行一个短语,其中包含//中每个短语的阈值
up /1.0/
down /1.0/
left /1.0/
right /1.0/
forwards /1e-1/
Run Code Online (Sandbox Code Playgroud)
必须选择阈值以避免误报.
归档时间: |
|
查看次数: |
16995 次 |
最近记录: |