android中的TextToSpeech synthezetofile()方法是否创建一个空白文件?

android中的TextToSpeech synthezetofile()方法是否创建一个空白文件?,android,android-studio,Android,Android Studio,我想使用synthesizeToFile()函数将android tts生成的输出保存到external storage(即SD卡),但不幸的是,它没有给出任何错误 这是我尝试的代码: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (B

我想使用
synthesizeToFile()
函数将
android tts
生成的输出保存到
external storage
(即SD卡),但不幸的是,它没有给出任何错误

这是我尝试的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("My Notification", "Anything", NotificationManager.IMPORTANCE_HIGH);
        NotificationManager manager = getSystemService(NotificationManager.class);
        manager.createNotificationChannel(channel);
    }
    t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if(status != TextToSpeech.ERROR) {t1.setLanguage(Locale.getDefault());}
        }
    });
    String toSpeak = "Some text to speak";
    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
    String envPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download";
    String destFileName = envPath + "/" + "my_tts_file.wav";
    File fileTTS = new File(destFileName);
    HashMap<String, String> myHashRender = new HashMap<>();
    myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, toSpeak);
    t1.synthesizeToFile(toSpeak, myHashRender, fileTTS.getAbsolutePath());
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.O){
NotificationChannel=新的NotificationChannel(“我的通知”、“任何事”、NotificationManager.HIGH);
NotificationManager=getSystemService(NotificationManager.class);
manager.createNotificationChannel(频道);
}
t1=new TextToSpeech(getApplicationContext(),new TextToSpeech.OnInitListener()){
@凌驾
公共无效onInit(int状态){
if(status!=TextToSpeech.ERROR){t1.setLanguage(Locale.getDefault());}
}
});
String toSpeak=“要说的文字”;
t1.讲话(toSpeak,TextToSpeech.QUEUE_FLUSH,null);
字符串envPath=Environment.getExternalStorageDirectory().getAbsolutePath()+“/Download”;
字符串destFileName=envPath+“/”+“my_tts_file.wav”;
File fileTTS=新文件(destFileName);
HashMap myHashRender=新建HashMap();
myHashRender.put(TextToSpeech.Engine.KEY\u PARAM\u outrance\u ID,toSpeak);
t1.synthezetofile(toSpeak、myHashRender、fileTTS.getAbsolutePath());
}
但现在它在下载目录中创建了一个空白的
my_tts_file.wav
文件(0字节)

错误到底在哪里