当前位置: 代码迷 >> Android >> 哪位高手能解释一上以上代码
  详细解决方案

哪位高手能解释一上以上代码

热度:57   发布时间:2016-05-01 11:38:25.0
谁能解释一下以下代码?
Simple, synchronous speech recognizer, using the Nuance SREC package. Usages proceeds as follows: 

Create a Recognizer. 
Create a Recognizer.Grammar. 
Setup the Recognizer.Grammar. 
Reset the Recognizer.Grammar slots, if needed. 
Fill the Recognizer.Grammar slots, if needed. 
Compile the Recognizer.Grammar, if needed. 
Save the filled Recognizer.Grammar, if needed. 
Start the Recognizer. 
Loop over advance and putAudio until recognition complete. 
Fetch and process results, or notify of failure. 
Stop the Recognizer. 
Destroy the Recognizer. 
Below is example code

 
 // create and start audio input
 InputStream audio = new MicrophoneInputStream(11025, 11025*5);
 // create a Recognizer
 String cdir = Recognizer.getConfigDir(null);
 Recognizer recognizer = new Recognizer(cdir + "/baseline11k.par");
 // create and load a Grammar
 Recognizer.Grammar grammar = recognizer.new Grammar(cdir + "/grammars/VoiceDialer.g2g");
 // setup the Grammar to work with the Recognizer
 grammar.setupRecognizer();
 // fill the Grammar slots with names and save, if required
 grammar.resetAllSlots();
 for (String name : names) grammar.addWordToSlot("@Names", name, null, 1, "V=1");
 grammar.compile();
 grammar.save(".../foo.g2g");
 // start the Recognizer
 recognizer.start();
 // loop over Recognizer events
 while (true) {
     switch (recognizer.advance()) {
     case Recognizer.EVENT_INCOMPLETE:
     case Recognizer.EVENT_STARTED:
     case Recognizer.EVENT_START_OF_VOICING:
     case Recognizer.EVENT_END_OF_VOICING:
         // let the Recognizer continue to run
         continue;
     case Recognizer.EVENT_RECOGNITION_RESULT:
         // success, so fetch results here!
         for (int i = 0; i < recognizer.getResultCount(); i++) {
             String result = recognizer.getResult(i, Recognizer.KEY_LITERAL);
         }
         break;
     case Recognizer.EVENT_NEED_MORE_AUDIO:
         // put more audio in the Recognizer
         recognizer.putAudio(audio);
         continue;
     default:
         notifyFailure();
         break;
  相关解决方案