0

I am trying to make a text to speech program, but I always get this:

Exception in thread "main" java.lang.NullPointerException
at FreeTTS.main(FreeTTS.java:7)

Here is my code:

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class FreeTTS {
    public static void main(String args[]) {
        VoiceManager vm = VoiceManager.getInstance();
        Voice voice = vm.getVoice("kevin16");
        voice.allocate();
        voice.speak("Hello World!");
        voice.deallocate();
    }
}

how can I fix it?

Napkin
  • 1
  • 3

1 Answers1

1
vm.getVoice("kevin16")

is returning null. From the Javadoc:

Returns: the Voice that has the same name as voiceName if one exists, else null

Ergo, voice "kevin16" was not found.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190