title: How to get TTS (Text To Speech) working in java netbeans?
body: <p>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</p>
  
  <ul>
  <li>cmu_us_kal.jar</li>
  <li>cmulex.jar </li>
  <li>en_us.jar</li>
  <li>freetts.jar</li>
  <li>cmulex.jar </li>
  <li>jsapi.jar</li>
  </ul>
  
  <p>When I run the follow code:</p>
  
  <pre><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&lt; 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");
   }
  }
  </code></pre>
  
  <p>I get the following message:</p>
  
  <pre><code>**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)**
  </code></pre>
  
  <p>When I change main method like so:</p>
  
  <pre><code>public static void main (String[]args)
  {
   Demofreetts2 obj = new Demofreetts2();
   obj.doSpeak("hello","kevin16");
  }
  </code></pre>
  
  <p>I get this message:</p>
  
  <pre><code>**run:
  java.lang.NullPointerException
  BUILD SUCCESSFUL (total time: 1 second)**
  </code></pre>
  
  <p>Does anyone know how I can get this to work?</p>
  
  <p>I just what a program that will convert a string to speech. </p>