2013-05-30 66 views
3

我開發了一個基於Android 2.3的TTS的應用程序。 我注意到,在最新版本的Android(4.2.2)中,例如,沒有默認安裝的默認TTS語言,您必須手動下載它們: 設置 - >語言和輸入 - >文本到語音輸出 - >谷歌文本轉語音 - >安裝語音數據自動下載安卓TTS引擎

有沒有辦法自動安裝一種語言?

回答

6

有沒有辦法自動安裝一種語言?

是的,但不會自動(未經用戶許可)作爲docs提到的發生:

由於數據的安裝可以被中斷或用戶下降,應用程序不應該期望從該意圖返回時成功安裝...

無論如何,您可以觸發安裝方法如this

/** 
* Ask the current default engine to launch the matching INSTALL_TTS_DATA activity 
* so the required TTS files are properly installed. 
*/ 
private void installVoiceData() { 
    Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); 
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    intent.setPackage("com.google.android.tts"/*replace with the package name of the target TTS engine*/); 
    try { 
     Log.v(TAG, "Installing voice data: " + intent.toUri(0)); 
     startActivity(intent); 
    } catch (ActivityNotFoundException ex) { 
     Log.e(TAG, "Failed to install TTS data, no acitivty found for " + intent + ")"); 
    } 
}