How do you use Android's real time speech to text? How do you use Android's real time speech to text? android android

How do you use Android's real time speech to text?


Before you call startListening you need to register the onPartialResults-callback. Two important things to note:

  • the structure of the bundle with which onPartialResults is called is not specified by the Android API;
  • not every speech recognizer supports this callback.

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 want real-time partial results to show up while the mic is on , while the speaker is speaking, you might want to drop approach using recognizerIntent and drop recognitionService in favor of a simple android text box combined with prior selection of the 'mic' icon like you can do in the android 'notes' sample app...

see ./samples/android-16/NotePad/tests/src/com/example/android/notepad

This combo provides the feature like u see in real time the partial text-from-speech results as they come back from the server-side 'voiceSearch' which is somehow different from 'recognizer' regarding the 'partial' callback.

Numerous comments state that recognizerIntent does not fire a callback to 'onPartialResults'. For some reason, android 4.2 does not seem to support the 'continuous' speechRecognition mode that works fine using javascript. My tests of 'RecognitionListener' interface on 4.2 show hundreds of callbacks to 'onRmsChanged' on volume events , but zero activity on the 'partialResult' event. Somewhere , this callback gets lost??

for js solution, install chrome-beta release 25 and go here

using android notes app. sample and pre-selecting the mic icon from the keyboard, you can do exactly the same thing as the JS webapp link above.


Since we cannot know for sure the key names of the Bundle coming in from partial results callback, use this to find out its contents:

public void onPartialResults(Bundle partialResults) {        String string = "Bundle{";    for (String key : partialResults.keySet()) {        string += " " + key + " => " + partialResults.get(key) + ";";    }     Log.e("joshtag","onPartialResults"+string);    //see the keynames in Logcat and extract partial reesults here}