[英]why TextToSpeech synthesizeToFile returns -1?
I'm trying to create a file with synthesizeToFile: 我正在尝试使用synthesizeToFile创建一个文件:
TextToSpeech tts = new TextToSpeech(getApplicationContext(), this, "com.google.android.tts");
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
String textToGenerate = "this is a test";
// /data/data/com.domain.my/files is returned by getFilesDir()
String completePathFile = "/data/data/com.domain.my/files/_12345_test";
File fileToGenerate = new File(completePathFile);
String fileName = fileToGenerate.getName();
// this works on Android 6
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
Bundle bundleTts = new Bundle();
bundleTts.putString(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, fileName);
tts.synthesizeToFile
(
textToGenerate
, bundleTts
, fileToGenerate
, fileName
);
}
// this doesn't works on Android 4.1: response is -1
else
{
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, fileName);
int response = tts.synthesizeToFile
(
textToGenerate
, hashMap
, completePathFile
);
Log.d("testTTS", "Generation file " + fileName + " - response = " + response);
}
}
}
With the device having Android 6 the synthesizeToFile
method works fine. 对于具有Android 6的设备, synthesizeToFile
方法可以正常工作。
With the device having Android 4.1 the synthesizeToFile
method returns -1
. 对于具有Android 4.1的设备, synthesizeToFile
方法返回-1
。
I already checked with getEngines() that "com.google.android.tts" is installed. 我已经使用getEngines()检查是否已安装“ com.google.android.tts”。
How can I debug my script to discover why synthesizeToFile
returns -1
? 如何调试脚本以发现synthesizeToFile
为什么返回-1
?
There is an alternative way to generate that file with TTS? 有另一种方法可以用TTS生成该文件吗?
I need to do that in the internal storage (the Path returned by getFilesDir()
) so I must not ask for external storage permission. 我需要在内部存储(由getFilesDir()
返回的路径)中执行此操作,因此我绝对不能要求外部存储权限。
EDIT: 编辑:
In the logcat I found this error: 在logcat中,我发现此错误:
E/TextToSpeechService: Can't use /data/data/com.domain.my/files/_12345_test due to exception java.io.IOException: open failed: EACCES (Permission denied)
I already tried: 我已经尝试过:
setWritable(true)
and 和
setWritable(true, true)
But even if both return true
, the Exception still occurs. 但是,即使两者都返回true
,仍然会发生异常。
So, now how to solve this? 那么,现在如何解决呢?
I found that to know the reason of the value -1
returned by synthesizeToFile
I need to see in the logcat: 我发现要知道synthesizeToFile
返回值-1
的原因,我需要在logcat中查看:
E/TextToSpeechService: Can't use /data/data/com.domain.my/files/_12345_test due to exception java.io.IOException: open failed: EACCES (Permission denied) E / TextToSpeechService:由于出现异常java.io.IOException而无法使用/data/data/com.domain.my/files/_12345_test:打开失败: EACCES(权限被拒绝)
Now, I must know why this exception occurs... 现在,我必须知道为什么会发生此异常...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.