安卓不承认TTS引擎 [英] Android not acknowledging TTS Engine

查看:134
本文介绍了安卓不承认TTS引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发这里一个非常简单的应用程序。这是我的脑瘫女儿。这只是一个大的YES和NO按钮,所以当要求她能preSS他们。

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.

嗯...我使用SVOX经典TTS引擎。

Well... I am using SVOX Classic TTS Engine.

一切都在顺利进行,直到我的平板电脑升级至ICS。现在,每次我运行的应用程序,它打开了市场要求我安装TTS。我打后退然后,我的应用程序讲。 这是很烦人的。

Everything was running smoothly until my tablet upgraded to ICS. Now, everytime I run the app, it opens the Market asking for me to install TTS. I hit "back" and then, my app speaks. This is VERY annoying.

下面是谷歌API说:

*一个成功的支票将由CHECK_VOICE_DATA_PASS结果code标记,表示该设备已准备好说话,创造我们的TextToSpeech对象之后。如果没有,我们需要让用户知道要安装的需要的该设备的数据成为一个多语言说话的机器!下载并安装由发射过的ACTION_INSTALL_TTS_DATA的意图,这将需要用户到Android市场完成的数据,并让她/他开始下载。一旦下载完成后安装数据会自动发生。这里是你实现onActivityResult()会是什么样子的例子:*

*A successful check will be marked by a CHECK_VOICE_DATA_PASS result code, indicating this device is ready to speak, after the creation of our TextToSpeech object. If not, we need to let the user know to install the data that's required for the device to become a multi-lingual talking machine! Downloading and installing the data is accomplished by firing off the ACTION_INSTALL_TTS_DATA intent, which will take the user to Android Market, and will let her/him initiate the download. Installation of the data will happen automatically once the download completes. Here is an example of what your implementation of onActivityResult() would look like:*

下面是我的code:

public class yesOunoActivity extends Activity implements OnInitListener{
ImageView yes;
ImageView no;
public TextToSpeech tts;
private int MY_DATA_CHECK_CODE = 0;

@Override
public void onCreate(Bundle savedInstanceState) {

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

    tts = new TextToSpeech(this, this);

    setContentView(R.layout.yesorno);

    yes = (ImageView) findViewById(R.id.yes);
    no = (ImageView) findViewById(R.id.no);


    yes.setClickable(true); 
    yes.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent arg1) {

             if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN) {                             
                 tts.speak("yes!", TextToSpeech.QUEUE_ADD, null);
             }
             return true;
        }
    });


    no.setClickable(true); 
    no.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent arg1) {

             if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN) {                             

                //Intent myIntent = new Intent(v.getContext(), ParametrosActivity.class);
                tts.speak("no!", TextToSpeech.QUEUE_ADD, null);
             }
            return true;
    }

    });


}


@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
            tts = new TextToSpeech(this, this);
        } else {
            // missing data, install it
            //ATTENTION: BELOW THIS GIVES ME PROBLEMS SINCE IT OPENS MARKET
            //AND I HAVE TO HIT THE BACK BUTTON, THEN, IT SPEAKS!
            //BTW TTS ENGINE "IS" INSTALLED!!
            Intent installIntent = new Intent();
            installIntent
                    .setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }

}

@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
    } else if (status == TextToSpeech.ERROR) {
    }
}

@Override
public void onDestroy() {
    if (tts != null) {
        tts.stop();
        tts.shutdown();
    }
    super.onDestroy();
    System.gc();
}

    }

如果我删除了注意之上的区域(因为我相信我已经安装了TTS),它的工作原理我第一次运行该应用程序,如果我离开了应用程序,我再次打开它,它说的 说话失败:不绑定到TTS引擎

If I remove the area with "ATTENTION" above (since I am SURE I have TTS installed), it works the first time I run the app, if I leave the app and I open it again, it says "speak failed: not bound to tts engine"

这就像它不会创建TTS对象,因为应用程序仍在内存。

It's like it doesn't create the TTS object since the app is still in memory.

所以,你们...你们怎么认为,我应该怎么办?

So, guys... what do you guys think that I should do??

这是推动我疯了,我真的很需要通过平板电脑来沟通,我的女儿!

This is driving me crazy and I really need to communicate to my daughter through the tablet!

任何帮助是AP preciated !!

Any help is appreciated!!

推荐答案

这是我在 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);                
    }
}

而不是使用如果(结果code == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)的{...} ,我检查 MTTS 已被实例化。您还必须设置 MTTS 静态,正如在以前的帖子中提到由jlquant和拉克什,所以你就会有它的只有一个实例。例如,私有静态TextToSpeech MTTS

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.

所以,除非你强制停机的应用程序,或者停止,因为一个错误的工作,也不会再调用 startActivity(installIntent); - 中恼人的罪魁祸首,要求您每一次安装TTS。

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.

这篇关于安卓不承认TTS引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆