0
我試圖將字符串轉換爲.wav文件,以便在texttospeech中使用暫停/恢復功能,但是我無法創建文件。synthesizeToFile返回-1,我無法使用Environment.getExternalStorageDirectory()創建文件getAbsolutePath()
public void fileCreate() {
String inputText = editText.getText().toString();
HashMap<String, String> myHashRender = new HashMap<String, String>();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, inputText);
Log.d("TAG", "successfully created hashmap");
int sr = textToSpeech.synthesizeToFile(inputText, myHashRender, Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"tts_file.wav");
Log.d("TAG", "synthesize returns = " + sr);
File fileTTS = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath(),"tts_file.wav");
if (fileTTS.exists()) {
Log.d("TAG", "successfully created fileTTS");
}
else {
Log.d("TAG", "failed while creating fileTTS");
}
fileUri = Uri.fromFile(fileTTS);
Log.d("TAG", "successfully created uri link: " + fileUri.getPath());
}
是的我已經在應用程序標記上方的清單文件中給予權限,但是在logcat監視器中它顯示java.io.FileNotFoundException:打開失敗:EACCES(Permission denied)@cristianorbs – kunal007