1 //Create a class for speech synthesis
2 package SpeechSynthesis
3 import SmartThing.SmartThing
5 public class SpeechSynthesis extends SmartThing {
6 // id, label, and display name of the device
7 StringBuilder id = new StringBuilder()
8 StringBuilder label = new StringBuilder()
9 StringBuilder displayName = new StringBuilder()
10 // Features with numberical values
11 MutableInteger currentLevel = new MutableInteger()
12 // Maps from features to values
13 HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
15 SpeechSynthesis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel) {
16 deviceIntValuesMap = deviceIntValueSmartThing
18 labelSmartThing = label
19 displayNameSmartThing = displayName
20 sendEventSmartThings = sendEvent
25 this.displayName = displayName
26 this.currentLevel = currentLevel
28 deviceIntValuesMap.put("level", currentLevel)
31 // Methods to set values
32 def setLevel(int newValue) {
33 if (!currentLevel.getValue().equals(newValue)) {
34 String tmpID = id.toString()
35 currentLevel.setValue(newValue)
36 println("The level of speech synthesis with id:$tmpID is changed to $currentLevel")
40 def speak(String message) {
41 String tmpID = id.toString()
42 println("Speech synthesis with id:$tmpID, SPEAKING:\"$message\"!")
45 // Methods to return values
46 def getCurrentLevel() {
47 return currentLevel.getValue()