Package jpotter

Source Code of jpotter.IncantationManager

package jpotter;

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;

/**
* Date: 27 Mar 2011 Time: 12:22:09
*
* @author Thomas Michel
*/
public class IncantationManager {

  private static final IncantationManager instance = new IncantationManager();

  public static IncantationManager getInstance() {
    return instance;
  }

  private ConfigurationManager cm;
  private Recognizer recognizer;
  private Microphone microphone;

  private IncantationManager() {
    if (instance != null)
      throw new AssertionError();
    cm = new ConfigurationManager(HarryPotter.class.getResource("harry.config.xml"));
    recognizer = (Recognizer) cm.lookup("recognizer");
    recognizer.allocate();
    microphone = (Microphone) cm.lookup("microphone");
    microphone.startRecording();
  }

  public void listen() {
    if (!microphone.startRecording()) {
      System.out.println("Cannot start microphone.");
      // recognizer.deallocate();
    } else {
      System.out.println("speak!");
    }
  }

  public void finish() {
    Result result = recognizer.recognize();
    if (result != null) {
      String resultText = result.getBestResultNoFiller();
      System.out.println("You said: " + resultText + '\n');
      FusionManager.getInstance().postIncantation(resultText);
    } else {
      System.out.println("I can't hear what you said.\n");
    }
    microphone.stopRecording();
    System.out.println("stopped mic");
  }

  public static void main(String[] args) {
    IncantationManager.getInstance().listen();
  }

}
TOP

Related Classes of jpotter.IncantationManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.