gpt4 book ai didi

java - 语音识别在android中超时太快

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:39:10 25 4
gpt4 key购买 nike

这个函数启动了语音识别,但是超时太快了,好像是语音识别从 IME 键盘(例如 Google 键盘)启动,它不会很快超时。我需要一种方法来启动与谷歌键盘所使用的相同的 Intent 。

public void StartSpeechRecognitionActivity(){
try{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 3000);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000);
main.startActivityForResult(intent, SPEECHRECOGNITION_RESULTCODE);
} catch (ActivityNotFoundException error) {
ShowAndSpeakMessage("Speech recognition is not supported by your device");
} catch( RuntimeException error ) {
Log.e( TAG, ERROR_PREFIX + Errors.toString(error) );
} catch( Error error ) {
Log.e( TAG, ERROR_PREFIX + Errors.toString(error) );
throw error;
}
}

最佳答案

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"Voice recognition!");
startActivityForResult(intent, REQUEST_CODE);

这对我来说很好用!

关于java - 语音识别在android中超时太快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17653188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com