Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java CMUSphinx:未识别关键字_Java_Android_Speech Recognition_Pocketsphinx_Pocketsphinx Android - Fatal编程技术网

Java CMUSphinx:未识别关键字

Java CMUSphinx:未识别关键字,java,android,speech-recognition,pocketsphinx,pocketsphinx-android,Java,Android,Speech Recognition,Pocketsphinx,Pocketsphinx Android,几天前我做了语音识别服务,它工作得很好,但现在当我再次在手机中运行时,当我说一些东西时,它只是“onstart”和“onend”,没有被识别出来,但有时它是“onstart”,并听关键字采取行动。我如何确保每次我说关键字时它都能正确识别 public class VoiceService extends Service implements RecognitionListener{ private static final String LOG_TAG = VoiceService.c

几天前我做了语音识别服务,它工作得很好,但现在当我再次在手机中运行时,当我说一些东西时,它只是“onstart”和“onend”,没有被识别出来,但有时它是“onstart”,并听关键字采取行动。我如何确保每次我说关键字时它都能正确识别

public class VoiceService extends Service implements
    RecognitionListener{

private static final String LOG_TAG = VoiceService.class.getSimpleName();

private static final String KWS_SEARCH = "wakeup";
private static final String KEYPHRASE = "okay computer";
private SpeechRecognizer recognizer;

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
        runRecognizerSetup();
    }
    return super.onStartCommand(intent, flags, startId);
}

private void runRecognizerSetup() {
    // Recognizer initialization is a time-consuming and it involves IO,
    // so we execute it in async task
    new AsyncTask<Void, Void, Exception>() {
        @Override
        protected Exception doInBackground(Void... params) {
            try {
                Assets assets = new Assets(VoiceService.this);
                File assetDir = assets.syncAssets();
                setupRecognizer(assetDir);
            } catch (IOException e) {
                return e;
            }
            return null;
        }

        @Override
        protected void onPostExecute(Exception e) {
            if (e != null) {
                Log.i(LOG_TAG, "Failed to init recognizer ");
            } else {
              //  switchSearch(KWS_SEARCH);
                startListening(KWS_SEARCH);
            }
        }
    }.execute();
}

private void startListening(String kwsSearch) {
    recognizer.startListening(KWS_SEARCH);
    Log.i(LOG_TAG, "startedlistening");
}

@Override
public void onDestroy() {
}


@Override
public void onPartialResult(Hypothesis hypothesis) {
    if (hypothesis == null)
        return;

    String text = hypothesis.getHypstr();
    if (text.contains(KEYPHRASE)) {
        switchSearch(KWS_SEARCH);
    }
}

/**
 * This callback is called when we stop the recognizer.
 */
@Override
public void onResult(Hypothesis hypothesis) {
    if (hypothesis != null) {
        String text = hypothesis.getHypstr();
        Intent Intent = new Intent(this, ReceiverActivity.class);
        Intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(Intent);

    }

}

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


@Override
public void onEndOfSpeech() {
    if (!recognizer.getSearchName().contains(KWS_SEARCH))
        recognizer.stop();
        recognizer.startListening(KWS_SEARCH);
    Log.i(LOG_TAG, "onEndOfSpeech");
}

private void switchSearch(String searchName) {
    if (recognizer != null) {
        recognizer.stop();
        recognizer.startListening(searchName);

    }
}



private void setupRecognizer(File assetsDir) throws IOException {
    recognizer = SpeechRecognizerSetup.defaultSetup()

            .setAcousticModel(new File(assetsDir, "en-us-ptm"))
            .setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
            .setRawLogDir(assetsDir) 
            .setKeywordThreshold(1e-45f) 
            .setBoolean("-allphone_ci", true) 
            .getRecognizer();
    recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
    recognizer.addListener(this);
}

@Override
public void onError(Exception error) {
    Log.i(LOG_TAG, "onError " + error.getMessage());
}

@Override
public void onTimeout() {
    switchSearch(KWS_SEARCH);
    Log.i(LOG_TAG, "onTimeout");
}
}

你能提供一些关于识别语音或单词、字母的代码吗?添加了更多详细信息你确定你的
识别器是正确的吗工作正常吗?我的意思是这个问题发生在两种情况下。首先,当您的关键字识别器不工作或出错时,第二,语音识别器不工作或出错。我认为你应该在IE类或方法上调查这个问题。@GürtuğGüngör请查看我的其他问题,请提供完整的代码。你能提供一些关于识别语音或单词、字母的代码吗?添加了更多详细信息你确定你的
识别器。addKeyphraseSearch(KWSğu SEARCH,KEYPHRASE)工作正常吗?我的意思是这个问题发生在两种情况下。首先,当您的关键字识别器不工作或出错时,第二,语音识别器不工作或出错。我认为你应该调查关于IE类或方法的问题。@GürtuğGüngör请查看我的其他问题,请提供完整的代码。
okay computer /1e-30/