我正在
java.io.FileNotFoundException: Is a directory
尝试将tts合成到文件时出现错误(来自语音识别和文本输入)当使用4.1.2操作系统在Android设备上进行测试时,它会将音频文件放在根目录而不是文件夹I&#39 ; m告诉它使文件进入,然后崩溃与该错误,它在根目录中创建的文件的名称是:
K9 Remotespoken.wav //when it should be saved as: K9 Remote/spoken.wav
但是,当我用我的其他设备测试android 7.0 os时,它不会崩溃或给出错误,但它根本不会制作音频文件,我做错了什么?
有人可以解释为什么以及如何在函数synthesizeToFile(" theText",bundle,file,string)中为lolipop和up synthesizeToFile函数获取第4个参数?我知道前3个是什么以及它们做了什么,但android开发者文档只说第4个参数中的字符串是唯一标识符?请解释一下,谢谢
private String state;
private File Root;
public File myFilename; //used in lolipop +
public String msg; //used in pre lolipop
//ON CREATE EVENT
if (Environment.MEDIA_MOUNTED.equals(state)) {
Root = Environment.getExternalStorageDirectory();
myFilename = new File(Root.getAbsolutePath() + "/K9 Remote");
if (!myFilename.exists()) {
myFilename.mkdirs();
msg = myFilename.toString();
}
}
//REST OF RELEVANT CODE
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 400) {
if (resultCode == RESULT_OK) {
ArrayList<String> res = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String holdForGMS = String.valueOf(res.get(0));
HDC = appPreferences.getInt("h_d_c", 0);
float nPitch = appPreferences.getFloat("my_pitch", (float) 1.0);
float nSpeed = appPreferences.getFloat("my_speed", (float) 1.0);
tts.setSpeechRate(nSpeed);
tts.setPitch(nPitch);
if (HDC == 0) {
if (transmitter == 1 && remote == 0) {
speakIT(holdForGMS);
}
if (transmitter == 1 && remote == 1) {
sendIT(holdForGMS);
}
}
if (HDC > 0)
synthToFile(holdForGMS);
}
}
}
public void synthToFile(String ultraSynth) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//THIS IS PRODUCING THE ERROR
this.tts.synthesizeToFile(ultraSynth, null, myFilename,"/spoken.wav");
PitchPlayer();
}else
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {//I DO NOT HAVE A DEVICE WITH THIS OS TO EVEN TEST IF THIS CODE IS WORKING
this.tts.synthesizeToFile(ultraSynth, null, msg+"/spoken.wav");
PitchPlayer();
}
} catch
(NullPointerException e) {
Log.i("K9 Remote", "Failed, can't synthesize to file");
}
}