speech
Class GrammarCenterAgent

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--metaglue.AgentAgent
                          |
                          +--agentland.util.GoodAgent
                                |
                                +--agentland.resource.ManagedAgent
                                      |
                                      +--speech.GrammarCenterAgent
All Implemented Interfaces:
Agent, Good, GrammarCenter, Managed, MetagluePrimitives, Remote, Serializable, SpeechStateListener, Spy, TagsListener

public class GrammarCenterAgent
extends ManagedAgent
implements GrammarCenter, TagsListener, SpeechStateListener

This is the center where it listens to the user and farms out stuff to various AppGrammars.

See Also:
ManagedAgent, GrammarCenter, TagsListener, Serialized Form

Inner classes inherited from class metaglue.AgentAgent
AgentAgent.Attribute
 
Field Summary
 boolean divertToTypeWriter
           
 TypeWriter tw
           
 
Fields inherited from class agentland.resource.ManagedAgent
rm, society
 
Fields inherited from class agentland.util.GoodAgent
alert, notifier
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface metaglue.Agent
ALIVE, DIED, NO_METAGLUE, NOT_RUNNING, STARTING
 
Constructor Summary
GrammarCenterAgent()
          Our lovely constructor.
 
Method Summary
 void activate(String grammarName)
          Activate a grammar, so that any public rule in the grammar can be spoken.
 void activate(String grammarName, String ruleName)
          Activate a specific rule in a grammar so that it can be spoken
 void addAlternative(String grammarName, String ruleName, String spokenText)
          This adds an alternative to some rule.
 void addAlternativeRule(String grammarName, String ruleName, String ruleNameToAdd)
          Add an alternative rule to the given rule.
 void addAlternatives(String grammarName, String ruleName, Collection spokenText)
          This does the same as the single case, but for a vector of alternatives.
 void addDictationListener()
          Registers a listener for dictation events.
 void addNewRuleAlternatives(String grammarName, String ruleName)
          Adds a new rule to the given grammar as a RuleAlternative.
 void deactivate(String grammarName)
          Deactivate all the rules in a grammar
 void deactivate(String grammarName, String ruleName)
          Deactivate a specific rule in a grammar.
protected  boolean ensureStartupNeeds()
          This a separeate so that we can override it.
 Vector getActiveGrammars()
          Gets all the active grammars.
 Vector getActiveRules(String sGrammarName)
          Gets all the rules in a grammar that are set active.
 String getDictation()
          Sets the speech system to dictation mode, where it listens for a single sentence of speech from the user.
 String getFile(String grammarName)
          Gets the String name of the file of this grammar.
 String getGrammar(String sGrammarName, AgentID whocares)
          Gets the grammar specified in sGrammarName, and returns the String name of the grammar.
 Vector getPublicRules(String sGrammarName)
          Gets all the rules in the grammar that are marked public.
 String getRandomSentence(String sGrammarName)
          Randomly picks a public rule from a given grammar, and randomly generates a sentence based on that rule.
 String getRandomSentence(String sGrammarName, boolean bPublicRulesOnly)
          If bPublicRulesOnly is true, randomly picks a public rule from a given grammar, and randomly generates a sentence based on that rule.
 String getRandomSentence(String sGrammarName, String sRuleName)
          Gets a random sentence based on a rule in a given grammar.
 boolean hasRule(String grammarName, String ruleName)
          Determines whether the given grammar has the given rule.
 boolean isEnabled(String grammarName)
          Gets whether or not this grammar is enabled.
 Enumeration listRuleNames(String grammarName)
          Lists the names of the rules of a given grammar.
 void nap(int ms)
          Take a short nap--to let the dictation voice play.
 void pauseRecognizer()
          Pause ViaVoice's recognizer.
 void playWav(String wavFile, boolean sync)
          Speech out playing files.
 void printRules(String grammarName)
          Prints out the rules in a specified grammar to standard output
 String processString(String text)
          Tries to match a String text with one of Listen's RuleGrammars.
 void releaseGrammar(String gname, AgentID whocares)
          Let an owner of a grammar release it.
 void requestWakeUp()
          Requests that the speech system start listening for public rules.
 void requestWakeUp(boolean playattention)
          Requests that the speech system start listening for public rules.
 void resultAccepted(String who, Hashtable tags)
          This is what is called by my application grammar.
 void resumeRecognizer()
          Resumes ViaVoice's recognizer.
 void save(String grammarName)
          Calls the save method on the underlying ApplicationGrammar
 void say(String text, boolean sync)
          Speak the given sentence using a speech synthesizer.
 String sayRandomSentence(String sGrammarName)
          Picks a random public rule from a given grammar, and says a random sentence from that rule.
 void setAlternatives(String grammarName, String ruleName, Collection spokenText)
          Sets the alternatives of a given rule.
 void setDictionFromTypeWriter(boolean b)
           
 void setTypeWriter(String agentID)
           
 boolean sleeping()
           
 void stateChanged(int iState)
          Called when the speech system wakes up or goes to sleep.
 void tellHeard(String s)
          Sends a message through the notifier about what was spoken.
 void volumeOverThresh(float fVolume, float fThresh)
          Not used right now.
 void volumeUnderThresh(float fVolume, float fThresh)
          Not used right now.
 
Methods inherited from class agentland.resource.ManagedAgent
connect, getAlert, getNeed, isAvailable, isAvailable, reliesOn, reliesOn, replace, replace, request, request, request, requestAgent, requestAgent, resources, resourcesByAgentID, setNeed, tiedTo, yank, yank, yank
 
Methods inherited from class agentland.util.GoodAgent
addSpy, addSpy, alert, alertString, beep, error, getHistory, getHistoryElement, getPersistentMap, log, notify, removeSpy, removeSpy, resetHistory, safeRely, safeRely, safeRely, setNiceLogName, tell
 
Methods inherited from class metaglue.AgentAgent
addMonitor, alive, buildEHAFor, defrost, defrostAll, defrostBoolean, defrostInt, defrostString, fixAttribute, fixAttribute, freeze, freeze, freeze, freezeAll, freezeVar, getAgentID, getAttribute, getCatalog, getCatalogID, getDesignation, getFrozenVariables, getLogLevel, getMetaglueAgent, getMetaglueAgentID, getOccupation, getOldLogs, getProperties, getProxyHandlerClass, getSociety, installAPH, log, log, lookupClass, reliesOn, reliesOnSynch, removeAPHFromCatalog, removeFrozen, setFreezeName, setLogLevel, setLogName, shutdown, startAgent, startAgentOn, startAgentOn, startup, status, tiedTo, tiedTo, tiedTo, tiedTo, tieToDesignation, toString, whereAreYou
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface agentland.resource.Managed
getNeed, replace, replace, resources, yank, yank
 
Methods inherited from interface agentland.util.Good
getHistory, getHistoryElement, resetHistory
 
Methods inherited from interface metaglue.Agent
addMonitor, alive, getAgentID, getMetaglueAgentID, getOldLogs, shutdown, startup, whereAreYou
 
Methods inherited from interface agentland.util.Spy
tell
 

Field Detail

tw

public TypeWriter tw

divertToTypeWriter

public boolean divertToTypeWriter
Constructor Detail

GrammarCenterAgent

public GrammarCenterAgent()
                   throws RemoteException
Our lovely constructor. Build tables, and rely on SpeechOut which could rely on us in turn later on if it barfs.
Method Detail

ensureStartupNeeds

protected boolean ensureStartupNeeds()
This a separeate so that we can override it.
Returns:
a boolean value which is true if all needs were satisfied, false otherwise

nap

public void nap(int ms)
Take a short nap--to let the dictation voice play.

getDictation

public String getDictation()
Sets the speech system to dictation mode, where it listens for a single sentence of speech from the user. The spoken sentence can contain any word that Viavoice knows about (does not have to be in a RuleGrammar).
Specified by:
getDictation in interface GrammarCenter
Returns:
a String value

playWav

public void playWav(String wavFile,
                    boolean sync)
Speech out playing files.
Specified by:
playWav in interface GrammarCenter
Parameters:
wavFile - a String value
sync - block until call completed.

say

public void say(String text,
                boolean sync)
Speak the given sentence using a speech synthesizer.
Specified by:
say in interface GrammarCenter
Parameters:
text - a String value
sync - a boolean value

pauseRecognizer

public void pauseRecognizer()
Pause ViaVoice's recognizer.
Specified by:
pauseRecognizer in interface GrammarCenter

resumeRecognizer

public void resumeRecognizer()
Resumes ViaVoice's recognizer.
Specified by:
resumeRecognizer in interface GrammarCenter

requestWakeUp

public void requestWakeUp()
Requests that the speech system start listening for public rules.
Specified by:
requestWakeUp in interface GrammarCenter

requestWakeUp

public void requestWakeUp(boolean playattention)
Requests that the speech system start listening for public rules.
Specified by:
requestWakeUp in interface GrammarCenter
Parameters:
playattention - a boolean value

processString

public String processString(String text)
Tries to match a String text with one of Listen's RuleGrammars. This method essentially "pretends" that the given text was spoken by a person.
Specified by:
processString in interface GrammarCenter
Parameters:
text - a String value
Returns:
a String value

setDictionFromTypeWriter

public void setDictionFromTypeWriter(boolean b)
Specified by:
setDictionFromTypeWriter in interface GrammarCenter

setTypeWriter

public void setTypeWriter(String agentID)
Specified by:
setTypeWriter in interface GrammarCenter

getGrammar

public String getGrammar(String sGrammarName,
                         AgentID whocares)
Gets the grammar specified in sGrammarName, and returns the String name of the grammar.
Specified by:
getGrammar in interface GrammarCenter
Parameters:
sGrammarName - a String value
whocares - an AgentID value
Returns:
a String value

releaseGrammar

public void releaseGrammar(String gname,
                           AgentID whocares)
Let an owner of a grammar release it. Grammar will be trashed if no one else owns it.
Specified by:
releaseGrammar in interface GrammarCenter
Parameters:
gname - a String value
whocares - an AgentID value

tellHeard

public void tellHeard(String s)
Sends a message through the notifier about what was spoken.
Parameters:
s - a String value

resultAccepted

public void resultAccepted(String who,
                           Hashtable tags)
This is what is called by my application grammar.
Specified by:
resultAccepted in interface TagsListener
Parameters:
who - a String value
tags - a Hashtable value

listRuleNames

public Enumeration listRuleNames(String grammarName)
Lists the names of the rules of a given grammar.
Specified by:
listRuleNames in interface GrammarCenter
Parameters:
grammarName - a String value
Returns:
an Enumeration value

addAlternative

public void addAlternative(String grammarName,
                           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
Specified by:
addAlternative in interface GrammarCenter
Parameters:
grammarName - a String value
ruleName - a String value
spokenText - a String value

addAlternatives

public void addAlternatives(String grammarName,
                            String ruleName,
                            Collection spokenText)
This does the same as the single case, but for a vector of alternatives. More efficient.
Specified by:
addAlternatives in interface GrammarCenter
Parameters:
grammarName - a String value
ruleName - a String value
spokenText - a Collection value
See Also:
addAlternative(String,String,String)

save

public void save(String grammarName)
Calls the save method on the underlying ApplicationGrammar
Specified by:
save in interface GrammarCenter
Parameters:
grammarName - a String value
See Also:
ApplicationGrammar

activate

public void activate(String grammarName)
Activate a grammar, so that any public rule in the grammar can be spoken.
Specified by:
activate in interface GrammarCenter
Parameters:
grammarName - a String value

activate

public void activate(String grammarName,
                     String ruleName)
Activate a specific rule in a grammar so that it can be spoken
Specified by:
activate in interface GrammarCenter
Parameters:
grammarName - a String value
ruleName - a String value

deactivate

public void deactivate(String grammarName)
Deactivate all the rules in a grammar
Specified by:
deactivate in interface GrammarCenter
Parameters:
grammarName - a String value

deactivate

public void deactivate(String grammarName,
                       String ruleName)
Deactivate a specific rule in a grammar.
Specified by:
deactivate in interface GrammarCenter
Parameters:
grammarName - a String value
ruleName - a String value

getPublicRules

public Vector getPublicRules(String sGrammarName)
Gets all the rules in the grammar that are marked public.
Specified by:
getPublicRules in interface GrammarCenter
Parameters:
sGrammarName - a String value
Returns:
a Vector value

getActiveGrammars

public Vector getActiveGrammars()
Gets all the active grammars.
Specified by:
getActiveGrammars in interface GrammarCenter
Returns:
a Vector value

getActiveRules

public Vector getActiveRules(String sGrammarName)
Gets all the rules in a grammar that are set active.
Specified by:
getActiveRules in interface GrammarCenter
Parameters:
sGrammarName - a String value
Returns:
a Vector value

getFile

public String getFile(String grammarName)
Gets the String name of the file of this grammar.
Specified by:
getFile in interface GrammarCenter
Parameters:
grammarName - a String value
Returns:
a String value

isEnabled

public boolean isEnabled(String grammarName)
Gets whether or not this grammar is enabled.
Specified by:
isEnabled in interface GrammarCenter
Parameters:
grammarName - a String value
Returns:
a boolean value

addAlternativeRule

public void addAlternativeRule(String grammarName,
                               String ruleName,
                               String ruleNameToAdd)
Add an alternative rule to the given rule.
Specified by:
addAlternativeRule in interface GrammarCenter
Parameters:
grammarName - a String value
ruleName - a String value
ruleNameToAdd - a String value

setAlternatives

public void setAlternatives(String grammarName,
                            String ruleName,
                            Collection spokenText)
Sets the alternatives of a given rule.
Specified by:
setAlternatives in interface GrammarCenter
Parameters:
grammarName - a String value
ruleName - a String value
spokenText - a Collection value

addNewRuleAlternatives

public void addNewRuleAlternatives(String grammarName,
                                   String ruleName)
Adds a new rule to the given grammar as a RuleAlternative.
Specified by:
addNewRuleAlternatives in interface GrammarCenter
Parameters:
grammarName - a String value
ruleName - a String value

hasRule

public boolean hasRule(String grammarName,
                       String ruleName)
Determines whether the given grammar has the given rule.
Specified by:
hasRule in interface GrammarCenter
Parameters:
grammarName - a String value
ruleName - a String value
Returns:
a boolean value

printRules

public void printRules(String grammarName)
Prints out the rules in a specified grammar to standard output
Specified by:
printRules in interface GrammarCenter
Parameters:
grammarName - the name of the grammar

addDictationListener

public void addDictationListener()
Registers a listener for dictation events. The listener will send notifications when dictation results are received.
Specified by:
addDictationListener in interface GrammarCenter
Following copied from interface: speech.GrammarCenter
Throws:
RemoteException - if an error occurs

getRandomSentence

public String getRandomSentence(String sGrammarName,
                                String sRuleName)
Gets a random sentence based on a rule in a given grammar. If the grammar is not already loaded into GrammarCenter, then it will be added as a new ApplicationGrammar
Specified by:
getRandomSentence in interface GrammarCenter
Parameters:
sGrammarName - a String value
sRuleName - a String value
Returns:
a String value

sayRandomSentence

public String sayRandomSentence(String sGrammarName)
Picks a random public rule from a given grammar, and says a random sentence from that rule.
Specified by:
sayRandomSentence in interface GrammarCenter
Parameters:
sGrammarName - a String value
Returns:
a String value
See Also:
getRandomSentence(String)

getRandomSentence

public String getRandomSentence(String sGrammarName)
Randomly picks a public rule from a given grammar, and randomly generates a sentence based on that rule.
Specified by:
getRandomSentence in interface GrammarCenter
Parameters:
sGrammarName - a String value
Returns:
a String value
See Also:
getRandomSentence(String,boolean)

getRandomSentence

public String getRandomSentence(String sGrammarName,
                                boolean bPublicRulesOnly)
If bPublicRulesOnly is true, randomly picks a public rule from a given grammar, and randomly generates a sentence based on that rule. Otherwise, randomly picks from any rule in a grammar.
Specified by:
getRandomSentence in interface GrammarCenter
Parameters:
sGrammarName - a String value
bPublicRulesOnly - a boolean value
Returns:
a String value

sleeping

public boolean sleeping()
Specified by:
sleeping in interface GrammarCenter

stateChanged

public void stateChanged(int iState)
Description copied from interface: SpeechStateListener
Called when the speech system wakes up or goes to sleep. The int values can be found in Listen, but I believe they are AWAKE, ASLEEP.
Specified by:
stateChanged in interface SpeechStateListener
Following copied from interface: speech.tools.SpeechStateListener
Parameters:
iState - an int value

volumeOverThresh

public void volumeOverThresh(float fVolume,
                             float fThresh)
Description copied from interface: SpeechStateListener
Not used right now.
Specified by:
volumeOverThresh in interface SpeechStateListener

volumeUnderThresh

public void volumeUnderThresh(float fVolume,
                              float fThresh)
Description copied from interface: SpeechStateListener
Not used right now.
Specified by:
volumeUnderThresh in interface SpeechStateListener