コード例 #1
0
ファイル: LatticeCompTest.java プロジェクト: zaqzaq/cmusphinx
  /**
   * Main method for running the LatticeCompTest demo.
   *
   * @throws IOException
   * @throws UnsupportedAudioFileException
   */
  @Test
  public void testLatticeComp() throws UnsupportedAudioFileException, IOException {

    URL audioFileURL = new File("src/test/edu/cmu/sphinx/result/test/green.wav").toURI().toURL();
    URL configURL = new File("src/test/edu/cmu/sphinx/result/test/config.xml").toURI().toURL();

    ConfigurationManager cm = new ConfigurationManager(configURL);

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

    StreamDataSource reader = (StreamDataSource) cm.lookup("streamDataSource");

    AudioInputStream ais = AudioSystem.getAudioInputStream(audioFileURL);

    /* set the stream data source to read from the audio file */
    reader.setInputStream(ais, audioFileURL.getFile());

    /* allocate the resource necessary for the recognizer */
    recognizer.allocate();

    /* decode the audio file */
    Result result = recognizer.recognize();

    /* print out the results */
    Lattice lattice = new Lattice(result);
    lattice.dumpAISee("lattice.gdl", "lattice");

    recognizer.deallocate();

    cm = new ConfigurationManager(configURL);

    ConfigurationManagerUtils.setProperty(cm, "keepAllTokens", "true");

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

    reader = (StreamDataSource) cm.lookup("streamDataSource");
    reader.setInputStream(AudioSystem.getAudioInputStream(audioFileURL), audioFileURL.getFile());

    Result allResult = recognizer.recognize();

    Lattice allLattice = new Lattice(allResult);
    allLattice.dumpAISee("allLattice.gdl", "All Lattice");

    assertTrue(lattice.isEquivalent(allLattice));
  }
コード例 #2
0
  public static void main(String[] args) {
    ConfigurationManager cm;

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

    // allocate the recognizer
    System.out.println("Loading...");
    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);
    }

    printInstructions();

    // loop the recognition until the programm exits.
    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');
        if (resultText == "alone") {
          System.out.println("Do not be afraid, baby!");
        }

      } else {
        System.out.println("I can't hear what you said.\n");
      }
    }
  }
コード例 #3
0
ファイル: ClippyGui.java プロジェクト: teihoata/Clippy
  /**
   * Initializes the Logic classes in the interface
   *
   * @throws IOException
   * @throws InterruptedException
   */
  private void setup() throws IOException, InterruptedException {
    // Get the configuration from the xml resource
    URL url = WordRecognizer.class.getResource("clippy.config.xml");
    ConfigurationManager cm = new ConfigurationManager(url);
    wordsRecognizer = (WordRecognizer) cm.lookup("dialogManager");
    wordsRecognizer.setGui(this);
    MyBehavior menu = new MyBehavior(this);
    MyBehavior time = new MyBehavior(this);
    MyBehavior music = new MyMusicBehavior(this);
    MyBehavior movie = new MyMovieBehavior(this);
    MyBehavior desktop = new MyDesktopBehavior(this);
    MyBehavior website = new MyWebsiteBehavior(this);
    search = new MyGoogleSearchBehavior(this);

    // Add each menu node to the words to be recognised
    wordsRecognizer.addNode("menu", menu);
    wordsRecognizer.addNode("tell me the time", time);
    wordsRecognizer.addNode("music", music);
    wordsRecognizer.addNode("movies", movie);
    wordsRecognizer.addNode("desktop", desktop);
    wordsRecognizer.addNode("web", website);
    wordsRecognizer.addNode("search", search);
    currentBehavior = menu;

    setHeader("Loading IntelliJ");
    initJIntellitype();

    setHeader("Loading Dialogs");
    wordsRecognizer.allocate();

    setHeader("Running  ...");
    wordsRecognizer.addWordListener(
        new WordsListener() {

          public void notify(String word) {
            updateMenu(word);
          }
        });

    wordsRecognizer.setInitialNode("menu");
    voiceMenu.setWordsRecognizer(wordsRecognizer);
  }
コード例 #4
0
ファイル: recognizerTest.java プロジェクト: G10DRAS/speech
  static void processSpeech(SphinxServer server) {
    ConfigurationManager cm = new ConfigurationManager(PATrecognizerTest.class.getResource(config));
    // allocate the recognizer
    Log.info("Loading...");
    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()) {
      Log.severe("Cannot start microphone.");
      recognizer.deallocate();
      System.exit(1);
    }

    System.out.println("Sample questions are in PATlm_training_file");

    // loop the recognition until the programm exits.
    while (true) {
      System.out.println("Start speaking. Press Ctrl-C to quit.\n");

      Result result = recognizer.recognize();

      if (result != null) {
        String resultText = result.getBestResultNoFiller();
        System.out.println("You said: " + resultText + '\n');
        String name = server.getServerId();
        String message = work1 + "\"" + resultText + "\"}";
        server.execute(message);
        try {
          Thread.sleep(4000);
        } catch (Exception e) {
          System.out.println(e.toString());
          break;
        }
      } else {
        System.out.println("I can't hear what you said.");
      }
    }
  }
コード例 #5
0
  public static void main(String[] args) throws Exception {

    String configPath;
    String testFile = null;
    PrintStream outStream = System.out;

    if (args.length == 0) {
      System.out.println(
          "Usage: java LargeTrigramModelTest <config_file> " + "[<testFile>] " + "<output_file>");
    }

    configPath = args[0];
    if (args.length >= 2) {
      testFile = args[1];
    }
    if (args.length >= 3) {
      outStream = new PrintStream(new FileOutputStream(args[2]));
    }

    ConfigurationManager cm = new ConfigurationManager(configPath);

    FastDictionary dictionary = (FastDictionary) cm.lookup("dictionary");
    LargeTrigramModel lm = (LargeTrigramModel) cm.lookup("trigramModel");

    InputStream stream = new FileInputStream(testFile);

    BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

    Timer timer = TimerPool.getTimer(new Object(), "lmLookup");

    String input;

    List<WordSequence> wordSequences = new LinkedList<WordSequence>();

    while ((input = reader.readLine()) != null) {

      if (!input.equals("<START_UTT>") && !input.equals("<END_UTT>")) {
        StringTokenizer st = new StringTokenizer(input);
        List<Word> list = new ArrayList<Word>();
        while (st.hasMoreTokens()) {
          String tok = st.nextToken().toLowerCase().trim();
          list.add(dictionary.getWord(tok));
        }
        WordSequence wordSequence = new WordSequence(list);
        wordSequences.add(wordSequence);
      }
    }

    int[] logScores = new int[wordSequences.size()];
    int s = 0;

    timer.start();

    for (WordSequence ws : wordSequences) {
      lm.start();
      logScores[s++] = (int) lm.getProbability(ws);
      lm.stop();
    }

    timer.stop();

    s = 0;
    for (WordSequence ws : wordSequences) {
      outStream.println(Utilities.pad(logScores[s++], 10) + ' ' + getString(ws));
    }

    if (true) {
      long usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
      System.out.println("Used memory: " + usedMemory + " bytes");
      System.out.println("NGram misses: " + lm.getNGramMisses());
    }

    TimerPool.dumpAll();
  }
コード例 #6
0
  /**
   * Construct a AlphaDictionaryTest with the given SphinxProperties file.
   *
   * @param propertiesFile a SphinxProperties file
   */
  public AlphaDictionaryTest(String configFile) throws Exception {

    ConfigurationManager cm = new ConfigurationManager(configFile);
    Dictionary dictionary = (FullDictionary) cm.lookup("dictionary");
    System.out.println(dictionary);
  }