我一直在網上衝浪(閱讀google/android開發人員文檔,閱讀stackoverflow的類似問題,閱讀本書),並非常仔細地遵循這些示例。 Text-to-Speech「speak」很棒。但我無法讓OnUtterance完成被調用。如何獲得OnUtterance完成被調用?
它一定很簡單,我沒有看到答案。請幫忙!這是我的代碼在幾次交互之後。
或者有人可以提供一個完整的源代碼(而不是片段),它可以真實地檢查它是否可以在我的模擬器/實際設備上運行?
public class testActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener {
...
protected void checkTtS() {
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, TTS_DATA_CHECK_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
....
if (requestCode == TTS_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
....
// Implements TextToSpeech.OnInitListener.
public void onInit(int status) {
// status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
if (status == TextToSpeech.SUCCESS) {
int result = mTts.setLanguage(Locale.FRANCE);
result = mTts.setOnUtteranceCompletedListener(this);
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");
mTts.speak("Text to Speak",TextToSpeech.QUEUE_FLUSH, params);
....
public void onUtteranceCompleted(String uttId) {
Toast.makeText(getBaseContext(), "onutterancecompleted", Toast.LENGTH_SHORT).show();
}
結果等於TextToSpeech.SUCCESS。所以setOnUtteranceCompletedListener被成功調用。但是,OnUtterance完成仍然不起作用 – mmmmm5