Search code examples
javaandroidspeech-recognitiontranscription

Get transcription of recognized data using SpeechRecognizer


I use SpeechRecognizer for implement a "speech-to-text" functional and result of her work is a text data:

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.US.toString());
intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[]{});
SpeechRecognizer recognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
recognizer.setRecognitionListener(new RecognitionListener() {
  @Override
  public void onReadyForSpeech(Bundle params) {}

  @Override
  public void onBeginningOfSpeech() {}  

  @Override
  public void onRmsChanged(float rmsdB) {}

  @Override
  public void onBufferReceived(byte[] buffer) {}

  @Override
  public void onEndOfSpeech() {}

  @Override
  public void onError(int error) {}

  @Override
  public void onPartialResults(Bundle partialResults) {}

  @Override
  public void onEvent(int eventType, Bundle params) {}

  @Override
  public void onResults(Bundle results) {
    String result = null;
    ArrayList<String> arrOfResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    String command = arrOfResults.get(0);
  }
});
recognizer.startListening(intent);  

Is it possible to get a transcription of recognized speech instead of text using this method?
For example, as it was implemented in Google Translate:

Or, if necessary, use a different approach.

How can i do this? Thanks in advance. Regards...


Solution

  • The SpeechReocgnizer API only offers the "text" (normal orthographic text, I guess), and optionally the confidence scores, see: https://developer.android.com/reference/android/speech/RecognitionListener.html#onResults(android.os.Bundle)