I try to use speech to text. This example is ok, but I don't want to call the intent and use the dialog.
I create a speech recognizer instance and it listens the intent.
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(getContext());
sr.setRecognitionListener(new RecognitionListener() {
@Override
public void onResults(Bundle b) {
Log.i("TAG", " onResults "); }
@Override
public void onBeginningOfSpeech() {
Log.i("TAG", " onBeginningOfSpeech ");
}@Override
public void onRmsChanged(float rmsdB) {
Log.i("TAG" , " onRmsChanged " + rmsdB);
}
@Override
....
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
sr.startListening(intent);
When I run this code, onRmsChanged triggers many times. So I comment out Log.i("TAG" , " onRmsChanged " + rmsdB);
.
onReadyForSpeech -> onBeginningOfSpeech -> onEndOfSpeech -> onResults. But timeout is too short time.
Now, I want to wait a while in silence. How can I do? It should listen until I call sr.stoplistening()