S p e a k X 1 0 |
J e s s e P e t e r s o n |
SpeakX10 has the following command line usage.
java SpeakX10 [-port serial_port] [-voice voice]
Where:
Example
-port serial_port serial_port is the name of the serial port for the CM11A interface. On Windows, "COM1" or "COM2" for example. -voice voice voice is the mode name used to choose a particular mode of JSAPI synthesizer. When using the Java Speech API for Microsoft SAPI, provided by Jesse Peterson at http://www.jpeterson.com, the value could be 'Mary' or 'Mike' to choose either a female or male voice.
To monitor X10 events using the JSAPI for SAPI toolkit's male voice called 'Mike', the following command would be executed.
java SpeakX10 -voice MikeCode
The source code for SpeakX10.java can be found in the samples/SpeakX10 directory.
Within the main method of SpeakX10.java, the optional serial port parameter is read. The optional synthesizer mode name is also read. If a port is identified, the port is passed to the SpeakX10 constructor, otherwise the empty SpeakX10 constructor is called. Once the constructor returns, the monitor method of SpeakX10 is called.
The empty parameter constructor for SpeakX10 just calls the SpeakX10 constructor that takes a String representation of the serial port with the port set to the String "COM2". The SpeakX10 constructor with the port parameter allocates a new CM11A object. It then sets the serial port name. Next, the JSAPI synthesizer is created. If a mode name is provided, the JSAPI SynthesizerModeDesc object with the mode name is created. An EngineList is created based on the mode name. The first element in the list is used as the mode descriptor. The synthesizer is then created. If no mode name is provided, the default synthesizer is created. The synthesizer is then allocated. Now, the SpeakX10 object registeres itself with the CM11A object as an AddressListener and a FunctionListener. The CM11A object is allocated with a call to allocate.
The monitor method waits indefinitely for the CM11A to become deallocated. Currently this will never happen. To end SpeakX10, just kill the program with a Control-C key combination on Windows. A more elegant termination method could be added.
Since SpeakX10 implements both AddressListener and FunctionListener, it must provide the required methods. AddressListener requires a method named address. When address is called, it indicates that an X10 Address event has occurred. The synthesizer's speakPlainText is called with the particulars about the event, resulting in the text being spoken. FunctionListener requires methods for each type of function event. Each of these methods also calls the synthesizer's speakPlainText with the event particulars, resulting in the text being spoken.