Package jpotter

Source Code of jpotter.HarryPotter

package jpotter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

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

  public static void main(String[] args) {
    ConfigurationManager cm;

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

    final Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
    recognizer.allocate();

    // start the microphone or exit if the programm 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: (Abracadabra | Accio | Aguamenti | "
        + "Avada Kedavra | Avis | Confringo | Confundo | Crucio | Densaugeo | "
        + "Deprimo | Descendo | Diffindo | Episkey | Excelsiosempra | "
        + "Expelliarmus | Expulso | Furnunculus | Impedimenta | Incendio | "
        + "Petrificus Totalus | Protego | Rictusempra | Sectumsempra | " + "Serpensortia | Stupefy | Waddiwasi)");

    // loop the recognition until the program exits.
    Timer t = new Timer(2500, new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        System.out.println("start speaking");
        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");
        }
      }
    });
    t.setRepeats(true);
    t.start();
    // 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");
    // }
    // }
  }
}
TOP

Related Classes of jpotter.HarryPotter

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.