0
使用文字轉語音我使用Android TextToSpeech API
在未結合TTS引擎,我想保存轉換text2speech如在SD卡中的文件,但我得到了錯誤:synthesizeToFile失敗:在Android中
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);