2012-06-06 31 views

回答

1

這位官員Android Blog Post給你最好的做法,如果安裝了TTS引擎,並準備使用,以及對TTS等手法來檢測。

1

要保存點擊:

啓動這個或檢查是否安裝了TTS沒有:

Intent checkIntent = new Intent(); 
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); 
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE); 

然後拿到導致此:

private TextToSpeech mTts; 
protected void onActivityResult(
    int requestCode, int resultCode, Intent data) { 
if (requestCode == MY_DATA_CHECK_CODE) { 
    if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { 
     // success, create the TTS instance 
     mTts = new TextToSpeech(this, this); 
    } else { 
     // missing data, install it 
     Intent installIntent = new Intent(); 
     installIntent.setAction(
      TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); 
     startActivity(installIntent); 
    } 
} 
} 
+0

但是這個代碼是如何幫助我知道,無論是通過TTS引擎與否和第2的東西支持的特定語言:如何設置默認引擎到其他TTS引擎? – piks

11

您可以通過檢查首先發送意圖結果

Intent intent = new Intent(); 
intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); 
startActivityForResult(intent, 0); 

然後,你可以檢查它,如果你已經安裝了TTS引擎或不onActivityResult方法:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
if(requestCode == 0){ 
    if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){ 
    Toast.makeText(getApplicationContext(),"Already Installed", Toast.LENGTH_LONG).show(); 
} else { 
    Intent installIntent = new Intent(); 
    installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); 
    startActivity(installIntent); 
    Toast.makeText(getApplicationContext(),"Installed Now", Toast.LENGTH_LONG).show(); 
} 

希望工程:)

+0

但這段代碼如何幫助我知道TTS引擎是否支持特定的語言,以及第二件事:如何將默認引擎設置爲其他TTS引擎? – piks

+0

答案1:Theres函數稱爲isLanguageAvailable(Locale.FRANCE);答2:我不明白你的問題! @piks –

+0

第二個問題是:假設設備安裝了多個TTS引擎,並且一個引擎將其設置爲默認值(通常爲PICO),但默認TTS不支持所有語言讓我們說葡萄牙語,在這種情況下,我的應用程序應該先檢查是否目前設置默認引擎支持葡萄牙語或不,那麼它會設置其他安裝TTS和驗證相同..如何實現它programmaticaly? – piks

1

這給你安裝在你的Android TTS引擎列表。

tts = new TextToSpeech(this, this); 
for (TextToSpeech.EngineInfo engines : tts.getEngines()) { 
Log.d("Engine Info " , engines.toString()); 
} 
相關問題