亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么 TextToSpeech synthesizeToFile 返回 -1?

為什么 TextToSpeech synthesizeToFile 返回 -1?

慕桂英4014372 2023-02-23 14:29:06
我正在嘗試使用 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);        }    }}對于裝有 Android 6 的設備,該synthesizeToFile方法可以正常工作。對于具有 Android 4.1 的設備,該synthesizeToFile方法返回-1。我已經用 getEngines() 檢查過是否安裝了“com.google.android.tts”。我如何調試我的腳本以發現synthesizeToFile返回的原因-1?有另一種方法可以使用 TTS 生成該文件嗎?我需要在內部存儲(返回的路徑getFilesDir())中執行此操作,因此我不能請求外部存儲許可。編輯:在 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)我已經嘗試過:setWritable(true)和setWritable(true, true)但即使兩者都返回true,異常仍然發生。那么,現在如何解決這個問題?
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻1850條經驗 獲得超11個贊

我發現要知道我需要在 logcat 中查看-1返回值的原因:synthesizeToFile

E/TextToSpeechService:由于異常 java.io.IOException:無法使用 /data/data/com.domain.my/files/_12345_test:打開失?。?strong>EACCES(權限被拒絕)

現在,我必須知道為什么會出現此異常......


查看完整回答
反對 回復 2023-02-23
  • 1 回答
  • 0 關注
  • 295 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號