我的目标是将文本转换为语音文件并播放。我正在
java.io.IOException:setDataSource失败。
我是android新手。请帮忙。
+639123456789 639123456789 9123456789
更新#1
HashMap<String, String> map = new HashMap<>();
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "speak");
File myDir = getApplicationContext().getFilesDir();
String documents = "documents/data";
File documentsFolder = new File(myDir, documents);
documentsFolder.mkdir();
String path = "/"+documents+"/"+"test.mp3";
textToSpeech.synthesizeToFile("text to speech to audio", map, path);
mMediaPlayer = new MediaPlayer();
try{
mMediaPlayer.setDataSource(path);
mMediaPlayer.prepare();
}
catch (Exception e) {
Log.d("ROYs", e.toString());
e.printStackTrace();
}
mMediaPlayer.start();
关于堆栈溢出的一些问题与我的问题相似。但是答案并不能解决我的问题。
答案 0 :(得分:0)
基本上,发生的是textToSpeech.synthesizeToFile("text to speech to audio", map, path);
不是在创建您认为是的文件,或不是在您认为应该创建的位置创建文件。
请参阅此特殊问题(Android TextToSpeech.synthesizeToFile() file is not created)