synthesizeToFile失败:在Android中使用文字转语音在未结合TTS引擎,(synt

2019-10-29 12:22发布

我使用Android TextToSpeech API ,我要保存转换text2speech作为SD卡存储器中的文件,但我得到了错误:

 synthesizeToFile failed: not bound to TTS engine

我的代码使用TTS是:

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);
            }
        }
    }

其中内部loadPage()函数的调用的synthesizeToFile如下功能:

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

Answer 1:

你必须等待,直到后onInit调用之前,你可以打电话speak, synthesizeToFile等等......把你的loadPage方法onInit成功有检查后。



文章来源: synthesizeToFile failed: not bound to TTS engine , when using TextToSpeech in android