Java Speech API (freetts)
Java
The following instructions were provided by me on a forum some years back on how to run helloworld for Java Speech API (on Windows platform). I am copying it here again (for my own reference, as well as any other aspirants out there)
Download the freetts library. Extract and follow following instructions to run a HelloWorld program successfully:
1. Unzipped: freetts-1.2.1-bin.zip to a folder, say [freetts]
2. Execute [freetts]/lib/jsapi.exe to obtain jsapi.jar
3. Created a sample 'demo' folder.
4. Copied contents (sound files and HelloWorld.java) of [freetts]\demo\JSAPI\HelloWorld to my 'demo' folder.
5. Copied following files from [freetts]\lib to my 'demo' folder:
freetts.jar
jsapi.jar
cmu_us_kal.jar
cmulex.jar
en_us.jar
6. Copied [freetts]/speech.properties file to my home folder i.e. C:\Documents and Settings\[my_user_name] OR /home/[my_user_name]
7. Compiled HelloWorld program as:
javac -classpath .;./jsapi.jar HelloWorld.java
8 Run it as follows:
java -classpath .;./jsapi.jar;./freetts.jar;./cmu_us_kal.jar HelloWorld
9. Following output came:
All general Mode JSAPI Synthesizers and Voices:
FreeTTS en_US general synthesizer (mode=general, locale=en_US):
kevin
kevin16
Using voice: kevin16
and I hear the voice as well.
and my own test code:
Download the freetts library. Extract and follow following instructions to run a HelloWorld program successfully:
1. Unzipped: freetts-1.2.1-bin.zip to a folder, say [freetts]
2. Execute [freetts]/lib/jsapi.exe to obtain jsapi.jar
3. Created a sample 'demo' folder.
4. Copied contents (sound files and HelloWorld.java) of [freetts]\demo\JSAPI\HelloWorld to my 'demo' folder.
5. Copied following files from [freetts]\lib to my 'demo' folder:
freetts.jar
jsapi.jar
cmu_us_kal.jar
cmulex.jar
en_us.jar
6. Copied [freetts]/speech.properties file to my home folder i.e. C:\Documents and Settings\[my_user_name] OR /home/[my_user_name]
7. Compiled HelloWorld program as:
javac -classpath .;./jsapi.jar HelloWorld.java
8 Run it as follows:
java -classpath .;./jsapi.jar;./freetts.jar;./cmu_us_kal.jar HelloWorld
9. Following output came:
All general Mode JSAPI Synthesizers and Voices:
FreeTTS en_US general synthesizer (mode=general, locale=en_US):
kevin
kevin16
Using voice: kevin16
and I hear the voice as well.
and my own test code:
import javax.speech.*;
import javax.speech.synthesis.*;
import java.util.Locale;
public class HelloWorld2 {
public static void main(String args[]) {
try {
// Create a synthesizer for English
Synthesizer synth = Central.createSynthesizer(
new SynthesizerModeDesc(Locale.ENGLISH));
// Get it ready to speak
synth.allocate();
synth.resume();
// Speak the "Hello world" string
synth.speakPlainText("I love Java programming.", null);
// Wait till speaking is done
synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
// Clean up
synth.deallocate();
} catch (Exception e) {
e.printStackTrace();
}
}
}