I am trying to save the output of TextToSpeech into mp3 file or wav file, I have tested different codes but it never work
The first code i tried:
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath() + "/me");
dir.mkdirs();
File file = new File(dir, "myData.wav");
Log.d("Debug ","Path : "+file.getAbsolutePath());
HashMap<String, String> params = new HashMap<>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, textToRead);
if(textToSpeech.synthesizeToFile(textToRead,params,file.getAbsolutePath()) == textToSpeech.ERROR){
Log.d("Debug ","file write fail ");
}else {
Log.d("Debug ","file write done ");
}
but always the result is "file write fail"
i tried to enter hard coded path to sdcard and it didn't work
textToSpeech.synthesizeToFile(textToRead,params,"/sdcard/Android/data/com.orbshine.orbshine/data.wav")
According to the official documentation , by default, apps targeting Android 10 and higher are given scoped access into external storage, or scoped storage.
You can either:
<manifest ... >
<!-- This attribute is "false" by default on apps targeting
Android 10 or higher. -->
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
</manifest>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.