2

I have used Freetts.jar file in my java application that announces the token number. My application is working perfectly in my laptop but is not working in my desktop that has an external speaker. I get a null pointer exception. NOTE: I use Windows 7 in both my computers.

The Below Code is the Sample Format I used.

package tsapp;

import java.util.Locale;
import javax.speech.Central;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.swing.JOptionPane;
public class TextSpeech {
 public static void main(String[] args){
 try
 {
   System.setProperty("freetts.voices",
    "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");

   Central.registerEngineCentral
    ("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
   Synthesizer  synthesizer =
    Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));
   synthesizer.allocate();
   synthesizer.resume();
   String str;

        str=JOptionPane.showInputDialog(null,"Voice Check");
        if(str==null)
        return;
        synthesizer.speakPlainText(str, null);
   synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
   synthesizer.deallocate();
  }
   catch(Exception e)
   {
       System.out.println(e.getClass());
     e.printStackTrace();
   }
 }
}
Kumar
  • 110
  • 14

1 Answers1

1

Can we do one simple thing:

  1. Download binary https://netix.dl.sourceforge.net/project/freetts/FreeTTS/FreeTTS%201.2.2/freetts-1.2.2-bin.zip
  2. Add to your project enter image description here
  3. Write simple code.

Like this

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class TestVoice {


    public static void main(String[] args) {

        String text = "Voice check!";

        Voice voice;
        VoiceManager voiceManager = VoiceManager.getInstance();
        voice = voiceManager.getVoice("kevin");
        voice.allocate();
        voice.speak(text);

    }

}

Just be sure that all these libs are on your desktop too.

Saulius Next
  • 1,340
  • 10
  • 16
  • Thank You Mr. Saulius. But could you please explain the mistake I did. – Kumar Dec 20 '16 at 02:56
  • I suspect that you haven't copied all libs to your desktop. Also next times please provide exception then I could say more about issue, and try to write simple code because this way you can get bets results. I'm not the expert with FreeTTS therefore I can't comment anything else. – Saulius Next Dec 20 '16 at 07:35
  • Thank You though for your help Mr. Saulius – Kumar Dec 20 '16 at 07:48