0

Hi.
I am making a program and I started at the first example for sphinx 4. I can't even run the program becouse I get an error:new ConfigurationManager(args [0]) so I can't even run the program. Please help. Here is my code:

import java.net.URL;

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

import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;

public class HelloWorld {
    // Default voice is Kevin16
    private static final String VOICENAME = "kevin16";
    private static final String VOICENAME2 = "kevin";
    static String resultText;
    public static String[] som;

    public static void main(String[] args) {
        ISpeak();
        System.out.println("Working");
    }

    public static void ISpeak(){
        ConfigurationManager cm;

        if (som.length > 0) {
            cm = new ConfigurationManager(som [0]);
        } else {
            cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));
        }

        Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
        recognizer.allocate();

        // start the microphone or exit if the programm if this is not possible
        Microphone microphone = (Microphone) cm.lookup("microphone");
        if (!microphone.startRecording()) {
            System.out.println("Cannot start microphone.");
            recognizer.deallocate();
            System.exit(1);
        }

        System.out.println("Say: (Good morning | Hello) ( Bhiksha | Evandro | Paul | Philip | Rita | Will | JARVIS )");

        // loop the recognition until the programm exits.
        while (true) {
            System.out.println("Start speaking. Press Ctrl-C to quit.\n");

            Result result = recognizer.recognize();

            if (result != null) {
                resultText = result.getBestFinalResultNoFiller();
                System.out.println("You said: " + resultText + '\n');
                JSpeak();
            } else {
                System.out.println("I can't hear what you said.\n");
            }
        }
    }

    public static void JSpeak(){
        Voice voice;
        // Taking instance of voice from VoiceManager factory.
        VoiceManager voiceManager = VoiceManager.getInstance();
        voice = voiceManager.getVoice(VOICENAME);
        // Allocating voice
        voice.allocate();
        // word per minute
        voice.setRate(100);
        voice.setPitch(50);

        // Read and speak
        voice.speak("Hello sir. What do you want to do?");
    }
}
2
Contributors
1
Reply
8
Views
3 Years
Discussion Span
Last Post by JamesCherrill
0

You declare the array variable som but you don't initialise it, so som is still null, it doesn't refer to an array yet, the array doesn't exist, it has no members, so you can't use som[0]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.