synthesizeToFile失败:在android中使用TextToSpeech时未绑定到TTS引擎

时间:2013-05-11 13:21:09

标签: android text-to-speech speechsynthesizer

我正在使用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);

1 个答案:

答案 0 :(得分:1)

您必须等到调用onInit之后才能致电speak, synthesizeToFile等等......在检查成功后,将loadPage方法放入onInit。< / p>