[英]how to save a output wav file from tts to internal storage, using the below code I am to save it in external storage
我能够将音频 wav 文件创建到内部存储,但我想将文件保存在内部存储中,这是我的代码:
public void speakNow(View v) {
Log.i(tag, "speakNow [" + et.getText().toString() + "]");
HashMap<String, String> myHashRender = new HashMap();
tts.speak(et.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
String destFileName = Environment.getExternalStoragePublicDirectory("/Audio007/") + "wakeUp.wav";
Toast.makeText(this, "" + destFileName, Toast.LENGTH_SHORT).show();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, et.getText().toString());
tts.synthesizeToFile(et.getText().toString(), myHashRender, destFileName);
}
我可以将音频 wav 文件创建到内部存储,但我想将文件保存在内部存储中,请帮忙。
Place your output to
fos.write(OUTPUT_FILE_PLACE_HERE);
保存文件的示例代码
String dir = null;
dir = getExternalFilesDir("/").getPath() + "/" + "Audio007/";
Toast.makeText(this, dir, Toast.LENGTH_LONG).show();
File file = new File(dir, "wakeUp" + ".wav");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//write the bytes in file
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
fos.write(OUTPUT_FILE_PLACE_HERE);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
将文件保存到 SD 卡
String dir = Environment.getExternalStorageDirectory() + "/Audio007/";
File file = new File(dir, "wakeUp"+".wav");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//write the bytes in file
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
fos.write(OUTPUT_FILE_PLACE_HERE);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.