1

I'm new to this topic and I was trying to build a sample project using Sphinx4 libraries following this tutorial step by step: Tutorial link

then I kept having the same error from the (run.xml)

the code I used:

public static void main(String[] args) {
        // TODO code application logic here
        //configuration obj
        Configuration configuration = new Configuration();

        //path to acoustic model
        configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/es-us");
        //path to dictionary model
        configuration.setDictionaryPath("/dictionary.dic");
        //path to the language model
        configuration.setLanguageModelPath("/languagemodel.lm");

        //recognizer object, pass configuration object

        try{

            LiveSpeechRecognizer recognize = new LiveSpeechRecognizer(configuration);
            recognize.startRecognition(true);

            //create SpeechResult Obj
            SpeechResult result;

            //checking if recognizer jas recognized the speech

            while((result = recognize.getResult())!=null){

                //get the recognized speech
                String command = result.getHypothesis();
                //Match recognized speech with our commands
                switch(command){

                    case "open file manager":
                        System.out.println("File manager Opened");
                    break;

                     case "close file manager":
                        System.out.println("File manager Closed");
                    break;

                     case "open browser":
                        System.out.println("Browser Opened");
                    break;

                         case "close browser":
                        System.out.println("Browser Closed");
                    break;


                }

            }
        }catch(IOException e){}



    }

the error I keep getting:

 run:
    Exception in thread "main" java.lang.NoSuchMethodError: edu.cmu.sphinx.util.props.ConfigurationManager.getComponentNames()Ljava/util/Set;
        at edu.cmu.sphinx.util.props.ConfigurationManagerUtils.listAllsPropNames(ConfigurationManagerUtils.java:553)
        at edu.cmu.sphinx.util.props.ConfigurationManagerUtils.setProperty(ConfigurationManagerUtils.java:610)
        at edu.cmu.sphinx.api.Context.setLocalProperty(Context.java:191)
        at edu.cmu.sphinx.api.Context.setAcousticModel(Context.java:88)
        at edu.cmu.sphinx.api.Context.<init>(Context.java:61)
        at edu.cmu.sphinx.api.Context.<init>(Context.java:45)
        at edu.cmu.sphinx.api.AbstractSpeechRecognizer.<init>(AbstractSpeechRecognizer.java:44)
        at edu.cmu.sphinx.api.LiveSpeechRecognizer.<init>(LiveSpeechRecognizer.java:34)
        at speechrecognizer.SpeechRecognizer.main(SpeechRecognizer.java:40)
    C:\Users\Sadeem\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:54: Java returned: 1
    BUILD FAILED (total time: 0 seconds)

I downloaded the jar files from this website oss.sonatype.org

and I added the file.dic, file.lm to the /src folder and to a separate folder to figure if this was the cause but no new results.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • You have conflicting or outdated jars in your classpath. You need to provide more information on which particular jars you are using to get further help. – Nikolay Shmyrev Oct 27 '16 at 15:50
  • these are the jars I used: - sphinx4-data-1.0.0.jar & - sphinx4-core-1.0.0.jar @NikolayShmyrev – Sadeem Khalaf Oct 27 '16 at 16:14

2 Answers2

1

You might just want to switch to a gradle or maven based project. You can get rid of a lot of problems regarding libraries.

I've got a Sphinx4 project currently using the following Gradle.build:

apply plugin: 'java'

repositories {
jcenter()
mavenLocal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven {url "https://mvnrepository.com/artifact/commons-io/commons-io"}
}

dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile group: 'edu.cmu.sphinx', name: 'sphinx4-core', version:'5prealpha-SNAPSHOT'
compile group: 'edu.cmu.sphinx', name: 'sphinx4-data', version:'5prealpha-SNAPSHOT'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
testCompile 'junit:junit:4.12'
}

If you've never used Gradle: https://docs.gradle.org/3.0/userguide/tutorial_java_projects.html

Also it is available in most IDE, like Eclipse, Netbeans or IntelliJ

Hespen
  • 1,384
  • 2
  • 17
  • 27
  • I already solved the problem, I missed adding the configuration that was attached with the demo project, so it wasn't able to see the libraries from sphinx. I'll try your solution in the future (y) – Sadeem Khalaf Nov 07 '16 at 22:42
0

You used wrong jars. Proper jars are sphinx4-core-5prealpha-20160628.232526-10.jar and sphinx4-data-5prealpha-20160628.232535-10.jar

You also need to ensure no other sphinx4 jar is in your classpath.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • thank you so much for the help, but I still get the same error and it's pointed in the run.xml file - – Sadeem Khalaf Oct 27 '16 at 16:23
  • You seem to have old sphinx4.jar in your classpath, you need to remove it. You need to provide a complete information about classpath in order to get further help. – Nikolay Shmyrev Oct 27 '16 at 16:37