2013-02-13 102 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