2015-02-24 100 views
0

我正在開發應用程序以顯示英語中的一些細節,並且當我單擊該按鈕時,它會以英語說出該消息,文本也包含數字。我想在泰盧固文語言中發言,有沒有什麼辦法可以做到。默認的android tts不支持泰盧固語,如何在android應用中使用外部的tts引擎。請幫助我,謝謝。如何在Android應用程序中將文字與語言結合爲泰盧固語語言

+0

檢查這一項:HTTP://stackoverflow.com/questions/ 22495332/how-to-display-south-indian-languages-in-android/22497074#22497074 – Afsar 2015-02-24 11:52:31

回答

0
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    tts = new TextToSpeech(this, this); 
    btnSpeak = (Button) findViewById(R.id.btnSpeak); 
    txtText = (EditText) findViewById(R.id.txtText); 
    // button on click event 
    btnSpeak.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View arg0) { 
      speakOut(); 
     } 
    }); 
} 

// shutdown tts when activity destroy 
@Override 
public void onDestroy() { 
    // Don't forget to shutdown! 
    if (tts != null) { 
     tts.stop(); 
     tts.shutdown(); 
    } 
    super.onDestroy(); 
} 

// It will called before TTS started 
@Override 
public void onInit(int status) { 
    // TODO Auto-generated method stub 
    // check status for TTS is initialized or not 
    if (status == TextToSpeech.SUCCESS) { 
     // if TTS initialized than set language 
     result = tts.setLanguage(Locale.US); 

     // tts.setPitch(5); // you can set pitch level 
     // tts.setSpeechRate(); //you can set speech speed rate 

     // check language is supported or not 
     // check language data is available or not 
     if (result == TextToSpeech.LANG_MISSING_DATA 
       || result == TextToSpeech.LANG_NOT_SUPPORTED) { 
      Toast.makeText(this, "Missing data", Toast.LENGTH_LONG).show(); 
      // disable button 
      btnSpeak.setEnabled(false); 
     } else { 
      // if all is good than enable button convert text to speech 
      btnSpeak.setEnabled(true); 
     } 
    } else { 
     Log.e("TTS", "Initilization Failed"); 
    } 
} 

// call this method to speak text 
private void speakOut() { 
    String text = txtText.getText().toString(); 
    if (result != tts.setLanguage(Locale.US)) { 
     Toast.makeText(getApplicationContext(), "Enter right Words...... ", 
       Toast.LENGTH_LONG).show(); 
    } else { 
     // speak given text 
     tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); 
    } 
} 

u必須設置語言環境,在法說出來

注意:手機和eclipse應該支持您的語言環境

+0

但是,谷歌默認tts不支持泰盧固語。它如何爲泰盧固語語言工作。 – user2273358 2015-02-25 05:21:11

+0

我沒有嘗試它,但你可以檢查http://www.findbestopensource.com/product/aa-tts – 2015-02-25 05:28:41

+0

我沒有得到這個,我不明白如何使用這個在Android應用程序 – user2273358 2015-02-25 06:45:16

相關問題