Package edu.cmu.sphinx.recognizer

Examples of edu.cmu.sphinx.recognizer.Recognizer


      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");
View Full Code Here


  @Override
  public void process(JCas aJCas) throws AnalysisEngineProcessException {
   
    try {
     
      Recognizer recognizer;
     
      //Clone necessario, istanzia un nuovo Configuration Manager per ogni process()
      //in caso di più sphinxAE in esecuzione, le risorse vengono duplicate da quello
      //creato nel metodo inizilize() per non reimpostare tutti i parametri
      ConfigurationManager cm = this.cm.clone();
     
      recognizer = (Recognizer) cm.lookup("recognizer");
     
      List<File> batch = new ArrayList<File>();
      ArrayList<Integer> beginAnnot = new ArrayList<Integer>();
      ArrayList<Integer> endAnnot = new ArrayList<Integer>();
      ArrayList<Long> beginTimeAnnot = new ArrayList<Long>();
      ArrayList<Long> endTimeAnnot = new ArrayList<Long>();
     
      StringBuffer document = new StringBuffer();
      Iterator audioIt = aJCas.getAnnotationIndex(Audio.type).iterator();
      Audio audio = (Audio) audioIt.next();
      Result result;
     
  //    getContext().getLogger().log("CF File is " + ConfigFile);
     
  //    if(audioIt.hasNext())
     
      ConcatAudioFileDataSource data = (ConcatAudioFileDataSource) cm.lookup("dataSource");
     
      for(String i: audio.getAudioPath().toArray())
        batch.add(new File(i));
     
      data.setBatchFiles(batch);
     
      recognizer.allocate();
     
      getContext().getLogger().log(Level.INFO, "Start recognition of " + audio.getAudioPath().toString(0));
      Long comp1 = System.currentTimeMillis();
     
      while((result = recognizer.recognize()) != null){
       
        ArrayList<TextAndTime> stt = TextAndTime.convert(result);
       
        if(stt != null)
          for(TextAndTime t: stt){
           
            String word = t.getWord();
           
            if(word.matches(TextAndTime.PATTERN_SIL))
              document.append(word);
            else{           
              beginAnnot.add(document.length());
              document.append(word);
              endAnnot.add(document.length());
             
              beginTimeAnnot.add(t.getIniTime());
              endTimeAnnot.add(t.getEndTime());
            }
            document.append(" ");
          }
       
      }
     
          Long comp2 = System.currentTimeMillis();
          getContext().getLogger().log(Level.INFO, "End recognition of " + audio.getAudioPath().toString(0));
          getContext().getLogger().log(Level.INFO, TextAndTime.getFormattedLong(comp2 - comp1)
              + " is total recognition time of this audio files " + audio.getAudioPath().toString(0));
          getContext().getLogger().log(Level.INFO, "Text " + document.toString());
         
          aJCas.setDocumentText(document.toString());
         
          Iterator<Long> itb = beginTimeAnnot.iterator(),
              ite = endTimeAnnot.iterator();
          Iterator<Integer> itbb = beginAnnot.iterator(),
              itee = endAnnot.iterator();
         
          while(itb.hasNext()){
            STText stt = new STText(aJCas);
            stt.setBegin(itbb.next());
            stt.setEnd(itee.next());
            stt.setStartTime(itb.next());
            stt.setEndTime(ite.next());
            stt.addToIndexes();
          }
         
          recognizer.deallocate();
    } catch (CloneNotSupportedException e) {
      getContext().getLogger().log(Level.WARNING, "Configuration Manager CloneError: " + e.getMessage());
    }
       
  }
View Full Code Here

    * (non-Javadoc)
    *
    * @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet)
    */
    public void newProperties(PropertySheet ps) throws PropertyException {
        Recognizer newRecognizer = (Recognizer) ps.getComponent(
                PROP_RECOGNIZER);
        initRecognizer(newRecognizer);
        showSummary = ps.getBoolean(PROP_SHOW_SUMMARY);
        showDetails = ps.getBoolean(PROP_SHOW_DETAILS);
    }
View Full Code Here

        URL lm = getClass().getResource("hellongram.trigram.lm");

        ConfigurationManager cm = new ConfigurationManager(configURL);
        setProperty(cm, "trigramModel", "location", lm.toString());

        Recognizer recognizer = cm.lookup("recognizer");
        StreamDataSource dataSource = cm.lookup(StreamDataSource.class);

        AudioInputStream ais = getAudioInputStream(audioFileURL);
        dataSource.setInputStream(ais);

        recognizer.allocate();
        Lattice lattice = new Lattice(recognizer.recognize());

        cm = new ConfigurationManager(configURL);
        setProperty(cm, "keepAllTokens", "true");
        setProperty(cm, "trigramModel", "location", lm.toString());

        recognizer = cm.lookup("recognizer");
        recognizer.allocate();
        dataSource = cm.lookup(StreamDataSource.class);
        dataSource.setInputStream(getAudioInputStream(audioFileURL));
        Lattice allLattice = new Lattice(recognizer.recognize());

        assertTrue(lattice.isEquivalent(allLattice));
    }
View Full Code Here

                url = HelloDigits.class.getResource("hellodigits.config.xml");
            }

            ConfigurationManager cm = new ConfigurationManager(url);

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

   
      /* allocate the resource necessary for the recognizer */
            recognizer.allocate();
   
      /* the microphone will keep recording until the program exits */
            if (microphone.startRecording()) {

                System.out.println
                        ("Say any digit(s): e.g. \"two oh oh four\", " +
                                "\"three six five\".");

                while (true) {
                    System.out.println
                            ("Start speaking. Press Ctrl-C to quit.\n");
   
        /*
        * This method will return when the end of speech
        * is reached. Note that the endpointer will determine
        * the end of speech.
        */
                    Result result = recognizer.recognize();

                    if (result != null) {
                        String resultText = result.getBestResultNoFiller();
                        System.out.println("You said: " + resultText + "\n");
                    } else {
                        System.out.println("I can't hear what you said.\n");
                    }
                }
            } else {
                System.out.println("Cannot start microphone.");
                recognizer.deallocate();
                System.exit(1);
            }
        } catch (IOException e) {
            System.err.println("Problem when loading HelloDigits: " + e);
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of edu.cmu.sphinx.recognizer.Recognizer

Copyright © 2018 www.massapicom. 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.