AudioFileFormat.Type type = PlayerModel.getAudioType(audioFile);
com.sun.speech.freetts.Voice freettsVoice =
((com.sun.speech.freetts.jsapi.FreeTTSVoice) jsapiVoice).getVoice();
SingleFileAudioPlayer player = new SingleFileAudioPlayer(PlayerModel.getBasename(audioFile), type);
freettsVoice.setAudioPlayer(player);
freettsVoice.startBatch();
if (!freettsVoice.speak(text)) {
JOptionPane.showMessageDialog(null, "Sorry, the application unable to convert your text into sound file!", "Failed to convert to Sound", JOptionPane.ERROR_MESSAGE);
}
freettsVoice.endBatch();
player.close();
freettsVoice.setAudioPlayer(new com.sun.speech.freetts.audio.JavaStreamingAudioPlayer() );
}
String finishMsg = "Your sound file have saved to "+audioFile;
JOptionPane.showMessageDialog(null,finishMsg, "Done Export sound file", JOptionPane.ERROR_MESSAGE);