Recognizer API

来源:互联网 发布:淘宝店需要营业执照吗 编辑:程序博客网 时间:2024/06/04 18:21

public class Recognizer implements Configurable, ResultProducer

此为识别了设置了相应的状态,以防止在某些方法在其必要的条件之前被调用。使用了异常处理。靠继承RuntimeException来实现新的异常类。

Sphinx4识别器。此是sphinx4的主要的入口。一个识别器的典型使用如下:

public void recognizeDigits() {

      URLdigitsConfig = new URL(“file:./digits.xml”);

     ConfigurationManager cm = new ConfigurationManager(digitsConfig);

      RecognizersphinxDigitsRecognizer

          =(Recognizer) cm.lookup(“digitsRecognizer”“);

      boolean done =false;

      Result result;
       sphinxDigitsRecognizer.allocate();
      // echo spoken digits, quit when’nine’ is spoken
       while (!done) {

           result =sphinxDigitsRecognizer.recognize();

          System.out.println(“Result: ” + result);

           done =result.toString().equals(“nine”);

      }

     sphinxDigitsRecognizer.deallocate();

  }

本类的属性:

 @S4Component(type =Decoder.class)

public final static String PROP_DECODER =“decoder”;识别器所使用的解码器。

 @S4ComponentList(type =Monitor.class)

public final static String PROP_MONITORS =“monitors”;此识别器所使用的监视器的集合。

 public static enum State { DEALLOCATED, ALLOCATING,ALLOCATED, READY,RECOGNIZING, DEALLOCATING,ERROR };定义了识别器的所有可能的状态。

 private String name;识别器的名字。

 private Decoder decoder;使用的解码器

private State currentState = State.DEALLOCATED;当前状态为未分配资源的状态。

 private finalList<StateListener> stateListeners = Collections.synchronizedList(new ArrayList<StateListener>());为状态监听器列表

 private List<Monitor> monitors;使用的监听器列表。

本类的构造方法:

public Recognizer();为空的构造方法。

 public Recognizer(Decoder decoder,List<Monitor> monitors);给定解码器和监听器列表来创建对象。

本类的方法:

public void newProperties(PropertySheetps);对属性进行设置。

  public String toString();为此对象的字符串表示。为名字和当前状态。

 public voidremoveStateListener(StateListener stateListener);从监听器列表中移除给定的监听器。此方法可以再任何状态调用。

 public void removeResultListener(ResultListenerresultListener);移除给定的结果监听器。此方法可以再任何状态被调用。此方法调用解码器的方法来实现的。

public void addStateListener(StateListener stateListener);为此识别器添加一个状态监听器,即添加到监听器列表中。 无论何时当识别器的状态改变时,此状态监听器被调用,此方法可以在任何状态被调用。

 public voidaddResultListener(ResultListener resultListener);为此识别器添加一个结果监听器。无论何时当一个新的结果被识别器产生时,此结果监听器被调用。此方法可以在任何时候被调用。是通过解码器来实现的。

 public void resetMonitors() ;为此识别器重新设置监听器即Resets the monitorsmonitoring this recognizer

 public State getState();获得此识别器的状态,此方法可以在任何时候被调用。返回的当前状态属性。

 public void deallocate();释放此识别器的资源,此方法仅仅在识别器处于已经分配的状态下才被调用。

  public void allocate();为此识别器分配必要的资源。注意此方法需要一些时间才能完成。此方法仅仅在识别器处于已经被释放资源的状态下才能被调用。如果识别器不在DEALLOCATED状态,则会抛出异常。

 private void setState(State newState);设置当前状态。把所有的状态监听器都该变成当前的状态。输入为:新的状态。

private void checkState(State desiredState);检查确保识别器处于给定的状态。输入:desiredState为识别器应该处于的状态。如果识别器不做给定的状态,则会抛出异常。

 public Result recognize();对给定输入数量的特征帧矢量进行识别处理,或者直到一个最终结果(final result)被产生。此方法仅在识别器处于allocated已经分配状态 才能被调用。返回的是一个识别的结果集result。如果识别器不处于allocated状态,则会抛出异常。

 public Result recognize(String referenceText);对给定输入数量的特征帧矢量进行识别处理,或者直到一个最终结果(final result)被产生。此方法仅在识别器处于allocated已经分配状态 才能被调用。返回的是一个识别的结果集result。如果识别器不处于allocated状态,则会抛出异常。在其中主要靠解码器的decode方法来完成识别。

转自:http://blog.csdn.net/taiyb/article/details/42610281

原创粉丝点击