Page 178 - The Definitive Guide to Building Java Robots
P. 178
Preston_5564C05.fm Page 159 Tuesday, September 20, 2005 5:13 AM
CHAPTER 5 ■ SPEECH 159
if (rule.equals("exit")) {
break;
}
}
sr.stop();
sr.close();
System.out.println("done!");
}
}
Next, I want to use JNI and implement a continuous dictation example. This will not use a
grammar file, but will require you to train the recognizer as to how you dictate words.
Code Objective
The objective here is to perform basic speech recognition to open notepad, and then exit via
JNI using continuous dictation.
Code Discussion
Just like the modification in Example 5-3, I’ll only modify the methods to match our new
package signature. See Example 5-15.
Example 5-15. QuadmoreSR.h and QuadSR.h
JNIEXPORT jstring JNICALL➥
Java_com_scottpreston_javarobot_chapter5_QuadmoreSR_TakeDictation
This class has a static block that calls QuadSR.dll. This DLL must be in the path, so I’ve put
it in the c:\windows\system32 directory. After the static block, I define a single native method
from the C++ project called TakeDictation. This method returns a string that I output to
System.out. See Example 5-16.
Example 5-16. QuadmoreSR.java
package com.scottpreston.javarobot.chapter5;
public class QuadmoreSR {
// this is a DLL in system path QuadSR.dll
static {
System.loadLibrary("QuadSR");
}
// from native class
public native String TakeDictation();