rxlabz / speech_recognition

A Flutter plugin to use speech recognition on iOS & Android (Swift/Java)
https://pub.dartlang.org/packages/speech_recognition
Other
336 stars 197 forks source link

Android local language speech detect and text in local language #96

Open ghure opened 4 years ago

ghure commented 4 years ago

I had issues in android for local language recognition.

Issue was speech_recognition was not detecting selected language and was giving error java.lang.IndexOutOfBoundsException

My code: _speechRecognition .listen(locale: "en-US") .then((result) => print('$result')); });

_speechRecognition .listen(locale: "mr-IN") .then((result) => print('$result')); });

After spending long time on issue, i resolved issue by changing code in SpeechRecognitionPlugin.java -> line no 67 -> recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, call.arguments.toString());

After changing this code works fine in android. So can any one update this line in android code Thanks.

WhatsApp Image 2020-05-24 at 7 16 29 PM

pinkeshmars commented 3 years ago

In SpeechRecognitionPlugin.java, you can also change a method like this.

private Locale getLocale(String code) {
    String[] localeParts;
    if(code.contains("_")){
        localeParts = code.split("_");
    }else{
        localeParts = code.split("-");
    }
    return new Locale(localeParts[0], localeParts[1]);
}