首页 > 解决方案 > 如果没有听到任何内容,Google Speech Recongizer 不会返回代码

问题描述

我需要检测用户是否没有说话。我正在使用以下意图来获取 Google 语音对话。有没有办法来解决这个问题?

public void askSpeechInput() {
    Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say Something!");
    i.putExtra(String.valueOf(RecognizerIntent.RESULT_CLIENT_ERROR), "Say Something!");
    i.putExtra(String.valueOf(RecognizerIntent.RESULT_AUDIO_ERROR), 201);
    i.putExtra(String.valueOf(RecognizerIntent.RESULT_SERVER_ERROR), 202);
    startActivityForResult(i, 200);
    refreshVoiceSettings();
}

标签: androidspeech-recognitiongoogle-speech-api

解决方案


推荐阅读