Home > Net >  how to save a output wav file from tts to internal storage, using the below code I am to save it in
how to save a output wav file from tts to internal storage, using the below code I am to save it in

Time:01-28

I am able to create audio wav file to internal storage but I want to save file it in internal storage this is my code:

 public void speakNow(View v) {
        Log.i(tag, "speakNow ["   et.getText().toString()   "]");
        HashMap<String, String> myHashRender = new HashMap();
        tts.speak(et.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
        String destFileName = Environment.getExternalStoragePublicDirectory("/Audio007/")   "wakeUp.wav";
        Toast.makeText(this, ""   destFileName, Toast.LENGTH_SHORT).show();
        myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, et.getText().toString());
        tts.synthesizeToFile(et.getText().toString(), myHashRender, destFileName);
    }

I am able to create audio wav file to internal storage but I want to save file it in internal storage, please help on it.

CodePudding user response:

Place your output to

 fos.write(OUTPUT_FILE_PLACE_HERE);

sample code for save file

  String dir = null;
    dir = getExternalFilesDir("/").getPath()   "/"   "Audio007/";

    Toast.makeText(this, dir, Toast.LENGTH_LONG).show();

    File file = new File(dir, "wakeUp"   ".wav");

    try {
        file.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //write the bytes in file
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(file);
        fos.write(OUTPUT_FILE_PLACE_HERE);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

CodePudding user response:

Save file to sdcard

  String dir = Environment.getExternalStorageDirectory()   "/Audio007/";
  File file = new File(dir, "wakeUp" ".wav");

  try {
    file.createNewFile();
} catch (IOException e) {
    e.printStackTrace();
}
//write the bytes in file
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(file);
    fos.write(OUTPUT_FILE_PLACE_HERE);
    fos.flush();
    fos.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

}

  • Related