1

In my application I am trying to create a speech recognizer from text to speech google Api for turkish and passing EXTRA_LANGUAGE_PREFERENCE as "tr_TR" to recognize and return result in Turkish but its recognizing in English but not in Turkish.

String lang_code="tr_TR";    
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
                    lang_code);
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, lang_code);
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                    this.getPackageName());
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                    RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
            recognizerIntent.putExtra(RecognizerInt

ent.EXTRA_MAX_RESULTS, 3);
Faisal Naseer
  • 4,110
  • 1
  • 37
  • 55
  • 1
    Where did you get `tur` from? it's `tr_TR`, supported since Android 2.3. See this [post](http://stackoverflow.com/questions/7973023/what-is-the-list-of-supported-languages-locales-on-android) for your reference. – Phantômaxx Jun 12 '16 at 10:03
  • Have you tried "tr-TR"? – Nickolai Astashonok Jun 12 '16 at 10:16
  • OK, but where do you change your locale to Turkish? – Phantômaxx Jun 12 '16 at 10:22
  • @Bob Malooga I dont know how to change that Where to modify the code accordingly. – Faisal Naseer Jun 12 '16 at 10:25
  • Where you need the SpeechToText to react to Turkish. You can find some inspirations in this [post](http://stackoverflow.com/questions/2264874/changing-locale-within-the-app-itself) – Phantômaxx Jun 12 '16 at 10:35
  • @BobMalooga actually in my application there is button which when pressed start SpeechRecognition and listens for a specific Turkish Word e.g. "Evet" meaning "Yes" in English and fill a TextBox Accordingly. But When I press button it Listens and returns some matching text in English. However I have tested the result in google chrome and its displaying right result. – Faisal Naseer Jun 12 '16 at 10:43
  • So, in your Button, switch to the Turkish locale BEFORE starting the SpeechToText engine. – Phantômaxx Jun 12 '16 at 10:57

2 Answers2

3

I fixed that problem in my code:

        language = "tr-TR";

        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, language);
        intent.putExtra(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES, language);
        intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, language);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, language);
        intent.putExtra(RecognizerIntent.EXTRA_RESULTS, language);
        startActivityForResult(intent, REQUEST_CODE);
elifekiz
  • 1,456
  • 13
  • 26
0

Language code for Turkish is "tr". Below is the way I used it.

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "tr");
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
MNEkin
  • 46
  • 1
  • 5