Android not acknowledging TTS Engine

后端 未结 6 1009
孤独总比滥情好
孤独总比滥情好 2021-02-04 13:10

I am developing a very simple app in here. It\'s for my Cerebral Palsy daughter. It\'s just a big YES and NO buttons, so she can press them when requested.

Well... I am

6条回答
  •  醉梦人生
    2021-02-04 13:52

    I had this trouble on my application as well: TTS works in 2.3, but when I tried 4.0, it had the same symptoms as your problem (which I just found now while searching for a solution). The engine would work if you force-closed the application through Settings and started it again but just "backing out" and going back made the TTS engine in ICS not bind.

    I tried setting the TTS object (mTts) to null after running mTts.shutdown(). When I started the application again after backing out, I got a null error on my mTts.speak() line.

    At least for ICS, something is not letting go of the TTS engine. My solution (for now) is that I have made my TTS object static:

    // in Activity
    private static TextToSpeech mTts;
    .
    .
    .
    // in onCreate()
    mTts = new TextToSpeech(this, this);
    .
    .
    .
    // in onDestroy()
    if (mTts != null) {
       mTts.stop();
       mTts.shutdown();
       mTts = null;
    }
    

    I was already only using one TTS object for the application so I don't think there are too many downsides to this approach.

提交回复
热议问题