2013-03-21 36 views
-1
public static void main(String[] args) { try { 
      URL url; 
      if (args.length > 0) { 
       url = new File(args[0]).toURI().toURL(); 
      } else { 
       url = HelloWorld.class.getResource("helloworld.config.xml"); 
      } 

      System.out.println("Loading..."); 

      ConfigurationManager cm = new ConfigurationManager(url); 
      System.out.println("Configured Successfully"); 
     Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); // I found exception in this line 
     System.out.println("Recognizer Ready"); 
     Microphone microphone = (Microphone) cm.lookup("microphone"); 
     System.out.println("Microphone Ready"); 

      /* allocate the resource necessary for the recognizer */ 
      recognizer.allocate(); 

      /* the microphone will keep recording until the program exits */ 
     if (microphone.startRecording()) { 

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

     while (true) { 
      System.out.println   ("Start speaking. Press Ctrl-C to quit.\n"); 

        /* 
        * This method will return when the end of speech 
        * is reached. Note that the endpointer will determine 
        * the end of speech. 
        */ 
      Result result = recognizer.recognize(); 

      if (result != null) {   String resultText = result.getBestFinalResultNoFiller();   System.out.println("You 
said: " + resultText + "\n"); 
      } else {   System.out.println("I can't hear what you said.\n"); 
      }  } 
     } else {  System.out.println("Cannot start microphone.");   recognizer.deallocate();  System.exit(1); 
     } 
     } catch (IOException e) { 
      System.err.println("Problem when loading HelloWorld: " + e); 
      e.printStackTrace(); 
     } catch (PropertyException e) { 
      System.err.println("Problem configuring HelloWorld: " + e); 
      e.printStackTrace(); 
     } catch (Exception e) { 
      System.err.println("Problem creating HelloWorld: " + e); 
      e.printStackTrace(); 
     } } 

尝试语音识别研究的时候有了这个代码,我得到了以下异常:当我运行我的程序的ClassNotFoundException在Java中

class not found !java.lang.ClassNotFoundException: 
edu.cmu.sphinx.model.acoustic.WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.Model 
Problem configuring HelloWorld: Property Exception component:'flatLinguist' 
property:'acousticModel' - mandatory property is not set! 
edu.cmu.sphinx.util.props.InternalConfigurationException 
Property Exception component:'flatLinguist' property:'acousticModel' - mandatory 
property is not set! 
edu.cmu.sphinx.util.props.InternalConfigurationException 

出现此错误。

我该如何解决这个问题?

+2

我认为你应该为你的问题添加更多细节。像代码的相关部分一样。赶上这个例外? – 2013-03-21 10:09:11

+1

使用WYSIWYG编辑器正确设置您的代码。 – carlspring 2013-03-21 10:21:03

+0

“helloworld.config.xml”文件包含什么内容? – Byron 2013-03-21 10:35:34

回答

0

从日志它看起来像您正在使用过时的config.xml文件指的是类edu.cmu.sphinx.model.acoustic.WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.Model

这个类是从Sphinx4很久以前

删除

下载最新的sphinx4源代码,并使用最新的Sphinx4包括配置文件的演示,一切都会正常工作。

+0

谢谢尼古拉 – ManojB 2013-03-21 12:41:43

相关问题