我需要使用synthesizeToFile创建音频文件。
它在Android 6上运行(synthesizeToFile的重载版本,但在Android 4.1中,synthesizeToFile
返回-1
。
synthesizeToFile
official documentation说:
使用指定的参数将给定的文本合成到文件中。此方法是异步的,即方法仅将请求添加到TTS请求的队列中,然后返回。
然后,知道是哪个错误导致synthesizeToFile
我在创建此异常的日志猫中搜索:
E / TextToSpeechService:由于异常java.io.IOException而无法使用/data/data/com.domain.my/files/_12345_test.wav:打开失败:EACCES(权限被拒绝)
[Android 6和4.1之间存在一些不同的系统配置/设置,导致此错误?
我必须传递给-1
的路径与synthesizeToFile
返回的路径不同?
我必须设置文件权限吗?
我用于Android 4.1的代码:
getFilesDir()
我已经通过getEngines()检查是否已安装“ com.google.android.tts”。
我需要将文件保存在内部存储中,所以我一定不要求外部存储许可(对于Android 4.1来说也是如此?或者对于此版本,我需要这样做?)>
如果我故意将不存在的路径传递给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.wav";
File fileToGenerate = new File(completePathFile);
String fileName = fileToGenerate.getName();
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);
}
}
,则logcat中的错误将更改为synthesizeToFile
,因此该方法可以正确检查路径file not found exception
存在。
我需要使用synthesizeToFile创建一个音频文件。它适用于Android 6(带有synthesizeToFile的重载版本),但在Android 4.1中,synthesizeToFile返回-1。 synthesizeToFile ...
我碰到您的问题,正在寻找解决方案。completePathFile