Reputation: 793
I am using spinx4-5prealpha in my application. When I run my application in eclipse, it all works just fine. I used Maven to load the dependencies. When I export the project as a runnable jar file, and run that, i get the following:
Exception in thread "recognizerEngine" java.lang.NullPointerException
at edu.cmu.sphinx.util.props.SaxLoader.load(SaxLoader.java:71)
at edu.cmu.sphinx.util.props.ConfigurationManager.<init>(ConfigurationManager.java:58)
at edu.cmu.sphinx.api.Context.<init>(Context.java:59)
at edu.cmu.sphinx.api.Context.<init>(Context.java:44)
at edu.cmu.sphinx.api.AbstractSpeechRecognizer.<init>(AbstractSpeechRecognizer.java:42)
at system.core.RecognizerEngineComponents.LiveSpeechRecognizerExtention.<init>(LiveSpeechRecognizerExtention.java:36)
at system.core.RecognizerEngine.run(RecognizerEngine.java:64)
at java.lang.Thread.run(Unknown Source)
All I do is instantiate a new `LiveSpeechRecognizer`
What should i do?
Here's what i dug up so far. So I looked into the code to see where the problem might be. What i've figured out so far is that, the path for the file default.config.xml
is what is causing the problem. The path returned by the Matcher
used in the ConfigurationManagerUtil
is /edu/cmu/sphinx/models/en-us/default.config.xml
. Which works fine when it runs in eclipse (though, i dont understand why it does). When i checked the jar file exported, the file it look for is in resources/edu/cmu/sphinx/models/en-us/default.config.xml
.
My guess is, the problem is somewhere around here...
Edit
The problem i believe is with the relative paths produced. The sphinx api, at a point uses the getResource(String resource)
method, and as i mentioned above, it returns /edu/cmu/sphinx/models/en-us/default.config.xml
. But in the jar file i export, these files are actually in the folder lik: /resources/edu/cmu/sphinx/models/en-us/default.config.xml
As a workaround, i copied the resource files i use to a directory in the project itself, and referred to them, and seems it works. Still i would like to know why it misbehaves as described earlier, and what is the proper solution
The .classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="res"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
The .project:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Speech Recognizer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>fr.obeo.dsl.viewpoint.nature.modelingproject</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
The pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpeechRecognizer</groupId>
<artifactId>SpeechRecognizer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.3</source>
<target>1.2</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>edu.cmu.sphinx</groupId>
<artifactId>sphinx4-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.cmu.sphinx</groupId>
<artifactId>sphinx4-data</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.cmu.sphinx</groupId>
<artifactId>sphinx4-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>edu.cmu.sphinx</groupId>
<artifactId>sphinx4-samples</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Upvotes: 1
Views: 528
Reputation: 13
Go to sphinx4-5prealpha-src directory on your computer.
To edit the Sphinx API, go to sphinx4-5prealpha-src\sphinx4-core\src\main\java\edu\cmu\sphinx\api directory and edit these files however you like.
Download Gradle on your computer and use Git Bash or Terminal. Make sure you also have a Java compiler that works on your shell.
Use a shell to type the command, making sure you are in the sphinx4-5prealpha directory:
cd sphinx4-5prealpha
build gradle
Get all jar files contained in:
sphinx4-5prealpha/sphinx4-core/build/libs
sphinx4-5prealpha/sphinx4-data/build/libs
Upvotes: 1
Reputation: 4156
How are you loading the config file?
You have to use ClassName.class.getResourceAsStream(String pathTOConfigFile) to load any configurations when executing jar files.
When using maven, the src/main/resources
folder will be checked to include the resources on the classpath
.
Upvotes: 0
Reputation: 25220
To properly create a single executable jar you need to make sure that Eclipse unpacks the dependencies in the right place. The xml file must be in the /edu/cmu/sphinx/api
folder inside the jar after packaging. All your paths with en-us
are not reasonable because it is not the place where configuration file is expected.
To get further help on this issue you need to provide more information about project layout and the way you use IDE. You seem to confuse maven with eclipse build, you could just use maven.
Upvotes: 1