本文介绍了synthesizeToFile失败:在Android中使用文字转语音时不绑定到TTS引擎,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Android的文字转语音API ,我想保存转换text2speech作为SD卡存储的文件,但我得到了错误:

  synthesizeToFile失败:不绑定到TTS引擎

我的code使用TTS是:

 公共无效的onActivityResult(INT申请code,INT结果code,意图意图){
        如果(要求code == MY_DATA_CHECK_ code){
            如果(结果code == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
                TTS =新的文字转语音(这一点,这一点);                如果(getIntent()!= NULL){
                    如果(getIntent()。getExtras()!= NULL){
                        。STRING D = getIntent()getExtras()的getString(数据);                        串数据[] = d.split( - );
                        BOOKNAME =数据[0];
                        loadPage(数据[0],的Integer.parseInt(数据[1]));
                    }
                }
                Log.d(TTS,数据加载);            }
            其他{
                意图installTTSIntent =新的Intent();
                installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installTTSIntent);
            }
        }
    }

,其中里面的 loadPage()函数的调用如下 synthesizeToFile 功能:

 字符串tempDestFile = appTmpPath.getAbsolutePath()+/+文件名;
tts.synthesizeToFile(speakTextTxt,myHashRender,tempDestFile);


解决方案

您必须等到的OnInit 调用之前,你可以叫讲话,synthesizeToFile 等...放在的OnInit 你的 loadPage 方法检查成功后有

I am using Android TextToSpeech API, I want to save the convert text2speech as a file on the SD-card memory, but I got the error:

 synthesizeToFile failed: not bound to TTS engine

My code to use TTS is :

public void onActivityResult(int requestCode, int resultCode, Intent intent) {


        if (requestCode == MY_DATA_CHECK_CODE) {
            if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
                tts = new TextToSpeech(this, this);

                if(getIntent() != null){
                    if(getIntent().getExtras()!=null){
                        String d = getIntent().getExtras().getString("data");

                        String data[] = d.split("-");
                        bookName = data[0];
                        loadPage(data[0], Integer.parseInt(data[1]));
                    }
                }
                Log.d("TTS","Data is loaded");

            }
            else {
                Intent installTTSIntent = new Intent();
                installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installTTSIntent);
            }
        }
    }

where inside the loadPage() function a call the synthesizeToFile function as below :

String tempDestFile = appTmpPath.getAbsolutePath() +"/"+ fileName;
tts.synthesizeToFile(speakTextTxt, myHashRender, tempDestFile);
解决方案

You have to wait until after onInit is called before you can call speak, synthesizeToFile etc... put your loadPage method in onInit after checking for success there.

这篇关于synthesizeToFile失败:在Android中使用文字转语音时不绑定到TTS引擎,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 05:18