When the web server receives a POST' message from the web page, it will first check whether the message is valid. If so, freeTTS‘ is used to generate a voice file and the file is saved in the `wav’ directory with pre-configured file name.
The voice generator looks as follows:
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
/**
*
* @author Daoyuan
*/
public class VoiceGenerator {
String message;
public VoiceGenerator(String message){
this.message = message;
}
public void generateVoiceFile(String filename){
Voice voice;
VoiceManager vm = VoiceManager.getInstance();
voice = vm.getVoice("kevin16");
voice.allocate();
String baseName = filename.substring(0, filename.toLowerCase().indexOf(".wav"));
SingleFileAudioPlayer sfap = new SingleFileAudioPlayer("wav/" + baseName, javax.sound.sampled.AudioFileFormat.Type.WAVE);
voice.setAudioPlayer(sfap);
voice.speak(message);
sfap.close();
voice.deallocate();
}
}
Comments