In android 4.1 you can get real-time speech to text conversion using the microphone option on the keyboard.
I've been looking at the docs for android.speech trying to find out how to implement real-time speech to text for an application. However, the only option that would facilitate this is the "EXTRA_PARTIAL_RESULTS" option (Which the server ignores every time I try to use it).
The code:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "VoiceIME");
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 3000L);
mSpeaker.startListening(intent);
Never returns partial results.
I know this is possible since the keyboard version does it consistently. Anyone know how?
Before you call startListening
you need to register the onPartialResults
-callback. Two important things to note:
onPartialResults
is called is not specified by the Android API;So your code will be specific to Google Voice Search.
mSpeaker.setRecognitionListener(new RecognitionListener() {
...
public void onPartialResults(Bundle partialResults) {
// WARNING: The following is specific to Google Voice Search
String[] results =
partialResults.getStringArray("com.google.android.voicesearch.UNSUPPORTED_PARTIAL_RESULTS");
updateTheUi(results);
}
...
}
To see this callback in action in an open source app, see Babble:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With