将文本音频保存为语音音频作为wav / mps文件到手机的内部闪存

时间:2016-02-23 11:17:15

标签: java android button text-to-speech

我已经阅读了此处的帖子,将文本音频文件保存为外部存储器即sd卡的wav文件。但是我想将TTS音频作为wav / mp3文件保存到手机的内部闪存而不是SD卡。此代码将其保存到外部存储,但如何使用context.getDir(" soundfiles",Context.MODE_WORLD_WRITEABLE)对其进行修改;因为我也只读了保存到内部的方法。

 public void saveAudio(View v) {
    if (v.getId() == R.id.save) {
        String speakTextTxt                  = "Good morning,have a nice day";
        HashMap<String, String> myHashRender = new HashMap<String, String>();
        myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, speakTextTxt);

        String exStoragePath                = Environment.getExternalStorageDirectory().getAbsolutePath();
        File appTmpPath                     = new File(exStoragePath);
        appTmpPath.mkdirs();
        String tempFilename                 = "testing.wav";
        String tempDestFile                 = appTmpPath.getAbsolutePath() + "/" + tempFilename;

        tts.synthesizeToFile(speakTextTxt, myHashRender, tempDestFile);

    }
    Toast.makeText(getApplicationContext(), "audio saved", Toast.LENGTH_SHORT).show();
}

0 个答案:

没有答案