Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

text to speech - synthesizeToFile failed: not bound to TTS engine , when using TextToSpeech in android

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...