referring to the answer of Ted Hopp in this post :
The important method is synthesizeToFile. It will write the audio to a file on the device that you specify. You can then play that file with a MediaPlayer or you can pull it off the device onto your development system with the adb command-line tool using the command
EDIT :
try this code , and then check the path sdcard/
if it contains the file : test.wav
HashMap<String, String> myHashRender = new HashMap();
String textToConvert = "this is a demo for saving a WAV file";
String destinationFileName = "/sdcard/test.wav";
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, textToConvert);
mTts.synthesizeToFile(textToConvert, myHashRender, destinationFileName);
EDIT 2 :
and if you are trying to save the wave file to the internal memory ( not the /sdcard/
folder) , then the only way to achieve this is to create a world writable
directory in the internal memory like this:
context.getDir("soundfiles", Context.MODE_WORLD_WRITEABLE);
And then write to this dir.
EDIT 3 :
after taking a look into your code , you've just some problems with creating directories and files : the code should be like this :
speakTextTxt = "Hello world";
HashMap<String, String> myHashRender = new HashMap<String, String>();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, speakTextTxt);
String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
Log.d("MainActivity", "exStoragePath : "+exStoragePath);
File appTmpPath = new File(exStoragePath + "/sounds/");
boolean isDirectoryCreated = appTmpPath.mkdirs();
Log.d("MainActivity", "directory "+appTmpPath+" is created : "+isDirectoryCreated);
String tempFilename = "tmpaudio.wav";
tempDestFile = appTmpPath.getAbsolutePath() + File.separator + tempFilename;
Log.d("MainActivity", "tempDestFile : "+tempDestFile);
new MySpeech(speakTextTxt);
i've tested it on android emulator , and it works fine , but you need to specify the size of the sdCard of your emulator bye using device manager, edit eumlator, and specify the size of your sdcard : example 512 Mb. and then you will find the wav file in the path : mnt/sdcard/sounds/tmpaudio.wav
to test it , just open the DDMS perspective
, File Explorer
, and then export the file to your PC .
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…