0

I am implementing speech to text using sphinx4 and my code is as below :

  public class TranscriberDemo {       

        public static void main(String[] args) throws Exception {

            Configuration configuration = new Configuration();

            configuration
                    .setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
            configuration
                    .setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
            configuration
                    .setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");

            StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(
                    configuration);
            InputStream stream = new FileInputStream(new File("BrookBentonAMillionMilesFromNowhere.wav"));

            recognizer.startRecognition(stream);
            SpeechResult result;
            while ((result = recognizer.getResult()) != null) {
                System.out.format("Hypothesis: %s\n", result.getHypothesis());
            }
            recognizer.stopRecognition();
        }
    }

I am getting following error :

Exception in thread "main" java.lang.UnsupportedClassVersionError: edu/cmu/sphinx/api/Configuration : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.pericent.test.TranscriberDemo.main(TranscriberDemo.java:16)

My pom.xml is as below :

 <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- servlet api jar for servlets -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
          <groupId>edu.cmu.sphinx</groupId>
          <artifactId>sphinx4-core</artifactId>
          <version>5prealpha-SNAPSHOT</version>
        </dependency>
        <dependency>
          <groupId>edu.cmu.sphinx</groupId>
          <artifactId>sphinx4-data</artifactId>
          <version>5prealpha-SNAPSHOT</version>
        </dependency>
  </dependencies>
   <repositories>
        <repository>
            <id>snapshots-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases><enabled>false</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
        </repository>
    </repositories>

I am using java7 and can't upgrade to java8. i also tried to find older version of Sphinx 4 but not succeed. So is there any other solution on that i can work upon that?

Jennifer
  • 351
  • 6
  • 18
  • You will have to compile your code with a JDK version, older or equal to the Java version that will execute the code. – Arnaud Dec 18 '15 at 10:53

2 Answers2

1

Your code has been compiled using Java 8 with a target version of Java 8. Because of that, it cannot run on Java 7 (which can only supports class files up to version 51 (details here).

You need to compile your code for Java 7 using either:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
</plugin>

from here

Or by setting

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>

in the main properties.

nfechner
  • 17,295
  • 7
  • 45
  • 64
1

I have just committed a fix for it in sphinx4, now it enforces java 1.7. I also deployed updated jars to Maven, you can just update and it should work.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87