speech
Class ApplicationGrammar

java.lang.Object
  |
  +--speech.ApplicationGrammar

public class ApplicationGrammar
extends Object

This is a simplified interface to the rule and dictation grammars in the Java Speech API (JSAPI beta v0.7). This interface provides all the basic functionality of the JSAPI RuleGrammar class but omits for the time being anything esoteric. It also adds several very useful things, such as a save() method, TagsListeners and synchronous getDictation() and saySync() methods. It is also thread-safe. For more information on the Java Speech Grammar Format (JSGF) specification, in which you actually write your grammars, see: http://java.sun.com/products/java-media/speech/forDevelopers/JSGF If you want to use speech recognition from Metaglue, don't use this class directly. Use the AppGrammarAgent instead, which is an agentified interface to this class. Notes: In the ApplicationGrammar model, every grammar has its own thread, so that it can't monopolize control over the recognizer's (& AWT's) event thread. People using this class don't need to be concerned with this, except to note that until you are done processing a given result in your grammar, you can't receive new ones. But, the all-important point is that other ApplicationGrammars can receive their speech events while you are still processing yours. Simply put, don't worry, everything will work the way you (should) expect it to! Sample calls: ApplicationGrammar g = new ApplicationGrammar ("package.grammarName"); g.setEnabled(boolean value); g.addResultListener(Listener myListener); g.addTagsListener(TagsListener myTagsListener); g.removeGrammarListener(Listener myListener); g.activate(); g.deactive(); g.activate(String ruleName); g.deactive(String ruleName); g.addAlternative(String ruleName, String spokenText); g.save(); String spokenText = g.getDictation(); // The following should not be used if you want to be RMI-friendly // (see note below) g.addTagsListener(String tag, TagsListener myTagsListener);


Constructor Summary
ApplicationGrammar(String packageList)
          Create an ApplicationGrammar, e.g.
 
Method Summary
 void activate()
           
 void activate(String ruleName)
           
 void addAlternative(String ruleName, String spokenText)
          This adds an alternative to some rule.
 void addAlternativeRule(String ruleName, String ruleNameToAdd)
          Adds the rule rulenameToAdd as an alternative in rule ruleName
 void addAlternatives(String ruleName, Vector spokenText)
          This does the same as the single case, but for a vector of alternatives.
 void addNewRuleAlternatives(String ruleName)
          Creates a public RuleAlternatives type rule called ruleName
 void addTagsListener(String tag, TagsListener suppliedListener)
          This is not useful if you want to access this via RMI (which is how Metaglue does it), because there's no easy way to do a generalized callback like this.
 void addTagsListener(TagsListener suppliedListener)
           
 void deactivate()
           
 void deactivate(String ruleName)
           
 Vector getActiveRules()
           
 String getFile()
           
 String getName()
           
 Vector getPublicRules()
           
 boolean hasRule(String ruleName)
          Returns true if the grammar contains a rule called ruleName
 boolean isBad()
          Get the value of bad (i.e.
 boolean isEnabled()
           
 Enumeration listRuleNames()
           
 void manualTrigger(javax.speech.recognition.RuleParse rp, String text)
           
 void pauseRecognizer()
           
 void printRules()
           
 String processString(String s)
           
 void removeTagsListener(String tag, TagsListener suppliedListener)
           
 void removeTagsListener(TagsListener suppliedListener)
           
 void requestWakeUp()
           
 void requestWakeUp(boolean playattention)
           
 void resumeRecognizer()
           
 void save()
           
 void setAlternatives(String ruleName, Vector spokenText)
          Sets the alternatives for ruleName.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ApplicationGrammar

public ApplicationGrammar(String packageList)
Create an ApplicationGrammar, e.g. new ApplicationGrammar("agentland.device.speechin.VCR"); Implementation detail: Because the constructor call recognizer.loadJCFG(URL, string) allows automatic loading of imported grammars, JSAPI semantics requires that they must all be found in the same directory hierarchy. (I.e, the same top level directory in the class path). In the code below, you might wonder why we don't just create the recognizer statically once in this class, rather than always check for it. This has to do with the way the Java class loader initializes static constructors. Java is not at fault here, but we need to be careful to avoid the unfortunate interactions this can sometimes cause, for example, when you use the reflection API.
Method Detail

isBad

public boolean isBad()
Get the value of bad (i.e. if grammar is dead.)
Returns:
Value of bad.

listRuleNames

public Enumeration listRuleNames()

printRules

public void printRules()

addAlternative

public void addAlternative(String ruleName,
                           String spokenText)
This adds an alternative to some rule. So if you had a rule mapping to pig | dog, you could add cat so it would map to pig | dog | cat

addAlternatives

public void addAlternatives(String ruleName,
                            Vector spokenText)
This does the same as the single case, but for a vector of alternatives. More efficient.

pauseRecognizer

public void pauseRecognizer()

resumeRecognizer

public void resumeRecognizer()

save

public void save()

toString

public String toString()
Overrides:
toString in class Object

addTagsListener

public void addTagsListener(TagsListener suppliedListener)

addTagsListener

public void addTagsListener(String tag,
                            TagsListener suppliedListener)
This is not useful if you want to access this via RMI (which is how Metaglue does it), because there's no easy way to do a generalized callback like this.

removeTagsListener

public void removeTagsListener(String tag,
                               TagsListener suppliedListener)

removeTagsListener

public void removeTagsListener(TagsListener suppliedListener)

activate

public void activate()

activate

public void activate(String ruleName)

deactivate

public void deactivate()

deactivate

public void deactivate(String ruleName)

getPublicRules

public Vector getPublicRules()

getActiveRules

public Vector getActiveRules()

getName

public String getName()

getFile

public String getFile()

requestWakeUp

public void requestWakeUp()

requestWakeUp

public void requestWakeUp(boolean playattention)

processString

public String processString(String s)

manualTrigger

public void manualTrigger(javax.speech.recognition.RuleParse rp,
                          String text)

isEnabled

public boolean isEnabled()

addAlternativeRule

public void addAlternativeRule(String ruleName,
                               String ruleNameToAdd)
Adds the rule rulenameToAdd as an alternative in rule ruleName

setAlternatives

public void setAlternatives(String ruleName,
                            Vector spokenText)
Sets the alternatives for ruleName. Any alternatives that were already there are deleted.

addNewRuleAlternatives

public void addNewRuleAlternatives(String ruleName)
Creates a public RuleAlternatives type rule called ruleName

hasRule

public boolean hasRule(String ruleName)
Returns true if the grammar contains a rule called ruleName