How to wait for TextToSpeech initialization on Android

后端 未结 2 1120
天涯浪人
天涯浪人 2021-01-19 06:47

I am writing an activity that speaks to the user and I\'d really like to block on TextToSpeech initialization - or else time out. How can I get my thread to wait?

I

2条回答
  •  情书的邮戳
    2021-01-19 07:16

    You need to initialize the TTS system within e.g. the activities onCreate() method, so that you can use it later when the user e.g. clicks a button.

    See e.g. https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L62 where setupspeak() is called and then later speak() ( https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/OneTweetActivity.java#L344 ) which is then called when the user clicks the 'speak' button.

提交回复
热议问题