Menu

Freetts Null Pointer exception on Linux

2013-11-20
2013-11-21
  • Devashi Tandon

    Devashi Tandon - 2013-11-20

    I am trying to implement a module which uses freetts to create a wave file with the text specified. The code runs fine on windows machine from eclipse, but when I try to execute the JAR on a linux device, it is always giving a NullPointerException. I tried on a couple of linux boxes, and I see consistent results.

    This is the error I am getting:

    voiceManager:
    helloVoice: null
    java.lang.NullPointerException
    at test.VoiceGen.textToVoice(VoiceGen.java:31)
    at test.MainClass.main(MainClass.java:9)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

    The code is as follows:

    import java.io.File;

    import javax.sound.sampled.AudioFileFormat.Type;

    import com.sun.speech.freetts.Voice;
    import com.sun.speech.freetts.VoiceManager;
    import com.sun.speech.freetts.audio.AudioPlayer;
    import com.sun.speech.freetts.audio.SingleFileAudioPlayer;

    public class VoiceGen {

    public String textToVoice(String path, String fileout){
        try 
        {
            AudioPlayer audioPlayer = null;
            String voiceName = "kevin16";
    
            System.setProperty("FreeTTSSynthEngineCentral", "com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
                //System.setProperty("freetts.voices", "com.sun.speech.freetts.VoiceDirectory");
                //Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
    
            VoiceManager voiceManager = VoiceManager.getInstance();
    
            System.out.println("voiceManager: " + voiceManager);
    
            Voice helloVoice = voiceManager.getVoice(voiceName);
    
            System.out.println("helloVoice: " + helloVoice);
    
            // Allocates the resources for the voice
            helloVoice.allocate();
    
            // Synthesize speech
            //create a audioplayer to dump the output file
            audioPlayer = new SingleFileAudioPlayer(path+File.separator + fileout, Type.WAVE);
            //attach the audioplayer 
            helloVoice.setAudioPlayer(audioPlayer);
            helloVoice.speak("Test Speech..Please listen");
    
            // Clean up
            helloVoice.deallocate();
            audioPlayer.close();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return fileout;
    }
    

    }

    Any ideas on what could be the issue and how to resolve it?

     

    Last edit: Devashi Tandon 2013-11-20
    • Devashi Tandon

      Devashi Tandon - 2013-11-21

      Found out the issue. Basically cmu_us_kal.jar contains the voices which was not included in my libraries on the linux boxes. After adding this file and all the others in the lib directory of freetts, the code works as expected. When including the libraries don't just include the freetts.jar but all the others as well.

       
  • Dirk Schnelle-Walka

    Great, that it is working.

    Dirk

     

Log in to post a comment.