Recognizer.java revision f013e1afd1e68af5e3b868c26a653bbfb39538f8
1/* 2 * --------------------------------------------------------------------------- 3 * Recognizer.java 4 * 5 * Copyright 2007 Nuance Communciations, Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the 'License'); you may not 8 * use this file except in compliance with the License. 9 * 10 * You may obtain a copy of the License at 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 * License for the specific language governing permissions and limitations under 17 * the License. 18 * 19 * --------------------------------------------------------------------------- 20 */ 21 22 23package android.speech.srec; 24 25import android.util.Config; 26import android.util.Log; 27 28import java.io.File; 29import java.io.InputStream; 30import java.io.IOException; 31import java.util.Locale; 32 33/** 34 * Simple, synchronous speech recognizer, using the Nuance SREC package. 35 * Usages proceeds as follows: 36 * 37 * <ul> 38 * <li>Create a <code>Recognizer</code>. 39 * <li>Create a <code>Recognizer.Grammar</code>. 40 * <li>Setup the <code>Recognizer.Grammar</code>. 41 * <li>Reset the <code>Recognizer.Grammar</code> slots, if needed. 42 * <li>Fill the <code>Recognizer.Grammar</code> slots, if needed. 43 * <li>Compile the <code>Recognizer.Grammar</code>, if needed. 44 * <li>Save the filled <code>Recognizer.Grammar</code>, if needed. 45 * <li>Start the <code>Recognizer</code>. 46 * <li>Loop over <code>advance</code> and <code>putAudio</code> until recognition complete. 47 * <li>Fetch and process results, or notify of failure. 48 * <li>Stop the <code>Recognizer</code>. 49 * <li>Destroy the <code>Recognizer</code>. 50 * </ul> 51 * 52 * <p>Below is example code</p> 53 * 54 * <pre class="prettyprint"> 55 * 56 * // create and start audio input 57 * InputStream audio = new MicrophoneInputStream(11025, 11025*5); 58 * // create a Recognizer 59 * String cdir = Recognizer.getConfigDir(null); 60 * Recognizer recognizer = new Recognizer(cdir + "/baseline11k.par"); 61 * // create and load a Grammar 62 * Recognizer.Grammar grammar = recognizer.new Grammar(cdir + "/grammars/VoiceDialer.g2g"); 63 * // setup the Grammar to work with the Recognizer 64 * grammar.setupRecognizer(); 65 * // fill the Grammar slots with names and save, if required 66 * grammar.resetAllSlots(); 67 * for (String name : names) grammar.addWordToSlot("@Names", name, null, 1, "V=1"); 68 * grammar.compile(); 69 * grammar.save(".../foo.g2g"); 70 * // start the Recognizer 71 * recognizer.start(); 72 * // loop over Recognizer events 73 * while (true) { 74 * switch (recognizer.advance()) { 75 * case Recognizer.EVENT_INCOMPLETE: 76 * case Recognizer.EVENT_STARTED: 77 * case Recognizer.EVENT_START_OF_VOICING: 78 * case Recognizer.EVENT_END_OF_VOICING: 79 * // let the Recognizer continue to run 80 * continue; 81 * case Recognizer.EVENT_RECOGNITION_RESULT: 82 * // success, so fetch results here! 83 * for (int i = 0; i < recognizer.getResultCount(); i++) { 84 * String result = recognizer.getResult(i, Recognizer.KEY_LITERAL); 85 * } 86 * break; 87 * case Recognizer.EVENT_NEED_MORE_AUDIO: 88 * // put more audio in the Recognizer 89 * recognizer.putAudio(audio); 90 * continue; 91 * default: 92 * notifyFailure(); 93 * break; 94 * } 95 * break; 96 * } 97 * // stop the Recognizer 98 * recognizer.stop(); 99 * // destroy the Recognizer 100 * recognizer.destroy(); 101 * // stop the audio device 102 * audio.close(); 103 * 104 * </pre> 105 */ 106public final class Recognizer { 107 static { 108 System.loadLibrary("srec_jni"); 109 } 110 111 private static String TAG = "Recognizer"; 112 113 /** 114 * Result key corresponding to confidence score. 115 */ 116 public static final String KEY_CONFIDENCE = "conf"; 117 118 /** 119 * Result key corresponding to literal text. 120 */ 121 public static final String KEY_LITERAL = "literal"; 122 123 /** 124 * Result key corresponding to semantic meaning text. 125 */ 126 public static final String KEY_MEANING = "meaning"; 127 128 // handle to SR_Vocabulary object 129 private int mVocabulary = 0; 130 131 // handle to SR_Recognizer object 132 private int mRecognizer = 0; 133 134 // Grammar currently associated with Recognizer via SR_GrammarSetupRecognizer 135 private Grammar mActiveGrammar = null; 136 137 /** 138 * Get the pathname of the SREC configuration directory corresponding to the 139 * language indicated by the Locale. 140 * This directory contains dictionaries, speech models, 141 * configuration files, and other data needed by the Recognizer. 142 * @param locale <code>Locale</code> corresponding to the desired language, 143 * or null for default, currently <code>Locale.US</code>. 144 * @return Pathname of the configuration directory. 145 */ 146 public static String getConfigDir(Locale locale) { 147 if (locale == null) locale = Locale.US; 148 String dir = "/system/usr/srec/config/" + 149 locale.toString().replace('_', '.').toLowerCase(); 150 if ((new File(dir)).isDirectory()) return dir; 151 return null; 152 } 153 154 /** 155 * Create an instance of a SREC speech recognizer. 156 * 157 * @param configFile pathname of the baseline*.par configuration file, 158 * which in turn contains references to dictionaries, speech models, 159 * and other data needed to configure and operate the recognizer. 160 * A separate config file is needed for each audio sample rate. 161 * Two files, baseline11k.par and baseline8k.par, which correspond to 162 * 11025 and 8000 hz, are present in the directory indicated by 163 * {@link #getConfigDir}. 164 * @throws IOException 165 */ 166 public Recognizer(String configFile) throws IOException { 167 PMemInit(); 168 SR_SessionCreate(configFile); 169 mRecognizer = SR_RecognizerCreate(); 170 SR_RecognizerSetup(mRecognizer); 171 mVocabulary = SR_VocabularyLoad(); 172 } 173 174 /** 175 * Represents a grammar loaded into the Recognizer. 176 */ 177 public class Grammar { 178 private int mGrammar = 0; 179 180 /** 181 * Create a <code>Grammar</code> instance. 182 * @param g2gFileName pathname of g2g file. 183 */ 184 public Grammar(String g2gFileName) throws IOException { 185 mGrammar = SR_GrammarLoad(g2gFileName); 186 SR_GrammarSetupVocabulary(mGrammar, mVocabulary); 187 } 188 189 /** 190 * Reset all slots. 191 */ 192 public void resetAllSlots() { 193 SR_GrammarResetAllSlots(mGrammar); 194 } 195 196 /** 197 * Add a word to a slot. 198 * 199 * @param slot slot name. 200 * @param word word to insert. 201 * @param pron pronunciation, or null to derive from word. 202 * @param weight weight to give the word. One is normal, 50 is low. 203 * @param tag semantic meaning tag string. 204 */ 205 public void addWordToSlot(String slot, String word, String pron, int weight, String tag) { 206 SR_GrammarAddWordToSlot(mGrammar, slot, word, pron, weight, tag); 207 } 208 209 /** 210 * Compile all slots. 211 */ 212 public void compile() { 213 SR_GrammarCompile(mGrammar); 214 } 215 216 /** 217 * Setup <code>Grammar</code> with <code>Recognizer</code>. 218 */ 219 public void setupRecognizer() { 220 SR_GrammarSetupRecognizer(mGrammar, mRecognizer); 221 mActiveGrammar = this; 222 } 223 224 /** 225 * Save <code>Grammar</code> to g2g file. 226 * 227 * @param g2gFileName 228 * @throws IOException 229 */ 230 public void save(String g2gFileName) throws IOException { 231 SR_GrammarSave(mGrammar, g2gFileName); 232 } 233 234 /** 235 * Release resources associated with this <code>Grammar</code>. 236 */ 237 public void destroy() { 238 // TODO: need to do cleanup and disassociation with Recognizer 239 if (mGrammar != 0) { 240 SR_GrammarDestroy(mGrammar); 241 mGrammar = 0; 242 } 243 } 244 245 /** 246 * Clean up resources. 247 */ 248 protected void finalize() { 249 if (mGrammar != 0) { 250 destroy(); 251 throw new IllegalStateException("someone forgot to destroy Grammar"); 252 } 253 } 254 } 255 256 /** 257 * Start recognition 258 */ 259 public void start() { 260 // TODO: shouldn't be here? 261 SR_RecognizerActivateRule(mRecognizer, mActiveGrammar.mGrammar, "trash", 1); 262 SR_RecognizerStart(mRecognizer); 263 } 264 265 /** 266 * Process some audio and return the current status. 267 * @return recognition event, one of: 268 * <ul> 269 * <li><code>EVENT_INVALID</code> 270 * <li><code>EVENT_NO_MATCH</code> 271 * <li><code>EVENT_INCOMPLETE</code> 272 * <li><code>EVENT_STARTED</code> 273 * <li><code>EVENT_STOPPED</code> 274 * <li><code>EVENT_START_OF_VOICING</code> 275 * <li><code>EVENT_END_OF_VOICING</code> 276 * <li><code>EVENT_SPOKE_TOO_SOON</code> 277 * <li><code>EVENT_RECOGNITION_RESULT</code> 278 * <li><code>EVENT_START_OF_UTTERANCE_TIMEOUT</code> 279 * <li><code>EVENT_RECOGNITION_TIMEOUT</code> 280 * <li><code>EVENT_NEED_MORE_AUDIO</code> 281 * <li><code>EVENT_MAX_SPEECH</code> 282 * </ul> 283 */ 284 public int advance() { 285 return SR_RecognizerAdvance(mRecognizer); 286 } 287 288 /** 289 * Put audio samples into the <code>Recognizer</code>. 290 * @param buf holds the audio samples. 291 * @param offset offset of the first sample. 292 * @param length number of bytes containing samples. 293 * @param isLast indicates no more audio data, normally false. 294 * @return number of bytes accepted. 295 */ 296 public int putAudio(byte[] buf, int offset, int length, boolean isLast) { 297 return SR_RecognizerPutAudio(mRecognizer, buf, offset, length, isLast); 298 } 299 300 /** 301 * Read audio samples from an <code>InputStream</code> and put them in the 302 * <code>Recognizer</code>. 303 * @param audio <code>InputStream</code> containing PCM audio samples. 304 */ 305 public void putAudio(InputStream audio) throws IOException { 306 // make sure the audio buffer is allocated 307 if (mPutAudioBuffer == null) mPutAudioBuffer = new byte[512]; 308 // read some data 309 int nbytes = audio.read(mPutAudioBuffer); 310 // eof, so signal Recognizer 311 if (nbytes == -1) { 312 SR_RecognizerPutAudio(mRecognizer, mPutAudioBuffer, 0, 0, true); 313 } 314 // put it into the Recognizer 315 else if (nbytes != SR_RecognizerPutAudio(mRecognizer, mPutAudioBuffer, 0, nbytes, false)) { 316 throw new IOException("SR_RecognizerPutAudio failed nbytes=" + nbytes); 317 } 318 } 319 320 // audio buffer for putAudio(InputStream) 321 private byte[] mPutAudioBuffer = null; 322 323 /** 324 * Get the number of recognition results. Must be called after 325 * <code>EVENT_RECOGNITION_RESULT</code> is returned by 326 * <code>advance</code>, but before <code>stop</code>. 327 * 328 * @return number of results in nbest list. 329 */ 330 public int getResultCount() { 331 return SR_RecognizerResultGetSize(mRecognizer); 332 } 333 334 /** 335 * Get a set of keys for the result. Must be called after 336 * <code>EVENT_RECOGNITION_RESULT</code> is returned by 337 * <code>advance</code>, but before <code>stop</code>. 338 * 339 * @param index index of result. 340 * @return array of keys. 341 */ 342 public String[] getResultKeys(int index) { 343 return SR_RecognizerResultGetKeyList(mRecognizer, index); 344 } 345 346 /** 347 * Get a result value. Must be called after 348 * <code>EVENT_RECOGNITION_RESULT</code> is returned by 349 * <code>advance</code>, but before <code>stop</code>. 350 * 351 * @param index index of the result. 352 * @param key key of the result. This is typically one of 353 * <code>KEY_CONFIDENCE</code>, <code>KEY_LITERAL</code>, or 354 * <code>KEY_MEANING</code>, but the user can also define their own keys 355 * in a grxml file, or in the <code>tag</code> slot of 356 * <code>Grammar.addWordToSlot</code>. 357 * @return the result. 358 */ 359 public String getResult(int index, String key) { 360 return SR_RecognizerResultGetValue(mRecognizer, index, key); 361 } 362 363 /** 364 * Stop the <code>Recognizer</code>. 365 */ 366 public void stop() { 367 SR_RecognizerStop(mRecognizer); 368 SR_RecognizerDeactivateRule(mRecognizer, mActiveGrammar.mGrammar, "trash"); 369 } 370 371 /** 372 * Clean up resources. 373 */ 374 public void destroy() { 375 try { 376 if (mVocabulary != 0) SR_VocabularyDestroy(mVocabulary); 377 } finally { 378 mVocabulary = 0; 379 try { 380 if (mRecognizer != 0) SR_RecognizerUnsetup(mRecognizer); 381 } finally { 382 try { 383 if (mRecognizer != 0) SR_RecognizerDestroy(mRecognizer); 384 } finally { 385 mRecognizer = 0; 386 try { 387 SR_SessionDestroy(); 388 } finally { 389 PMemShutdown(); 390 } 391 } 392 } 393 } 394 } 395 396 /** 397 * Clean up resources. 398 */ 399 protected void finalize() throws Throwable { 400 if (mVocabulary != 0 || mRecognizer != 0) { 401 destroy(); 402 throw new IllegalStateException("someone forgot to destroy Recognizer"); 403 } 404 } 405 406 /* an example session captured, for reference 407 void doall() { 408 if (PMemInit ( ) 409 || lhs_audioinOpen ( WAVE_MAPPER, SREC_TEST_DEFAULT_AUDIO_FREQUENCY, &audio_in_handle ) 410 || srec_test_init_application_data ( &applicationData, argc, argv ) 411 || SR_SessionCreate ( "/system/usr/srec/config/en.us/baseline11k.par" ) 412 || SR_RecognizerCreate ( &applicationData.recognizer ) 413 || SR_RecognizerSetup ( applicationData.recognizer) 414 || ESR_SessionGetLCHAR ( L("cmdline.vocabulary"), filename, &flen ) 415 || SR_VocabularyLoad ( filename, &applicationData.vocabulary ) 416 || SR_VocabularyGetLanguage ( applicationData.vocabulary, &applicationData.locale ) 417 || (applicationData.nametag = NULL) 418 || SR_NametagsCreate ( &applicationData.nametags ) 419 || (LSTRCPY ( applicationData.grammars [0].grammar_path, "/system/usr/srec/config/en.us/grammars/VoiceDialer.g2g" ), 0) 420 || (LSTRCPY ( applicationData.grammars [0].grammarID, "BothTags" ), 0) 421 || (LSTRCPY ( applicationData.grammars [0].ruleName, "trash" ), 0) 422 || (applicationData.grammars [0].is_ve_grammar = ESR_FALSE, 0) 423 || SR_GrammarLoad (applicationData.grammars [0].grammar_path, &applicationData.grammars [applicationData.grammarCount].grammar ) 424 || SR_GrammarSetupVocabulary ( applicationData.grammars [0].grammar, applicationData.vocabulary ) 425 || SR_GrammarSetupRecognizer( applicationData.grammars [0].grammar, applicationData.recognizer ) 426 || SR_GrammarSetDispatchFunction ( applicationData.grammars [0].grammar, L("myDSMCallback"), NULL, myDSMCallback ) 427 || (applicationData.grammarCount++, 0) 428 || SR_RecognizerActivateRule ( applicationData.recognizer, applicationData.grammars [0].grammar, 429 applicationData.grammars [0].ruleName, 1 ) 430 || (applicationData.active_grammar_num = 0, 0) 431 || lhs_audioinStart ( audio_in_handle ) 432 || SR_RecognizerStart ( applicationData.recognizer ) 433 || strl ( applicationData.grammars [0].grammar, &applicationData, audio_in_handle, &recognition_count ) 434 || SR_RecognizerStop ( applicationData.recognizer ) 435 || lhs_audioinStop ( audio_in_handle ) 436 || SR_RecognizerDeactivateRule ( applicationData.recognizer, applicationData.grammars [0].grammar, applicationData.grammars [0].ruleName ) 437 || (applicationData.active_grammar_num = -1, 0) 438 || SR_GrammarDestroy ( applicationData.grammars [0].grammar ) 439 || (applicationData.grammarCount--, 0) 440 || SR_NametagsDestroy ( applicationData.nametags ) 441 || (applicationData.nametags = NULL, 0) 442 || SR_VocabularyDestroy ( applicationData.vocabulary ) 443 || (applicationData.vocabulary = NULL) 444 || SR_RecognizerUnsetup ( applicationData.recognizer) // releases acoustic models 445 || SR_RecognizerDestroy ( applicationData.recognizer ) 446 || (applicationData.recognizer = NULL) 447 || SR_SessionDestroy ( ) 448 || srec_test_shutdown_application_data ( &applicationData ) 449 || lhs_audioinClose ( &audio_in_handle ) 450 || PMemShutdown ( ) 451 } 452 */ 453 454 455 // 456 // PMem native methods 457 // 458 private static native void PMemInit(); 459 private static native void PMemShutdown(); 460 461 462 // 463 // SR_Session native methods 464 // 465 private static native void SR_SessionCreate(String filename); 466 private static native void SR_SessionDestroy(); 467 468 469 // 470 // SR_Recognizer native methods 471 // 472 473 /** 474 * Reserved value. 475 */ 476 public final static int EVENT_INVALID = 0; 477 478 /** 479 * <code>Recognizer</code> could not find a match for the utterance. 480 */ 481 public final static int EVENT_NO_MATCH = 1; 482 483 /** 484 * <code>Recognizer</code> processed one frame of audio. 485 */ 486 public final static int EVENT_INCOMPLETE = 2; 487 488 /** 489 * <code>Recognizer</code> has just been started. 490 */ 491 public final static int EVENT_STARTED = 3; 492 493 /** 494 * <code>Recognizer</code> is stopped. 495 */ 496 public final static int EVENT_STOPPED = 4; 497 498 /** 499 * Beginning of speech detected. 500 */ 501 public final static int EVENT_START_OF_VOICING = 5; 502 503 /** 504 * End of speech detected. 505 */ 506 public final static int EVENT_END_OF_VOICING = 6; 507 508 /** 509 * Beginning of utterance occured too soon. 510 */ 511 public final static int EVENT_SPOKE_TOO_SOON = 7; 512 513 /** 514 * Recognition match detected. 515 */ 516 public final static int EVENT_RECOGNITION_RESULT = 8; 517 518 /** 519 * Timeout occured before beginning of utterance. 520 */ 521 public final static int EVENT_START_OF_UTTERANCE_TIMEOUT = 9; 522 523 /** 524 * Timeout occured before speech recognition could complete. 525 */ 526 public final static int EVENT_RECOGNITION_TIMEOUT = 10; 527 528 /** 529 * Not enough samples to process one frame. 530 */ 531 public final static int EVENT_NEED_MORE_AUDIO = 11; 532 533 /** 534 * More audio encountered than is allowed by 'swirec_max_speech_duration'. 535 */ 536 public final static int EVENT_MAX_SPEECH = 12; 537 538 /** 539 * Produce a displayable string from an <code>advance</code> event. 540 * @param event 541 * @return String representing the event. 542 */ 543 public static String eventToString(int event) { 544 switch (event) { 545 case EVENT_INVALID: 546 return "EVENT_INVALID"; 547 case EVENT_NO_MATCH: 548 return "EVENT_NO_MATCH"; 549 case EVENT_INCOMPLETE: 550 return "EVENT_INCOMPLETE"; 551 case EVENT_STARTED: 552 return "EVENT_STARTED"; 553 case EVENT_STOPPED: 554 return "EVENT_STOPPED"; 555 case EVENT_START_OF_VOICING: 556 return "EVENT_START_OF_VOICING"; 557 case EVENT_END_OF_VOICING: 558 return "EVENT_END_OF_VOICING"; 559 case EVENT_SPOKE_TOO_SOON: 560 return "EVENT_SPOKE_TOO_SOON"; 561 case EVENT_RECOGNITION_RESULT: 562 return "EVENT_RECOGNITION_RESULT"; 563 case EVENT_START_OF_UTTERANCE_TIMEOUT: 564 return "EVENT_START_OF_UTTERANCE_TIMEOUT"; 565 case EVENT_RECOGNITION_TIMEOUT: 566 return "EVENT_RECOGNITION_TIMEOUT"; 567 case EVENT_NEED_MORE_AUDIO: 568 return "EVENT_NEED_MORE_AUDIO"; 569 case EVENT_MAX_SPEECH: 570 return "EVENT_MAX_SPEECH"; 571 } 572 return "EVENT_" + event; 573 } 574 575 private static native void SR_RecognizerStart(int recognizer); 576 private static native void SR_RecognizerStop(int recognizer); 577 private static native int SR_RecognizerCreate(); 578 private static native void SR_RecognizerDestroy(int recognizer); 579 private static native void SR_RecognizerSetup(int recognizer); 580 private static native void SR_RecognizerUnsetup(int recognizer); 581 private static native boolean SR_RecognizerIsSetup(int recognizer); 582 private static native String SR_RecognizerGetParameter(int recognizer, String key); 583 private static native int SR_RecognizerGetSize_tParameter(int recognizer, String key); 584 private static native boolean SR_RecognizerGetBoolParameter(int recognizer, String key); 585 private static native void SR_RecognizerSetParameter(int recognizer, String key, String value); 586 private static native void SR_RecognizerSetSize_tParameter(int recognizer, 587 String key, int value); 588 private static native void SR_RecognizerSetBoolParameter(int recognizer, String key, 589 boolean value); 590 private static native void SR_RecognizerSetupRule(int recognizer, int grammar, 591 String ruleName); 592 private static native boolean SR_RecognizerHasSetupRules(int recognizer); 593 private static native void SR_RecognizerActivateRule(int recognizer, int grammar, 594 String ruleName, int weight); 595 private static native void SR_RecognizerDeactivateRule(int recognizer, int grammar, 596 String ruleName); 597 private static native void SR_RecognizerDeactivateAllRules(int recognizer); 598 private static native boolean SR_RecognizerIsActiveRule(int recognizer, int grammar, 599 String ruleName); 600 private static native boolean SR_RecognizerCheckGrammarConsistency(int recognizer, 601 int grammar); 602 private static native int SR_RecognizerPutAudio(int recognizer, byte[] buffer, int offset, 603 int length, boolean isLast); 604 private static native int SR_RecognizerAdvance(int recognizer); 605 // private static native void SR_RecognizerLoadUtterance(int recognizer, 606 // const LCHAR* filename); 607 // private static native void SR_RecognizerLoadWaveFile(int recognizer, 608 // const LCHAR* filename); 609 // private static native void SR_RecognizerSetLockFunction(int recognizer, 610 // SR_RecognizerLockFunction function, void* data); 611 private static native boolean SR_RecognizerIsSignalClipping(int recognizer); 612 private static native boolean SR_RecognizerIsSignalDCOffset(int recognizer); 613 private static native boolean SR_RecognizerIsSignalNoisy(int recognizer); 614 private static native boolean SR_RecognizerIsSignalTooQuiet(int recognizer); 615 private static native boolean SR_RecognizerIsSignalTooFewSamples(int recognizer); 616 private static native boolean SR_RecognizerIsSignalTooManySamples(int recognizer); 617 // private static native void SR_Recognizer_Change_Sample_Rate (size_t new_sample_rate); 618 619 620 // 621 // SR_Grammar native methods 622 // 623 private static native void SR_GrammarCompile(int grammar); 624 private static native void SR_GrammarAddWordToSlot(int grammar, String slot, 625 String word, String pronunciation, int weight, String tag); 626 private static native void SR_GrammarResetAllSlots(int grammar); 627 // private static native void SR_GrammarAddNametagToSlot(int grammar, String slot, 628 // const struct SR_Nametag_t* nametag, int weight, String tag); 629 private static native void SR_GrammarSetupVocabulary(int grammar, int vocabulary); 630 // private static native void SR_GrammarSetupModels(int grammar, SR_AcousticModels* models); 631 private static native void SR_GrammarSetupRecognizer(int grammar, int recognizer); 632 private static native void SR_GrammarUnsetupRecognizer(int grammar); 633 // private static native void SR_GrammarGetModels(int grammar,SR_AcousticModels** models); 634 private static native int SR_GrammarCreate(); 635 private static native void SR_GrammarDestroy(int grammar); 636 private static native int SR_GrammarLoad(String filename); 637 private static native void SR_GrammarSave(int grammar, String filename); 638 // private static native void SR_GrammarSetDispatchFunction(int grammar, 639 // const LCHAR* name, void* userData, SR_GrammarDispatchFunction function); 640 // private static native void SR_GrammarSetParameter(int grammar, const 641 // LCHAR* key, void* value); 642 // private static native void SR_GrammarSetSize_tParameter(int grammar, 643 // const LCHAR* key, size_t value); 644 // private static native void SR_GrammarGetParameter(int grammar, const 645 // LCHAR* key, void** value); 646 // private static native void SR_GrammarGetSize_tParameter(int grammar, 647 // const LCHAR* key, size_t* value); 648 // private static native void SR_GrammarCheckParse(int grammar, const LCHAR* 649 // transcription, SR_SemanticResult** result, size_t* resultCount); 650 private static native void SR_GrammarAllowOnly(int grammar, String transcription); 651 private static native void SR_GrammarAllowAll(int grammar); 652 653 654 // 655 // SR_Vocabulary native methods 656 // 657 // private static native int SR_VocabularyCreate(); 658 private static native int SR_VocabularyLoad(); 659 // private static native void SR_VocabularySave(SR_Vocabulary* self, 660 // const LCHAR* filename); 661 // private static native void SR_VocabularyAddWord(SR_Vocabulary* self, 662 // const LCHAR* word); 663 // private static native void SR_VocabularyGetLanguage(SR_Vocabulary* self, 664 // ESR_Locale* locale); 665 private static native void SR_VocabularyDestroy(int vocabulary); 666 private static native String SR_VocabularyGetPronunciation(int vocabulary, String word); 667 668 669 // 670 // SR_RecognizerResult native methods 671 // 672 private static native byte[] SR_RecognizerResultGetWaveform(int recognizer); 673 private static native int SR_RecognizerResultGetSize(int recognizer); 674 private static native int SR_RecognizerResultGetKeyCount(int recognizer, int nbest); 675 private static native String[] SR_RecognizerResultGetKeyList(int recognizer, int nbest); 676 private static native String SR_RecognizerResultGetValue(int recognizer, 677 int nbest, String key); 678 // private static native void SR_RecognizerResultGetLocale(int recognizer, ESR_Locale* locale); 679} 680