I am trying to get a TTS working in netbeans for java. I have unzipped the JSAPI files and added the following jars to the library
- cmu_us_kal.jar
- cmulex.jar
- en_us.jar
- freetts.jar
- cmulex.jar
- jsapi.jar
When I run the follow code:
package demofreetts2;
import javax.speech.*;
import java.util.*;
import javax.speech.synthesis.*;
public class Demofreetts2 {
String speaktext ="";
public void doSpeak(String speak, String voicename)
{
speaktext = speak;
String voiceName = voicename;
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.US, null, null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc)synthesizer.getEngineModeDesc();
Voice[] voices = desc.getVoices();
Voice voice = null;
for(int i = 0; i< voices. length; i++)
{
if(voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
synthesizer.speakPlainText(speaktext, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch (Exception e)
{
String message = "missing speech properties in " + System.getProperty("user.home") + "\n";
System.out.println (""+e);
}
}
public static void main (String[]args)
{
Demofreetts2 obj = new Demofreetts2();
obj.doSpeak(args[0],"kevin16");
}
}
I get the following message:
**run:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at demofreetts2.Demofreetts2.main(Demofreetts2.java:46)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)**
When I change main method like so:
public static void main (String[]args)
{
Demofreetts2 obj = new Demofreetts2();
obj.doSpeak("hello","kevin16");
}
I get this message:
**run:
java.lang.NullPointerException
BUILD SUCCESSFUL (total time: 1 second)**
Does anyone know how I can get this to work?
I just what a program that will convert a string to speech.