2016-06-12 58 views
1

在我的應用程序中,我嘗試創建一個語音識別器,從文本到語音谷歌API,用於土耳其語,並通過EXTRA_LANGUAGE_PREFERENCE作爲「tr_TR」識別並返回土耳其語的結果,但其識別內容英語但不是土耳其語。如何爲SpeechRecognizer設置土耳其語語音Google SpeechToText APi

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); 
+1

你從哪兒弄來的'tur'?它是'tr_TR',從Android 2.3開始支持。看到這個[post](http://stackoverflow.com/questions/7973023/what-is-the-list-of-supported-languages-locales-on-android)供您參考。 –

+0

您是否嘗試過「tr-TR」? –

+0

好的,但是你在哪裏將語言環境更改爲土耳其語? –

回答

2

我,在我的代碼的問題:

 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); 
0

土耳其語的語言代碼是「tr」。以下是我使用它的方式。

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