How can I save the andts troid output in a wav file?

I searched almost everywhere, trying to find a way to save Android output in an audio file. I looked at these posts:

  • How to save TTS output to an audio file on Android?
  • How to allow TTS to write files to the directories of my application?

but could not find / understand the answers. I use synthesizeToFile() as follows:

 HashMap<String, String> myHashRender = new HashMap<String, String>(); myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, result); String fileName = "/Android/data/com.android.voicelanglearning.vll/ttsfile1.wav"; tts.synthesizeToFile(result, myHashRender, fileName); 

So, I repeat the same question. Any help is greatly appreciated.

Thanks, Maunik

+8
android text-to-speech
source share
3 answers

An important method is synthesizeToFile . It will record audio to a file on the specified device. You can then play this file using MediaPlayer or you can pull it out of your development system using the adb command-line tool with the command

 adb pull <path-to-file> 
+4
source share

It may not work on real devices. The problem may be that you are testing a real device with a USB cable connected to the computer in debug mode. This may result in disabling file saving on the phone.

Environment.getExternalStorageDirectory ()

Return the main directory of the external storage. This directory is currently unavailable if it was installed by the user on his computer, was deleted from the device, or some other problem occurred. You can determine its current state using getExternalStorageState ().

0
source share

TextToSpeech.synthesizeToFile () does not work on real devices. It works only in AVD.

I also experimented with this, using both the original Pico TTS engine and the third-party TTS engine, trying to write to either an SD card or internal memory (on the root device):

 context.getDir("soundfiles", Context.MODE_WORLD_WRITEABLE); 

But, as you noted, the method returns TextToSpeech.SUCCESS without actually creating the file.

If you need to write your TTS output to a WAV file, connect the headset output to the aux input on the sound card on your PC and use any recording software to fix it.

-2
source share

All Articles