2013-02-13 43 views
0

我有一點與獅身人面像4在Java中的一個問題。我波紋管的實現代碼:獅身人面像4 - 控制檯

package test.ionut; 

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 Test { 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) { 
     ConfigurationManager manager; 

     if(args.length > 0){ 
      manager=new ConfigurationManager(args[0]); 
      }else{ 

      manager=new ConfigurationManager(Test.class.getResource("test.config.xml")); 

     } 

     Recognizer recognizer=(Recognizer)manager.lookup("recognizer"); 
     recognizer.allocate(); 
     Microphone mic=(Microphone)manager.lookup("microphone"); 
     if(!mic.startRecording()){ 

      System.out.println("Mic not identified."); 
      recognizer.deallocate(); 
      System.out.println(1); 

      System.out.println("Say: (Good morning | Hello | Hi | Welcome) (Dipayan | Paul | Philip | Rita | Will)"); 

      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((new StringBuilder()).append("You said: ").append(resultText).append('\n').toString()); 
       System.out.println("You said: "+resultText+"..."); 
       } else { 
       System.out.println("I can't hear what you said.\n"); 
       } 
       } 

     } 


    } 

} 

this is the grammar file: 

***#JSGF V1.0;*** 

***grammar hello;*** 

***public <greet>= (Good morning | Hello | Hi | Welcome) (Paul | Philip | Rita | Will);*** 

and in the xml file i have modified so that the program knows what to do with the gram file. 



Bellow is the part of the code where i modified the xml: 

    <!-- ******************************************************** --> 
    <!-- The Grammar configuration        --> 
    <!-- ******************************************************** --> 

    <component name="jsgfGrammar" type="edu.cmu.sphinx.jsgf.JSGFGrammar"> 
     <property name="dictionary" value="dictionary"/> 
     <property name="grammarLocation" 
      value="resource:/test/ionut/"/> 
     <property name="grammarName" value="mydict"/> 
    <property name="logMath" value="logMath"/> 
    </component> 


Any help is appreciated. 

的問題是,當我編譯的代碼,我沒有錯誤,但控制檯不顯示任何東西,甚至不是第一個打印。如果我通過添加不在字典中的單詞來修改克文件,然後點擊運行,控制檯會向我顯示該單詞是字典中已知單詞的錯誤。刪除單詞後,點擊運行,然後再次顯示:控制檯沒有顯示任何內容。另外我已經用-mx256m參數添加了額外的堆內存。

我一直在試圖整天跟這一點,因爲我要實現我自己的語言的話有獅身人面像4。但現在,我只是做了一些測試,得到與它一起使用。

+0

很抱歉的壞編輯,不知道爲什麼的問題已發佈這樣的。如果你閱讀滾動窗格中的文本,你就會明白我在說什麼。再次,對不起... – Myself 2013-02-13 18:37:50

回答

0

你通過麥克風說,那些你把語法文件的話嗎?或者只是說出隨機的單詞。系統只能識別Grammer文件和字典中的單詞。請記住,.gram文件是該文件的子集。 DIC文件。

+0

是的,我已經把話說得對。事實證明,當我執行if的原因時,我意外地執行了if內部的原因。這個問題已經解決了寫:(!mic.startRecording())\t \t如果{ \t \t \t \t \t \t的System.out.println( 「麥克風不辨」); \t \t \t recognizer.deallocate(); \t \t \t的System.out.println(1); \t \t \t \t \t} \t \t \t \t \t \t的System.out.println( 「你說:(早上好|你好|喜|歡迎)(Dipayan |保羅|菲利普|麗塔|威爾)」); \t \t \t之後,它工作得很好。 – Myself 2013-02-13 18:53:03

+0

也Dipayan開發,非常感謝你的教程。它真的有幫助。 – Myself 2013-02-13 18:54:04