2013-07-11 1 views
1

설정 파일을 분석하여 스핑크스에 익숙해 지려고합니다.null 포인터 예외 설정 파일

불행히도, 나는 그것을 컴파일 할 수 없었습니다. helloworld 예제의 동일한 클래스 내용을 사용하여 나열된 구성 파일을 제거하고 표시된 파일로 대체했습니다. http://cmusphinx.sourceforge.net/sphinx4/javadoc/edu/cmu/sphinx/util/props/doc-files/ConfigurationManagement.html

null 포인터 예외가 발생하며 그 이유를 알 수 없습니다. 나는 sphinx4.jar, WSJ_8gau .... jar, js.jar 및 jsapi.jar를 가져 왔습니다. 나는 그것이 설정 파일에서 읽는 것을 안다.

HelloWorld.class.getResource ("helloworld.config.xml")로 올바르게 두었습니다. 다음은 약간의 변경이있는 코드입니다.

package speechcapture; 
//import edu.cmu.sphinx.demo.helloworld.HelloWorld; 
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 capturespeech { 
    public void speechtolist(String[] args){ 
      ConfigurationManager cm; 

      if (args.length > 0) { 
       cm = new ConfigurationManager(args[0]); 
      } else { 
       cm = new ConfigurationManager("testing.config.xml"); 
      } 

      Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); 
      recognizer.allocate(); //Where error occurs 

      // start the microphone or exit if the program 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)"); 

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

       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"); 
       } 
     }  
    } 
} 

답변

0

인식기이 줄에 널 (null) :

 Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); 
     recognizer.allocate(); //Where error occurs 

"인식"라는 구성 요소가 구성 XML 파일에서 누락 되었기 때문에. XML 파일을 업데이트 할 때 코드가 동기화되어 있는지 확인하십시오.

https://sourceforge.net/p/cmusphinx/discussion/sphinx4/thread/91efe5b7/?limit=25#52da

: 자세한 내용은

은 원래의 설명을 참조