Copying a file to/from external storage

删除回忆录丶 提交于 2019-12-08 12:47:34
Trees

Aha, I finally got it. And of course it makes perfect sense.

I was trying to copy the file immediately after calling [synthesizeToFile()][1], and so the file was not finished being sythesized/created. Hence the 0 byte file size.

What works is the way that it's explained [here][2]. Basically, just sending in a unique ID to synthesizeToFile() as one of the optional parameters. Then, implementing the TextToSpeech.OnUtteranceCompletedListener Interface in your activity and overriding the onUtteranceCompleted() callback method.

onUtteranceCompleted() is then of course called when the utterance is finished being synthesized. You can check for the unique id you passed in earlier to tell the difference between multiple utterances that you may be waiting for to finish.

Pretty standard stuff, I guess but for some reason it evaded me for a few days.

Hopefully this can help out someone else who might be stuck.

[1]:

http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#synthesizeToFile%28java.lang.String,%20java.util.HashMap%3Cjava.lang.String,%20java.lang.String%3E,%20java.lang.String%29
[2]:

http://developer.android.com/resources/articles/tts.html

have you tried this old school method?

FileInputStream fis = new FileInputStream(tempDestFile);
FileOutputStream fos = new FileOutputStream(permDestFile);
byte[] bites= new byte[1024];
int count = fis.read(bites);
while (  count != -1){
    fos.write(bites, 0, count);
    count = fis.read(bites);            
}

and make sure the WRITE_EXTERNAL_STORAGE permission is in your manifest.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!