Skip to content →

Tag: Voice

Transferring Voice Data

This is done using JMF (Java Media Framework). Voice data is read from a file using `MediaLocator’. It is used as the data source for a `Processor’. The `Processor’ specifies and converts the audio data to a certain format and then output the converted data into a `DataSink’. The `DataSink’ then transfers the stream to its destination address and port.

Leave a Comment

Generating Voice File

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();
    }
}
Leave a Comment