How can I save the TTS output in an audio file on Android?

This is my first post here. I am new to Android programming. I want to create an application where I can save text to speech in an audio file in my database. I heard about the synthesis of ToFile (), but not it.

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

Use this code and get the mp3 file from the assets folder and try this code.

mMediaPlayer = new MediaPlayer(); mMediaPlayer = MediaPlayer.create(this,R.raw.button); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.start(); mMediaPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mMediaPlayer.stop(); } }); 
+1
source share

synhesizeToFile () should create a wav (which you can decode and send to your db or save as a file or something else that you do with it) and you can play it using Nitesh code.

From http://android-developers.blogspot.fi/2009/09/introduction-to-text-to-speech-in.html :

 HashMap<String, String> myHashRender = new HashMap(); String wakeUpText = "Are you up yet?"; String destFileName = "/sdcard/myAppCache/wakeUp.wav"; myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, wakeUpText); mTts.synthesizeToFile(wakeUpText, myHashRender, destFileName); 

As soon as you receive a notification of the completion of the synthesis, you can play the output file, like any other audio resource, with android.media.MediaPlayer.

+8
source share

You must be saved in a folder with tts file files.

0
source share

All Articles