Android not acknowledging TTS Engine

后端 未结 6 1001
孤独总比滥情好
孤独总比滥情好 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:37

    in my app I also used checkintent.setAction(...) to check if the necessary tts files are installed (which was working like a charm before upgrading to ICS). In ICS it always returned that the files are missing. So now I just ignore this check: i am creating the object and it initializes fine. Moreover I was using two instances for two different languages. This also seems to not work anymore. Now when I set the language for one of the instances, the other instance of the object is set to the same language (behaves like one instance).

    0 讨论(0)
  • 2021-02-04 13:39

    This is what I have in onActivityResult(...)

    @Override
    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);
            }
    */
            if (mTts==null) {
                Intent installIntent = new Intent();
                installIntent.setAction(
                    TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installIntent);                           
            }
            mTts = new TextToSpeech(this, this);                
        }
    }
    

    Instead of using if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {...}, I check if mTts has already been instantiated. You'll also have to set mTts as static, as was mentioned by jlquant and Rakesh in an earlier post, so you'll have only a single instance of it. For example, private static TextToSpeech mTts.

    So, unless you "Force stop" the app or it stops working because of an error, it won't anymore call the startActivity(installIntent);-- the annoying culprit that asks you to install TTS every time.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-04 13:53

    gingerbread allowed setting of default tts in voice input& output / default tts

    gingerbread only allows 'preferred' tts in language and input / text to speech output.

    so tts is preferred instead of default, which just means it is not as clear as to which gets used.

    The default with application overrides where stated is a better option I think.

    0 讨论(0)
  • 2021-02-04 13:54

    I had the same problem and solved. Maybe it's a timing issue in bounding, not sure, but a simple action before speak helped me. Anyway I did this:

    mTts = new TextToSpeech(this, this);

    String engine = mTts.getDefaultEngine();

    mTts = new TextToSpeech(this, this,engine);

    Log.d("","...something here...");

    Then when I hit my speak button, it speaks. You should watch your variable status on OnInit method. Maybe a separate thread can help talking in the app.

    By the way, if you are sure TTS is installed, you can remove the block Intent checkIntent = new Intent(); for checking.

    I definitely hope this helps you.

    0 讨论(0)
  • 2021-02-04 14:00

    I fixed this by installing ivona having both Tts engines cured all problems, though I'm finding other issues such as no default tts is installed using the two together makes one work not a great fix but its s fix,

    Also I can't find the option to allow my phone to install non market apps ie apk from my SD card

    0 讨论(0)
提交回复
热议问题