Added uncommited files
Former-commit-id: 3154adfa7fa5dee9976723e51a37793419d29b0a
This commit is contained in:
parent
53da641909
commit
36d0826a33
3 changed files with 225 additions and 0 deletions
155
src/se/koc/hal/HALClient.java
Normal file
155
src/se/koc/hal/HALClient.java
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
package se.koc.hal;
|
||||
|
||||
import se.koc.hal.bot.AliceBot;
|
||||
import se.koc.hal.intf.HalBot;
|
||||
import se.koc.hal.intf.HalTextToSpeach;
|
||||
import se.koc.hal.plugin.tellstick.TellstickChangeListener;
|
||||
import se.koc.hal.plugin.tellstick.TellstickProtocol;
|
||||
import se.koc.hal.plugin.tellstick.TellstickSerialComm;
|
||||
import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
|
||||
import se.koc.hal.struct.Switch;
|
||||
import se.koc.hal.stt.GoogleSTTClient;
|
||||
import se.koc.hal.intf.HalSpeachToText;
|
||||
import se.koc.hal.stt.ManualSTTClient;
|
||||
import se.koc.hal.stt.Sphinx4STTClient;
|
||||
import se.koc.hal.tts.MaryRemoteTTSClient;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: ezivkoc
|
||||
* Date: 2013-12-17
|
||||
* Time: 10:59
|
||||
*/
|
||||
public class HALClient{
|
||||
private static HashMap<String, Switch> switches = new HashMap<String, Switch>();
|
||||
|
||||
|
||||
public static void main(String[] args){
|
||||
System.setProperty("org.apache.commons.logging.log", "org.apache.commons.logging.impl.NoOpLog");
|
||||
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
|
||||
|
||||
/********************************************************************/
|
||||
System.out.println("Initializing STT...");
|
||||
HalSpeachToText stt =
|
||||
new ManualSTTClient();
|
||||
// new GoogleSTTClient();
|
||||
// new Sphinx4STTClient();
|
||||
stt.initSTT();
|
||||
|
||||
/********************************************************************/
|
||||
System.out.println("Initializing TTS...");
|
||||
|
||||
final HalTextToSpeach tts =
|
||||
// new JarvisTTSClient();
|
||||
new MaryRemoteTTSClient();
|
||||
// new MaryLocalTTSClient();
|
||||
tts.initTTS();
|
||||
|
||||
/********************************************************************/
|
||||
System.out.println("Initializing BOT...");
|
||||
HalBot bot = new AliceBot();
|
||||
bot.initialize();
|
||||
|
||||
/********************************************************************/
|
||||
NexaSelfLearning nexa1 = new NexaSelfLearning();
|
||||
nexa1.setHouse(15087918);
|
||||
nexa1.setUnit(0);
|
||||
switches.put("livingroom", new Switch("livingroom", nexa1));
|
||||
|
||||
NexaSelfLearning nexa2 = new NexaSelfLearning();
|
||||
nexa2.setHouse(15087918);
|
||||
nexa2.setUnit(1);
|
||||
switches.put("bedroom", new Switch("bedroom", nexa2));
|
||||
|
||||
NexaSelfLearning nexa3 = new NexaSelfLearning();
|
||||
nexa3.setHouse(15087918);
|
||||
nexa3.setUnit(3);
|
||||
switches.put("kitchen", new Switch("kitchen", nexa3));
|
||||
|
||||
TellstickSerialComm.getInstance().setListener(new TellstickChangeListener() {
|
||||
@Override
|
||||
public void stateChange(TellstickProtocol protocol) {
|
||||
for(Switch s : switches.values()) {
|
||||
if(s.equals(protocol)) {
|
||||
String response = s.getName()+" window is "+(((NexaSelfLearning)protocol).isEnabled() ? "open": "closed");
|
||||
System.out.println(">>> " + response);
|
||||
tts.speak(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
System.out.println("Listening...");
|
||||
while(true){
|
||||
// Listen to input
|
||||
System.out.print("<<< ");
|
||||
String request = stt.listen();
|
||||
System.out.println(request);
|
||||
|
||||
String response = doActions(request);
|
||||
|
||||
if(response == null) {
|
||||
// Bot answer
|
||||
response = bot.respond(request);
|
||||
}
|
||||
System.out.println(">>> " + response);
|
||||
|
||||
// Cleanup response and Speak
|
||||
response = response.replaceAll("\\<.*?>","");
|
||||
tts.speak(response);
|
||||
}
|
||||
}
|
||||
|
||||
private static Pattern pattern_isOn = Pattern.compile("\\bis (\\w*)\\b.*(on|off)");
|
||||
private static Pattern pattern_turnOn = Pattern.compile("\\bturn on (\\w*)\\b");
|
||||
private static Pattern pattern_turnOff = Pattern.compile("\\bturn off (\\w*)\\b");
|
||||
private static String doActions(String request) {
|
||||
if(request == null)
|
||||
return null;
|
||||
Matcher m = pattern_isOn.matcher(request);
|
||||
if(m.find()){
|
||||
String name = m.group(1);
|
||||
if(switches.containsKey(name))
|
||||
return "It is " + (switches.get(name).isOn() ? "on" : "off");
|
||||
}
|
||||
|
||||
m = pattern_turnOn.matcher(request);
|
||||
if(m.find()){
|
||||
String name = m.group(1);
|
||||
if(name.equals("all")){
|
||||
for(Switch s : switches.values())
|
||||
s.turnOn();
|
||||
return "I've turned everything on for you";
|
||||
}
|
||||
else if(switches.containsKey(name)) {
|
||||
switches.get(name).turnOn();
|
||||
return "Turned "+name+" on";
|
||||
}
|
||||
}
|
||||
|
||||
m = pattern_turnOff.matcher(request);
|
||||
if(m.find()){
|
||||
String name = m.group(1);
|
||||
if(name.equals("all")){
|
||||
for(Switch s : switches.values())
|
||||
s.turnOff();
|
||||
return "I turned everything off";
|
||||
}
|
||||
else if(switches.containsKey(name)) {
|
||||
switches.get(name).turnOff();
|
||||
return "I switched "+name+" off";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
35
src/se/koc/hal/intf/HalSpeachToText.java
Normal file
35
src/se/koc/hal/intf/HalSpeachToText.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2013 ezivkoc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.koc.hal.intf;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: ezivkoc
|
||||
* Date: 2013-12-17
|
||||
* Time: 13:40
|
||||
*/
|
||||
public interface HalSpeachToText {
|
||||
public void initSTT();
|
||||
|
||||
public String listen();
|
||||
}
|
||||
35
src/se/koc/hal/intf/HalTextToSpeach.java
Normal file
35
src/se/koc/hal/intf/HalTextToSpeach.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2013 ezivkoc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.koc.hal.intf;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: ezivkoc
|
||||
* Date: 2013-12-17
|
||||
* Time: 13:40
|
||||
*/
|
||||
public interface HalTextToSpeach {
|
||||
public void initTTS();
|
||||
|
||||
public void speak(String msg);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue