Removed "koc" from package names
Former-commit-id: 93e426a87e8a82a83783d68cf7a814c88df375aa
This commit is contained in:
parent
1ab72ffbc3
commit
5b2dffeb43
56 changed files with 2289 additions and 2313 deletions
10
build.xml
Normal file → Executable file
10
build.xml
Normal file → Executable file
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
|
|
||||||
<target name="run-local-sensor" depends="">
|
<target name="run-local-sensor" depends="">
|
||||||
<java fork="true" failonerror="true" classname="se.koc.hal.plugin.localsensor.ImpulseTracker">
|
<java fork="true" failonerror="true" classname="se.hal.plugin.localsensor.ImpulseTracker">
|
||||||
<classpath>
|
<classpath>
|
||||||
<pathelement path="${buildDir}/hal.jar"/> <!--wildcard may not be platform independent, ok?-->
|
<pathelement path="${buildDir}/hal.jar"/> <!--wildcard may not be platform independent, ok?-->
|
||||||
<pathelement path="${libDir}/*"/> <!--wildcard may not be platform independent, ok?-->
|
<pathelement path="${libDir}/*"/> <!--wildcard may not be platform independent, ok?-->
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="run-remote-sensor" depends="">
|
<target name="run-remote-sensor" depends="">
|
||||||
<java fork="true" failonerror="true" classname="se.koc.hal.plugin.tellstick.TelstickSerialCommTest">
|
<java fork="true" failonerror="true" classname="se.hal.plugin.tellstick.TelstickSerialCommTest">
|
||||||
<classpath>
|
<classpath>
|
||||||
<pathelement path="${buildDir}/hal.jar"/> <!--wildcard may not be platform independent, ok?-->
|
<pathelement path="${buildDir}/hal.jar"/> <!--wildcard may not be platform independent, ok?-->
|
||||||
<pathelement path="${libDir}/*"/> <!--wildcard may not be platform independent, ok?-->
|
<pathelement path="${libDir}/*"/> <!--wildcard may not be platform independent, ok?-->
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="run-main-server" depends="">
|
<target name="run-main-server" depends="">
|
||||||
<java fork="true" failonerror="true" classname="se.koc.hal.PowerChallenge">
|
<java fork="true" failonerror="true" classname="se.hal.PowerChallenge">
|
||||||
<classpath>
|
<classpath>
|
||||||
<pathelement path="${buildDir}/hal.jar"/> <!--wildcard may not be platform independent, ok?-->
|
<pathelement path="${buildDir}/hal.jar"/> <!--wildcard may not be platform independent, ok?-->
|
||||||
<pathelement path="${libDir}/*"/> <!--wildcard may not be platform independent, ok?-->
|
<pathelement path="${libDir}/*"/> <!--wildcard may not be platform independent, ok?-->
|
||||||
|
|
@ -70,12 +70,12 @@
|
||||||
<mkdir dir="${buildDir}" />
|
<mkdir dir="${buildDir}" />
|
||||||
<javac srcdir="${srcDir}" destdir="${buildDir}" fork="yes">
|
<javac srcdir="${srcDir}" destdir="${buildDir}" fork="yes">
|
||||||
<include name="**/*.java" />
|
<include name="**/*.java" />
|
||||||
<exclude name="se/koc/hal/tts/GoogleTTSClient.java" />
|
<exclude name="se/hal/tts/GoogleTTSClient.java" />
|
||||||
<classpath refid="classpath.build" />
|
<classpath refid="classpath.build" />
|
||||||
</javac>
|
</javac>
|
||||||
<javac srcdir="${testDir}" destdir="${buildDir}" fork="yes">
|
<javac srcdir="${testDir}" destdir="${buildDir}" fork="yes">
|
||||||
<include name="**/*.java" />
|
<include name="**/*.java" />
|
||||||
<exclude name="se/koc/hal/test/JarvisSyntersizerTest.java" />
|
<exclude name="se/hal/test/JarvisSyntersizerTest.java" />
|
||||||
<classpath refid="classpath.build" />
|
<classpath refid="classpath.build" />
|
||||||
</javac>
|
</javac>
|
||||||
<jar destfile="${buildDir}/hal.jar" basedir="${buildDir}" excludes="hal.jar" />
|
<jar destfile="${buildDir}/hal.jar" basedir="${buildDir}" excludes="hal.jar" />
|
||||||
|
|
|
||||||
2
run.sh
2
run.sh
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#screen -S hal -L -d -m \
|
#screen -S hal -L -d -m \
|
||||||
# java -cp sqlite-jdbc-3.7.2.jar:jSerialComm-1.3.4.jar:hal.jar:. se.koc.hal.plugin.tellstick.TelstickSerialCommTest
|
# java -cp sqlite-jdbc-3.7.2.jar:jSerialComm-1.3.4.jar:hal.jar:. se.hal.plugin.tellstick.TelstickSerialCommTest
|
||||||
|
|
||||||
#ant clean
|
#ant clean
|
||||||
ant build
|
ant build
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
package se.koc.hal;
|
package se.hal;
|
||||||
|
|
||||||
import se.koc.hal.intf.*;
|
import se.hal.intf.*;
|
||||||
import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
|
import se.hal.struct.Event;
|
||||||
import se.koc.hal.struct.Event;
|
import se.hal.struct.Sensor;
|
||||||
import se.koc.hal.struct.Sensor;
|
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
import zutil.plugin.PluginData;
|
import zutil.plugin.PluginData;
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package se.koc.hal;
|
package se.hal;
|
||||||
|
|
||||||
import se.koc.hal.bot.AliceBot;
|
import se.hal.bot.AliceBot;
|
||||||
import se.koc.hal.intf.HalBot;
|
import se.hal.intf.HalBot;
|
||||||
import se.koc.hal.intf.HalSpeachToText;
|
import se.hal.intf.HalSpeachToText;
|
||||||
import se.koc.hal.intf.HalTextToSpeach;
|
import se.hal.intf.HalTextToSpeach;
|
||||||
import se.koc.hal.struct.SwitchEvent;
|
import se.hal.struct.SwitchEvent;
|
||||||
import se.koc.hal.stt.ManualSTTClient;
|
import se.hal.stt.ManualSTTClient;
|
||||||
import se.koc.hal.tts.MaryRemoteTTSClient;
|
import se.hal.tts.MaryRemoteTTSClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal;
|
package se.hal;
|
||||||
|
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.DBUpgradeHandler;
|
import zutil.db.DBUpgradeHandler;
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
package se.koc.hal;
|
package se.hal;
|
||||||
|
|
||||||
|
|
||||||
import se.koc.hal.deamon.DataAggregatorDaemon;
|
import se.hal.deamon.DataAggregatorDaemon;
|
||||||
import se.koc.hal.deamon.DataCleanupDaemon;
|
import se.hal.deamon.DataCleanupDaemon;
|
||||||
import se.koc.hal.deamon.DataSynchronizationClient;
|
import se.hal.deamon.DataSynchronizationClient;
|
||||||
import se.koc.hal.deamon.DataSynchronizationDaemon;
|
import se.hal.deamon.DataSynchronizationDaemon;
|
||||||
import se.koc.hal.intf.HalDaemon;
|
import se.hal.intf.HalDaemon;
|
||||||
import se.koc.hal.intf.HalHttpPage;
|
import se.hal.intf.HalHttpPage;
|
||||||
import se.koc.hal.page.PCConfigureHttpPage;
|
import se.hal.page.PCConfigureHttpPage;
|
||||||
import se.koc.hal.page.PCHeatMapHttpPage;
|
import se.hal.page.PCHeatMapHttpPage;
|
||||||
import se.koc.hal.page.PCOverviewHttpPage;
|
import se.hal.page.PCOverviewHttpPage;
|
||||||
import se.koc.hal.struct.Event;
|
import se.hal.struct.Event;
|
||||||
import se.koc.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.log.CompactLogFormatter;
|
import zutil.log.CompactLogFormatter;
|
||||||
|
|
@ -35,8 +35,8 @@ public class PowerChallenge {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// init logging
|
// init logging
|
||||||
CompactLogFormatter formatter = new CompactLogFormatter();
|
CompactLogFormatter formatter = new CompactLogFormatter();
|
||||||
LogUtil.setLevel("se.koc.hal", Level.FINEST);
|
LogUtil.setLevel("se.hal", Level.FINEST);
|
||||||
LogUtil.setFormatter("se.koc.hal", formatter);
|
LogUtil.setFormatter("se.hal", formatter);
|
||||||
LogUtil.setLevel("zutil", Level.FINEST);
|
LogUtil.setLevel("zutil", Level.FINEST);
|
||||||
LogUtil.setFormatter("zutil", formatter);
|
LogUtil.setFormatter("zutil", formatter);
|
||||||
LogUtil.setGlobalFormatter(formatter);
|
LogUtil.setGlobalFormatter(formatter);
|
||||||
|
|
@ -1,58 +1,58 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.bot;
|
package se.hal.bot;
|
||||||
|
|
||||||
import org.alicebot.ab.Bot;
|
import org.alicebot.ab.Bot;
|
||||||
import org.alicebot.ab.Chat;
|
import org.alicebot.ab.Chat;
|
||||||
import org.alicebot.ab.MagicBooleans;
|
import org.alicebot.ab.MagicBooleans;
|
||||||
import se.koc.hal.intf.HalBot;
|
import se.hal.intf.HalBot;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-05-07.
|
* Created by Ziver on 2015-05-07.
|
||||||
*/
|
*/
|
||||||
public class AliceBot implements HalBot{
|
public class AliceBot implements HalBot{
|
||||||
private Chat chatSession;
|
private Chat chatSession;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
MagicBooleans.trace_mode = false;
|
MagicBooleans.trace_mode = false;
|
||||||
|
|
||||||
File path = FileUtil.find("resource");
|
File path = FileUtil.find("resource");
|
||||||
if(path == null || !path.exists()){
|
if(path == null || !path.exists()){
|
||||||
System.err.println("Bot folder does not exist");
|
System.err.println("Bot folder does not exist");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
Bot bot = new Bot(
|
Bot bot = new Bot(
|
||||||
"super",
|
"super",
|
||||||
path.getAbsolutePath());
|
path.getAbsolutePath());
|
||||||
chatSession = new Chat(bot);
|
chatSession = new Chat(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String respond(String question) {
|
public String respond(String question) {
|
||||||
return chatSession.multisentenceRespond(question);
|
return chatSession.multisentenceRespond(question);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package se.koc.hal.deamon;
|
package se.hal.deamon;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.intf.HalDaemon;
|
import se.hal.intf.HalDaemon;
|
||||||
import se.koc.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
import se.koc.hal.intf.HalSensor.AggregationMethod;
|
import se.hal.intf.HalSensor.AggregationMethod;
|
||||||
import se.koc.hal.struct.PowerConsumptionSensor;
|
import se.hal.struct.PowerConsumptionSensor;
|
||||||
import se.koc.hal.util.TimeUtility;
|
import se.hal.util.TimeUtility;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.SQLResultHandler;
|
import zutil.db.SQLResultHandler;
|
||||||
import zutil.db.handler.SimpleSQLResult;
|
import zutil.db.handler.SimpleSQLResult;
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package se.koc.hal.deamon;
|
package se.hal.deamon;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.intf.HalDaemon;
|
import se.hal.intf.HalDaemon;
|
||||||
import se.koc.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
import se.koc.hal.struct.PowerConsumptionSensor;
|
import se.hal.struct.PowerConsumptionSensor;
|
||||||
import se.koc.hal.util.TimeUtility;
|
import se.hal.util.TimeUtility;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.SQLResultHandler;
|
import zutil.db.SQLResultHandler;
|
||||||
import zutil.db.handler.SimpleSQLResult;
|
import zutil.db.handler.SimpleSQLResult;
|
||||||
|
|
@ -1,134 +1,134 @@
|
||||||
package se.koc.hal.deamon;
|
package se.hal.deamon;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.deamon.DataSynchronizationDaemon.*;
|
import se.hal.deamon.DataSynchronizationDaemon.*;
|
||||||
import se.koc.hal.intf.HalDaemon;
|
import se.hal.intf.HalDaemon;
|
||||||
import se.koc.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
import se.koc.hal.struct.User;
|
import se.hal.struct.User;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.NoRouteToHostException;
|
import java.net.NoRouteToHostException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class DataSynchronizationClient implements HalDaemon {
|
public class DataSynchronizationClient implements HalDaemon {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
private static final long SYNC_INTERVAL = 5 * 60 * 1000; // 5 min
|
private static final long SYNC_INTERVAL = 5 * 60 * 1000; // 5 min
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initiate(ScheduledExecutorService executor){
|
public void initiate(ScheduledExecutorService executor){
|
||||||
executor.scheduleAtFixedRate(this, 10000, SYNC_INTERVAL, TimeUnit.MILLISECONDS);
|
executor.scheduleAtFixedRate(this, 10000, SYNC_INTERVAL, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
DBConnection db = HalContext.getDB();
|
DBConnection db = HalContext.getDB();
|
||||||
List<User> users = User.getExternalUsers(db);
|
List<User> users = User.getExternalUsers(db);
|
||||||
for(User user : users){
|
for(User user : users){
|
||||||
if(user.getHostname() == null){
|
if(user.getHostname() == null){
|
||||||
logger.fine("Hostname not defined for user: "+ user.getUserName());
|
logger.fine("Hostname not defined for user: "+ user.getUserName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
logger.fine("Synchronizing user: "+ user.getUserName() +" ("+user.getHostname()+":"+user.getPort()+")");
|
logger.fine("Synchronizing user: "+ user.getUserName() +" ("+user.getHostname()+":"+user.getPort()+")");
|
||||||
try (Socket s = new Socket(user.getHostname(), user.getPort());){
|
try (Socket s = new Socket(user.getHostname(), user.getPort());){
|
||||||
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
||||||
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
|
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
|
||||||
|
|
||||||
// Request peer data
|
// Request peer data
|
||||||
out.writeObject(new PeerDataReqDTO());
|
out.writeObject(new PeerDataReqDTO());
|
||||||
PeerDataRspDTO peerData = (PeerDataRspDTO) in.readObject();
|
PeerDataRspDTO peerData = (PeerDataRspDTO) in.readObject();
|
||||||
user.setUserName(peerData.username);
|
user.setUserName(peerData.username);
|
||||||
user.setAddress(peerData.address);
|
user.setAddress(peerData.address);
|
||||||
user.save(db);
|
user.save(db);
|
||||||
|
|
||||||
for(SensorDTO sensorDTO : peerData.sensors){
|
for(SensorDTO sensorDTO : peerData.sensors){
|
||||||
Sensor sensor = Sensor.getExternalSensor(db, sensorDTO.sensorId);
|
Sensor sensor = Sensor.getExternalSensor(db, sensorDTO.sensorId);
|
||||||
if(sensor != null) { // new sensor
|
if(sensor != null) { // new sensor
|
||||||
sensor = new Sensor();
|
sensor = new Sensor();
|
||||||
logger.fine("Created new external sensor with external_id: "+ sensorDTO.sensorId);
|
logger.fine("Created new external sensor with external_id: "+ sensorDTO.sensorId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
logger.fine("Updating external sensor with external_id: "+ sensorDTO.sensorId);
|
logger.fine("Updating external sensor with external_id: "+ sensorDTO.sensorId);
|
||||||
sensor.setExternalId(sensorDTO.sensorId);
|
sensor.setExternalId(sensorDTO.sensorId);
|
||||||
sensor.setName(sensorDTO.name);
|
sensor.setName(sensorDTO.name);
|
||||||
sensor.setType(sensorDTO.type);
|
sensor.setType(sensorDTO.type);
|
||||||
sensor.setConfig(sensorDTO.config);
|
sensor.setConfig(sensorDTO.config);
|
||||||
sensor.save(db);
|
sensor.save(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request sensor data
|
// Request sensor data
|
||||||
List<Sensor> sensors = Sensor.getSensors(db, user);
|
List<Sensor> sensors = Sensor.getSensors(db, user);
|
||||||
for(Sensor sensor : sensors){
|
for(Sensor sensor : sensors){
|
||||||
if(sensor.isSynced()) {
|
if(sensor.isSynced()) {
|
||||||
SensorDataReqDTO req = new SensorDataReqDTO();
|
SensorDataReqDTO req = new SensorDataReqDTO();
|
||||||
req.sensorId = sensor.getExternalId();
|
req.sensorId = sensor.getExternalId();
|
||||||
req.offsetSequenceId = Sensor.getHighestSequenceId(sensor.getId());
|
req.offsetSequenceId = Sensor.getHighestSequenceId(sensor.getId());
|
||||||
out.writeObject(req);
|
out.writeObject(req);
|
||||||
|
|
||||||
SensorDataListDTO dataList = (SensorDataListDTO) in.readObject();
|
SensorDataListDTO dataList = (SensorDataListDTO) in.readObject();
|
||||||
for (SensorDataDTO data : dataList) {
|
for (SensorDataDTO data : dataList) {
|
||||||
PreparedStatement stmt = db.getPreparedStatement("INSERT INTO sensor_data_aggr(sensor_id, sequence_id, timestamp_start, timestamp_end, data, confidence) VALUES(?, ?, ?, ?, ?, ?)");
|
PreparedStatement stmt = db.getPreparedStatement("INSERT INTO sensor_data_aggr(sensor_id, sequence_id, timestamp_start, timestamp_end, data, confidence) VALUES(?, ?, ?, ?, ?, ?)");
|
||||||
stmt.setLong(1, sensor.getId());
|
stmt.setLong(1, sensor.getId());
|
||||||
stmt.setLong(2, data.sequenceId);
|
stmt.setLong(2, data.sequenceId);
|
||||||
stmt.setLong(3, data.timestampStart);
|
stmt.setLong(3, data.timestampStart);
|
||||||
stmt.setLong(4, data.timestampEnd);
|
stmt.setLong(4, data.timestampEnd);
|
||||||
stmt.setInt(5, data.data);
|
stmt.setInt(5, data.data);
|
||||||
stmt.setFloat(6, data.confidence);
|
stmt.setFloat(6, data.confidence);
|
||||||
DBConnection.exec(stmt);
|
DBConnection.exec(stmt);
|
||||||
}
|
}
|
||||||
logger.fine("Stored " + dataList.size() + " entries for sensor " + sensor.getId() + " from " + user.getUserName());
|
logger.fine("Stored " + dataList.size() + " entries for sensor " + sensor.getId() + " from " + user.getUserName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
logger.fine("Skipped sensor " + sensor.getId());
|
logger.fine("Skipped sensor " + sensor.getId());
|
||||||
}
|
}
|
||||||
out.writeObject(null); // Tell server we are disconnecting
|
out.writeObject(null); // Tell server we are disconnecting
|
||||||
out.close();
|
out.close();
|
||||||
in.close();
|
in.close();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
} catch (NoRouteToHostException |UnknownHostException|ConnectException e) {
|
} catch (NoRouteToHostException |UnknownHostException|ConnectException e) {
|
||||||
logger.warning("Unable to connect to "+ user.getHostname()+":"+user.getPort() +", "+ e.getMessage());
|
logger.warning("Unable to connect to "+ user.getHostname()+":"+user.getPort() +", "+ e.getMessage());
|
||||||
} catch (ClassNotFoundException|IOException e) {
|
} catch (ClassNotFoundException|IOException e) {
|
||||||
logger.log(Level.SEVERE, null, e);
|
logger.log(Level.SEVERE, null, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
logger.log(Level.SEVERE, null, e);
|
logger.log(Level.SEVERE, null, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////// DTO ///////////////////////
|
/////////////// DTO ///////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request Peer information and available sensors
|
* Request Peer information and available sensors
|
||||||
*/
|
*/
|
||||||
protected static class PeerDataReqDTO implements Serializable{}
|
protected static class PeerDataReqDTO implements Serializable{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request aggregate data for a specific sensor and offset
|
* Request aggregate data for a specific sensor and offset
|
||||||
*/
|
*/
|
||||||
protected static class SensorDataReqDTO implements Serializable{
|
protected static class SensorDataReqDTO implements Serializable{
|
||||||
private static final long serialVersionUID = -9066734025245139989L;
|
private static final long serialVersionUID = -9066734025245139989L;
|
||||||
|
|
||||||
public long sensorId;
|
public long sensorId;
|
||||||
public long offsetSequenceId; // highest known sequence id
|
public long offsetSequenceId; // highest known sequence id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,167 +1,166 @@
|
||||||
package se.koc.hal.deamon;
|
package se.hal.deamon;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.deamon.DataSynchronizationClient.*;
|
import se.hal.deamon.DataSynchronizationClient.*;
|
||||||
import se.koc.hal.intf.HalDaemon;
|
import se.hal.intf.HalDaemon;
|
||||||
import se.koc.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
import se.koc.hal.struct.User;
|
import se.hal.struct.User;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.SQLResultHandler;
|
import zutil.db.SQLResultHandler;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
import zutil.net.threaded.ThreadedTCPNetworkServer;
|
import zutil.net.threaded.ThreadedTCPNetworkServer;
|
||||||
import zutil.net.threaded.ThreadedTCPNetworkServerThread;
|
import zutil.net.threaded.ThreadedTCPNetworkServerThread;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
public class DataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
|
||||||
public class DataSynchronizationDaemon extends ThreadedTCPNetworkServer implements HalDaemon {
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
|
||||||
|
|
||||||
|
public DataSynchronizationDaemon() {
|
||||||
public DataSynchronizationDaemon() {
|
super(HalContext.getIntegerProperty("sync_port"));
|
||||||
super(HalContext.getIntegerProperty("sync_port"));
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void initiate(ScheduledExecutorService executor){
|
||||||
public void initiate(ScheduledExecutorService executor){
|
this.start();
|
||||||
this.start();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
@Override
|
protected ThreadedTCPNetworkServerThread getThreadInstance(Socket s) {
|
||||||
protected ThreadedTCPNetworkServerThread getThreadInstance(Socket s) {
|
try {
|
||||||
try {
|
return new DataSynchronizationDaemonThread(s);
|
||||||
return new DataSynchronizationDaemonThread(s);
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
logger.log(Level.SEVERE, "Unable to create DataSynchronizationDaemonThread", e);
|
||||||
logger.log(Level.SEVERE, "Unable to create DataSynchronizationDaemonThread", e);
|
}
|
||||||
}
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
private class DataSynchronizationDaemonThread implements ThreadedTCPNetworkServerThread{
|
||||||
private class DataSynchronizationDaemonThread implements ThreadedTCPNetworkServerThread{
|
private Socket s;
|
||||||
private Socket s;
|
private ObjectOutputStream out;
|
||||||
private ObjectOutputStream out;
|
private ObjectInputStream in;
|
||||||
private ObjectInputStream in;
|
|
||||||
|
|
||||||
|
public DataSynchronizationDaemonThread(Socket s) throws IOException{
|
||||||
public DataSynchronizationDaemonThread(Socket s) throws IOException{
|
this.s = s;
|
||||||
this.s = s;
|
this.out = new ObjectOutputStream(s.getOutputStream());
|
||||||
this.out = new ObjectOutputStream(s.getOutputStream());
|
this.in = new ObjectInputStream(s.getInputStream());
|
||||||
this.in = new ObjectInputStream(s.getInputStream());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
public void run(){
|
||||||
public void run(){
|
logger.fine("User connected: "+ s.getInetAddress().getHostName());
|
||||||
logger.fine("User connected: "+ s.getInetAddress().getHostName());
|
DBConnection db = HalContext.getDB();
|
||||||
DBConnection db = HalContext.getDB();
|
|
||||||
|
try {
|
||||||
try {
|
Object obj = null;
|
||||||
Object obj = null;
|
while((obj = in.readObject()) != null){
|
||||||
while((obj = in.readObject()) != null){
|
if(obj instanceof PeerDataReqDTO){
|
||||||
if(obj instanceof PeerDataReqDTO){
|
logger.fine("Client requesting peer data");
|
||||||
logger.fine("Client requesting peer data");
|
PeerDataRspDTO rsp = new PeerDataRspDTO();
|
||||||
PeerDataRspDTO rsp = new PeerDataRspDTO();
|
User localUser = User.getLocalUser(db);
|
||||||
User localUser = User.getLocalUser(db);
|
rsp.username = localUser.getUserName();
|
||||||
rsp.username = localUser.getUserName();
|
rsp.address = localUser.getAddress();
|
||||||
rsp.address = localUser.getAddress();
|
|
||||||
|
rsp.sensors = new ArrayList<>();
|
||||||
rsp.sensors = new ArrayList<>();
|
for(Sensor sensor : Sensor.getLocalSensors(db)){
|
||||||
for(Sensor sensor : Sensor.getLocalSensors(db)){
|
if(sensor.isSynced()) {
|
||||||
if(sensor.isSynced()) {
|
SensorDTO dto = new SensorDTO();
|
||||||
SensorDTO dto = new SensorDTO();
|
dto.sensorId = sensor.getId();
|
||||||
dto.sensorId = sensor.getId();
|
dto.name = sensor.getName();
|
||||||
dto.name = sensor.getName();
|
dto.type = sensor.getType();
|
||||||
dto.type = sensor.getType();
|
dto.config = sensor.getConfig();
|
||||||
dto.config = sensor.getConfig();
|
rsp.sensors.add(dto);
|
||||||
rsp.sensors.add(dto);
|
}
|
||||||
}
|
}
|
||||||
}
|
out.writeObject(rsp);
|
||||||
out.writeObject(rsp);
|
}
|
||||||
}
|
if(obj instanceof SensorDataReqDTO){
|
||||||
if(obj instanceof SensorDataReqDTO){
|
SensorDataReqDTO req = (SensorDataReqDTO) obj;
|
||||||
SensorDataReqDTO req = (SensorDataReqDTO) obj;
|
Sensor sensor = Sensor.getSensor(db, req.sensorId);
|
||||||
Sensor sensor = Sensor.getSensor(db, req.sensorId);
|
if(sensor.isSynced()) {
|
||||||
if(sensor.isSynced()) {
|
PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM sensor_data_aggr WHERE sensor_id == ? AND sequence_id > ?");
|
||||||
PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM sensor_data_aggr WHERE sensor_id == ? AND sequence_id > ?");
|
stmt.setLong(1, sensor.getId());
|
||||||
stmt.setLong(1, sensor.getId());
|
stmt.setLong(2, req.offsetSequenceId);
|
||||||
stmt.setLong(2, req.offsetSequenceId);
|
logger.fine("Client requesting sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
|
||||||
logger.fine("Client requesting sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
|
SensorDataListDTO rsp = DBConnection.exec(stmt, new SQLResultHandler<SensorDataListDTO>() {
|
||||||
SensorDataListDTO rsp = DBConnection.exec(stmt, new SQLResultHandler<SensorDataListDTO>() {
|
@Override
|
||||||
@Override
|
public SensorDataListDTO handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
||||||
public SensorDataListDTO handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
SensorDataListDTO list = new SensorDataListDTO();
|
||||||
SensorDataListDTO list = new SensorDataListDTO();
|
while (result.next()) {
|
||||||
while (result.next()) {
|
SensorDataDTO data = new SensorDataDTO();
|
||||||
SensorDataDTO data = new SensorDataDTO();
|
data.sequenceId = result.getLong("sensor_id");
|
||||||
data.sequenceId = result.getLong("sensor_id");
|
data.timestampStart = result.getLong("timestamp_start");
|
||||||
data.timestampStart = result.getLong("timestamp_start");
|
data.timestampEnd = result.getLong("timestamp_end");
|
||||||
data.timestampEnd = result.getLong("timestamp_end");
|
data.data = result.getInt("data");
|
||||||
data.data = result.getInt("data");
|
data.confidence = result.getFloat("confidence");
|
||||||
data.confidence = result.getFloat("confidence");
|
list.add(data);
|
||||||
list.add(data);
|
}
|
||||||
}
|
return list;
|
||||||
return list;
|
}
|
||||||
}
|
});
|
||||||
});
|
logger.fine("Sending " + rsp.size() + " sensor data items to client");
|
||||||
logger.fine("Sending " + rsp.size() + " sensor data items to client");
|
out.writeObject(rsp);
|
||||||
out.writeObject(rsp);
|
}
|
||||||
}
|
else{
|
||||||
else{
|
logger.warning("Client requesting non synced sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
|
||||||
logger.warning("Client requesting non synced sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
|
SensorDataListDTO rsp = new SensorDataListDTO();
|
||||||
SensorDataListDTO rsp = new SensorDataListDTO();
|
out.writeObject(rsp);
|
||||||
out.writeObject(rsp);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
out.close();
|
||||||
out.close();
|
in.close();
|
||||||
in.close();
|
s.close();
|
||||||
s.close();
|
|
||||||
|
} catch (ClassNotFoundException|IOException|SQLException e) {
|
||||||
} catch (ClassNotFoundException|IOException|SQLException e) {
|
logger.log(Level.SEVERE, null, e);
|
||||||
logger.log(Level.SEVERE, null, e);
|
}
|
||||||
}
|
logger.fine("User disconnected: "+ s.getInetAddress().getHostName());
|
||||||
logger.fine("User disconnected: "+ s.getInetAddress().getHostName());
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/////////////// DTO ///////////////////////
|
||||||
/////////////// DTO ///////////////////////
|
protected static class PeerDataRspDTO implements Serializable{
|
||||||
protected static class PeerDataRspDTO implements Serializable{
|
public String username;
|
||||||
public String username;
|
public String address;
|
||||||
public String address;
|
|
||||||
|
public ArrayList<SensorDTO> sensors;
|
||||||
public ArrayList<SensorDTO> sensors;
|
}
|
||||||
}
|
protected static class SensorDTO implements Serializable{
|
||||||
protected static class SensorDTO implements Serializable{
|
public long sensorId;
|
||||||
public long sensorId;
|
public String name;
|
||||||
public String name;
|
public String type;
|
||||||
public String type;
|
public String config;
|
||||||
public String config;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
protected static class SensorDataListDTO extends ArrayList<SensorDataDTO> implements Serializable{
|
||||||
protected static class SensorDataListDTO extends ArrayList<SensorDataDTO> implements Serializable{
|
private static final long serialVersionUID = -5701618637734020691L;
|
||||||
private static final long serialVersionUID = -5701618637734020691L;
|
}
|
||||||
}
|
protected static class SensorDataDTO implements Serializable{
|
||||||
protected static class SensorDataDTO implements Serializable{
|
private static final long serialVersionUID = 8494331502087736809L;
|
||||||
private static final long serialVersionUID = 8494331502087736809L;
|
|
||||||
|
public long sequenceId;
|
||||||
public long sequenceId;
|
public long timestampStart;
|
||||||
public long timestampStart;
|
public long timestampEnd;
|
||||||
public long timestampEnd;
|
public int data;
|
||||||
public int data;
|
public float confidence;
|
||||||
public float confidence;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
@ -1,33 +1,33 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-05-07.
|
* Created by Ziver on 2015-05-07.
|
||||||
*/
|
*/
|
||||||
public interface HalBot {
|
public interface HalBot {
|
||||||
|
|
||||||
public void initialize();
|
public void initialize();
|
||||||
|
|
||||||
public String respond(String question);
|
public String respond(String question);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
import zutil.parser.DataNode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-23.
|
* Created by Ziver on 2015-12-23.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-15.
|
* Created by Ziver on 2015-12-15.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
public interface HalEventReportListener {
|
public interface HalEventReportListener {
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.struct.User;
|
import se.hal.struct.User;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.net.http.HttpHeaderParser;
|
import zutil.net.http.HttpHeaderParser;
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
import zutil.parser.DataNode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-23.
|
* Created by Ziver on 2015-12-23.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-15.
|
* Created by Ziver on 2015-12-15.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
public interface HalSensorReportListener {
|
public interface HalSensorReportListener {
|
||||||
|
|
||||||
|
|
@ -1,35 +1,35 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 ezivkoc
|
* Copyright (c) 2013 ezivkoc
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
* User: ezivkoc
|
* User: ezivkoc
|
||||||
* Date: 2013-12-17
|
* Date: 2013-12-17
|
||||||
* Time: 13:40
|
* Time: 13:40
|
||||||
*/
|
*/
|
||||||
public interface HalSpeachToText {
|
public interface HalSpeachToText {
|
||||||
public void initSTT();
|
public void initSTT();
|
||||||
|
|
||||||
public String listen();
|
public String listen();
|
||||||
}
|
}
|
||||||
|
|
@ -1,35 +1,35 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 ezivkoc
|
* Copyright (c) 2013 ezivkoc
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.intf;
|
package se.hal.intf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
* User: ezivkoc
|
* User: ezivkoc
|
||||||
* Date: 2013-12-17
|
* Date: 2013-12-17
|
||||||
* Time: 13:40
|
* Time: 13:40
|
||||||
*/
|
*/
|
||||||
public interface HalTextToSpeach {
|
public interface HalTextToSpeach {
|
||||||
public void initTTS();
|
public void initTTS();
|
||||||
|
|
||||||
public void speak(String msg);
|
public void speak(String msg);
|
||||||
}
|
}
|
||||||
|
|
@ -1,135 +1,135 @@
|
||||||
package se.koc.hal.page;
|
package se.hal.page;
|
||||||
|
|
||||||
import se.koc.hal.ControllerManager;
|
import se.hal.ControllerManager;
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.intf.HalHttpPage;
|
import se.hal.intf.HalHttpPage;
|
||||||
import se.koc.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
import se.koc.hal.struct.User;
|
import se.hal.struct.User;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.parser.Templator;
|
import zutil.parser.Templator;
|
||||||
import zutil.ui.Configurator;
|
import zutil.ui.Configurator;
|
||||||
import zutil.ui.Configurator.*;
|
import zutil.ui.Configurator.*;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PCConfigureHttpPage extends HalHttpPage {
|
public class PCConfigureHttpPage extends HalHttpPage {
|
||||||
private class SensorDataParams{
|
private class SensorDataParams{
|
||||||
public Class clazz;
|
public Class clazz;
|
||||||
public ConfigurationParam[] params;
|
public ConfigurationParam[] params;
|
||||||
}
|
}
|
||||||
private SensorDataParams[] sensorConfigurations;
|
private SensorDataParams[] sensorConfigurations;
|
||||||
|
|
||||||
|
|
||||||
public PCConfigureHttpPage() {
|
public PCConfigureHttpPage() {
|
||||||
super("Configuration", "config");
|
super("Configuration", "config");
|
||||||
|
|
||||||
sensorConfigurations = new SensorDataParams[
|
sensorConfigurations = new SensorDataParams[
|
||||||
ControllerManager.getInstance().getAvailableSensors().size()];
|
ControllerManager.getInstance().getAvailableSensors().size()];
|
||||||
int i=0;
|
int i=0;
|
||||||
for(Class c : ControllerManager.getInstance().getAvailableSensors()){
|
for(Class c : ControllerManager.getInstance().getAvailableSensors()){
|
||||||
sensorConfigurations[i] = new SensorDataParams();
|
sensorConfigurations[i] = new SensorDataParams();
|
||||||
sensorConfigurations[i].clazz = c;
|
sensorConfigurations[i].clazz = c;
|
||||||
sensorConfigurations[i].params = Configurator.getConfiguration(c);
|
sensorConfigurations[i].params = Configurator.getConfiguration(c);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Templator httpRespond(
|
public Templator httpRespond(
|
||||||
Map<String, Object> session,
|
Map<String, Object> session,
|
||||||
Map<String, String> cookie,
|
Map<String, String> cookie,
|
||||||
Map<String, String> request)
|
Map<String, String> request)
|
||||||
throws Exception{
|
throws Exception{
|
||||||
|
|
||||||
DBConnection db = HalContext.getDB();
|
DBConnection db = HalContext.getDB();
|
||||||
User localUser = User.getLocalUser(db);
|
User localUser = User.getLocalUser(db);
|
||||||
|
|
||||||
// Save new input
|
// Save new input
|
||||||
if(request.containsKey("action")){
|
if(request.containsKey("action")){
|
||||||
String action = request.get("action");
|
String action = request.get("action");
|
||||||
int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
|
int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
|
||||||
Sensor sensor;
|
Sensor sensor;
|
||||||
User user;
|
User user;
|
||||||
switch(action) {
|
switch(action) {
|
||||||
// Local User
|
// Local User
|
||||||
case "modify_local_user":
|
case "modify_local_user":
|
||||||
localUser.setUserName(request.get("username"));
|
localUser.setUserName(request.get("username"));
|
||||||
localUser.setAddress(request.get("address"));
|
localUser.setAddress(request.get("address"));
|
||||||
localUser.save(db);
|
localUser.save(db);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Local Sensors
|
// Local Sensors
|
||||||
case "create_local_sensor":
|
case "create_local_sensor":
|
||||||
sensor = new Sensor();
|
sensor = new Sensor();
|
||||||
sensor.setName(request.get("name"));
|
sensor.setName(request.get("name"));
|
||||||
sensor.setType(request.get("type"));
|
sensor.setType(request.get("type"));
|
||||||
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
||||||
//sensor.setConfig(request.get("config"));
|
//sensor.setConfig(request.get("config"));
|
||||||
sensor.setUser(localUser);
|
sensor.setUser(localUser);
|
||||||
sensor.save(db);
|
sensor.save(db);
|
||||||
case "modify_local_sensor":
|
case "modify_local_sensor":
|
||||||
sensor = Sensor.getSensor(db, id);
|
sensor = Sensor.getSensor(db, id);
|
||||||
if(sensor != null){
|
if(sensor != null){
|
||||||
sensor.setName(request.get("name"));
|
sensor.setName(request.get("name"));
|
||||||
sensor.setType(request.get("type"));
|
sensor.setType(request.get("type"));
|
||||||
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
||||||
//sensor.setConfig(request.get("config"));
|
//sensor.setConfig(request.get("config"));
|
||||||
sensor.save(db);
|
sensor.save(db);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "remove_local_sensor":
|
case "remove_local_sensor":
|
||||||
sensor = Sensor.getSensor(db, id);
|
sensor = Sensor.getSensor(db, id);
|
||||||
if(sensor != null)
|
if(sensor != null)
|
||||||
sensor.delete(db);
|
sensor.delete(db);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// External Users
|
// External Users
|
||||||
case "create_external_user":
|
case "create_external_user":
|
||||||
user = new User();
|
user = new User();
|
||||||
user.setHostname(request.get("hostname"));
|
user.setHostname(request.get("hostname"));
|
||||||
user.setPort(Integer.parseInt(request.get("port")));
|
user.setPort(Integer.parseInt(request.get("port")));
|
||||||
user.setExternal(true);
|
user.setExternal(true);
|
||||||
user.save(db);
|
user.save(db);
|
||||||
break;
|
break;
|
||||||
case "modify_external_user":
|
case "modify_external_user":
|
||||||
user = User.getUser(db, id);
|
user = User.getUser(db, id);
|
||||||
if(user != null){
|
if(user != null){
|
||||||
user.setHostname(request.get("hostname"));
|
user.setHostname(request.get("hostname"));
|
||||||
user.setPort(Integer.parseInt(request.get("port")));
|
user.setPort(Integer.parseInt(request.get("port")));
|
||||||
user.save(db);
|
user.save(db);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "remove_external_user":
|
case "remove_external_user":
|
||||||
user = User.getUser(db, id);
|
user = User.getUser(db, id);
|
||||||
if(user != null)
|
if(user != null)
|
||||||
user.delete(db);
|
user.delete(db);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// External Sensors
|
// External Sensors
|
||||||
case "modify_external_sensor":
|
case "modify_external_sensor":
|
||||||
sensor = Sensor.getSensor(db, id);
|
sensor = Sensor.getSensor(db, id);
|
||||||
if(sensor != null){
|
if(sensor != null){
|
||||||
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
||||||
sensor.save(db);
|
sensor.save(db);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
Templator tmpl = new Templator(FileUtil.find("web-resource/configure.tmpl"));
|
Templator tmpl = new Templator(FileUtil.find("web-resource/configure.tmpl"));
|
||||||
tmpl.set("user", localUser);
|
tmpl.set("user", localUser);
|
||||||
tmpl.set("localSensors", Sensor.getLocalSensors(db));
|
tmpl.set("localSensors", Sensor.getLocalSensors(db));
|
||||||
tmpl.set("localSensorConf", sensorConfigurations);
|
tmpl.set("localSensorConf", sensorConfigurations);
|
||||||
tmpl.set("detectedSensors", ControllerManager.getInstance().getDetectedSensors());
|
tmpl.set("detectedSensors", ControllerManager.getInstance().getDetectedSensors());
|
||||||
tmpl.set("extUsers", User.getExternalUsers(db));
|
tmpl.set("extUsers", User.getExternalUsers(db));
|
||||||
tmpl.set("extSensor", Sensor.getExternalSensors(db));
|
tmpl.set("extSensor", Sensor.getExternalSensors(db));
|
||||||
|
|
||||||
tmpl.set("availableSensors", ControllerManager.getInstance().getAvailableSensors());
|
tmpl.set("availableSensors", ControllerManager.getInstance().getAvailableSensors());
|
||||||
|
|
||||||
return tmpl;
|
return tmpl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,26 +1,26 @@
|
||||||
package se.koc.hal.page;
|
package se.hal.page;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalHttpPage;
|
import se.hal.intf.HalHttpPage;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.parser.Templator;
|
import zutil.parser.Templator;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PCHeatMapHttpPage extends HalHttpPage {
|
public class PCHeatMapHttpPage extends HalHttpPage {
|
||||||
|
|
||||||
public PCHeatMapHttpPage() {
|
public PCHeatMapHttpPage() {
|
||||||
super("Heatmap", "map");
|
super("Heatmap", "map");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Templator httpRespond(
|
public Templator httpRespond(
|
||||||
Map<String, Object> session,
|
Map<String, Object> session,
|
||||||
Map<String, String> cookie,
|
Map<String, String> cookie,
|
||||||
Map<String, String> request)
|
Map<String, String> request)
|
||||||
throws Exception{
|
throws Exception{
|
||||||
|
|
||||||
Templator tmpl = new Templator(FileUtil.find("web-resource/heatmap.tmpl"));
|
Templator tmpl = new Templator(FileUtil.find("web-resource/heatmap.tmpl"));
|
||||||
return tmpl;
|
return tmpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package se.koc.hal.page;
|
package se.hal.page;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.intf.HalHttpPage;
|
import se.hal.intf.HalHttpPage;
|
||||||
import se.koc.hal.util.TimeUtility;
|
import se.hal.util.TimeUtility;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.SQLResultHandler;
|
import zutil.db.SQLResultHandler;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.plugin.localsensor;
|
package se.hal.plugin.localsensor;
|
||||||
|
|
||||||
import com.pi4j.io.gpio.*;
|
import com.pi4j.io.gpio.*;
|
||||||
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
|
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
|
||||||
|
|
@ -1,100 +1,100 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.plugin.tellstick;
|
package se.hal.plugin.tellstick;
|
||||||
|
|
||||||
import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
|
import se.hal.plugin.tellstick.protocols.NexaSelfLearning;
|
||||||
import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
|
import se.hal.plugin.tellstick.protocols.Oregon0x1A2D;
|
||||||
import zutil.converters.Converter;
|
import zutil.converters.Converter;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-02-18.
|
* Created by Ziver on 2015-02-18.
|
||||||
*/
|
*/
|
||||||
public class TellstickParser {
|
public class TellstickParser {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
private static HashMap<String, Class<? extends TellstickProtocol>> protocolMap;
|
private static HashMap<String, Class<? extends TellstickProtocol>> protocolMap;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
registerProtocol(NexaSelfLearning.class);
|
registerProtocol(NexaSelfLearning.class);
|
||||||
registerProtocol(Oregon0x1A2D.class);
|
registerProtocol(Oregon0x1A2D.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public TellstickProtocol decode(String data) {
|
public TellstickProtocol decode(String data) {
|
||||||
if (data.startsWith("+W")) {
|
if (data.startsWith("+W")) {
|
||||||
data = data.substring(2);
|
data = data.substring(2);
|
||||||
HashMap<String, String> map = new HashMap<String, String>();
|
HashMap<String, String> map = new HashMap<String, String>();
|
||||||
String[] parameters = data.split(";");
|
String[] parameters = data.split(";");
|
||||||
for (String parameter : parameters) {
|
for (String parameter : parameters) {
|
||||||
String[] keyValue = parameter.split(":");
|
String[] keyValue = parameter.split(":");
|
||||||
map.put(keyValue[0], keyValue[1]);
|
map.put(keyValue[0], keyValue[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<? extends TellstickProtocol> protClass =
|
Class<? extends TellstickProtocol> protClass =
|
||||||
getProtocolClass(map.get("protocol"), map.get("model"));
|
getProtocolClass(map.get("protocol"), map.get("model"));
|
||||||
if (protClass != null) {
|
if (protClass != null) {
|
||||||
try {
|
try {
|
||||||
TellstickProtocol protocol = protClass.newInstance();
|
TellstickProtocol protocol = protClass.newInstance();
|
||||||
String binData = map.get("data");
|
String binData = map.get("data");
|
||||||
|
|
||||||
protocol.decode(Converter.hexToByte(binData));
|
protocol.decode(Converter.hexToByte(binData));
|
||||||
logger.finest("Decoded: " + protocol);
|
logger.finest("Decoded: " + protocol);
|
||||||
return protocol;
|
return protocol;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.WARNING, null, e);
|
logger.log(Level.WARNING, null, e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warning("Unknown protocol: " + data);
|
logger.warning("Unknown protocol: " + data);
|
||||||
}
|
}
|
||||||
} else if (data.startsWith("+S") || data.startsWith("+T")) {
|
} else if (data.startsWith("+S") || data.startsWith("+T")) {
|
||||||
// This is confirmation of send commands
|
// This is confirmation of send commands
|
||||||
}else {
|
}else {
|
||||||
logger.severe("Unknown prefix: " + data);
|
logger.severe("Unknown prefix: " + data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void registerProtocol(Class<? extends TellstickProtocol> protClass) {
|
public static void registerProtocol(Class<? extends TellstickProtocol> protClass) {
|
||||||
try {
|
try {
|
||||||
if (protocolMap == null)
|
if (protocolMap == null)
|
||||||
protocolMap = new HashMap<String, Class<? extends TellstickProtocol>>();
|
protocolMap = new HashMap<String, Class<? extends TellstickProtocol>>();
|
||||||
TellstickProtocol tmp = protClass.newInstance();
|
TellstickProtocol tmp = protClass.newInstance();
|
||||||
protocolMap.put(
|
protocolMap.put(
|
||||||
tmp.getProtocolName() + "-" + tmp.getModelName(),
|
tmp.getProtocolName() + "-" + tmp.getModelName(),
|
||||||
protClass);
|
protClass);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.SEVERE, null, e);
|
logger.log(Level.SEVERE, null, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<? extends TellstickProtocol> getProtocolClass(String protocol, String model) {
|
public static Class<? extends TellstickProtocol> getProtocolClass(String protocol, String model) {
|
||||||
return protocolMap.get(protocol + "-" + model);
|
return protocolMap.get(protocol + "-" + model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,68 +1,68 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.plugin.tellstick;
|
package se.hal.plugin.tellstick;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalEventController;
|
import se.hal.intf.HalEventController;
|
||||||
import se.koc.hal.intf.HalSensorController;
|
import se.hal.intf.HalSensorController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-02-18.
|
* Created by Ziver on 2015-02-18.
|
||||||
*/
|
*/
|
||||||
public abstract class TellstickProtocol {
|
public abstract class TellstickProtocol {
|
||||||
|
|
||||||
private String protocol;
|
private String protocol;
|
||||||
private String model;
|
private String model;
|
||||||
private long timestamp = -1;
|
private long timestamp = -1;
|
||||||
|
|
||||||
|
|
||||||
public TellstickProtocol(String protocol, String model){
|
public TellstickProtocol(String protocol, String model){
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getProtocolName(){
|
public String getProtocolName(){
|
||||||
return protocol;
|
return protocol;
|
||||||
}
|
}
|
||||||
public String getModelName(){
|
public String getModelName(){
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimestamp() {
|
public long getTimestamp() {
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
public void setTimestamp(long timestamp) {
|
public void setTimestamp(long timestamp) {
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Class<? extends HalEventController> getEventController() {
|
public Class<? extends HalEventController> getEventController() {
|
||||||
return TellstickSerialComm.class;
|
return TellstickSerialComm.class;
|
||||||
}
|
}
|
||||||
public Class<? extends HalSensorController> getSensorController() {
|
public Class<? extends HalSensorController> getSensorController() {
|
||||||
return TellstickSerialComm.class;
|
return TellstickSerialComm.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String encode();
|
public abstract String encode();
|
||||||
public abstract void decode(byte[] data);
|
public abstract void decode(byte[] data);
|
||||||
}
|
}
|
||||||
|
|
@ -1,209 +1,207 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.plugin.tellstick;
|
package se.hal.plugin.tellstick;
|
||||||
|
|
||||||
import com.fazecast.jSerialComm.SerialPort;
|
import com.fazecast.jSerialComm.SerialPort;
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.intf.*;
|
import se.hal.intf.*;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.log.InputStreamLogger;
|
||||||
import zutil.log.InputStreamLogger;
|
import zutil.log.LogUtil;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.OutputStreamLogger;
|
||||||
import zutil.log.OutputStreamLogger;
|
import zutil.struct.TimedHashSet;
|
||||||
import zutil.struct.TimedHashSet;
|
|
||||||
|
import java.io.*;
|
||||||
import java.io.*;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.Properties;
|
import java.util.logging.Level;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.logging.Logger;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
/**
|
||||||
|
* This version of the TwoWaySerialComm example makes use of the
|
||||||
/**
|
* SerialPortEventListener to avoid polling.
|
||||||
* This version of the TwoWaySerialComm example makes use of the
|
*/
|
||||||
* SerialPortEventListener to avoid polling.
|
public class TellstickSerialComm implements Runnable, HalSensorController, HalEventController {
|
||||||
*/
|
private static final long TRANSMISSION_UNIQUENESS_TTL = 300; // milliseconds
|
||||||
public class TellstickSerialComm implements Runnable, HalSensorController, HalEventController {
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
private static final long TRANSMISSION_UNIQUENESS_TTL = 300; // milliseconds
|
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private SerialPort serial;
|
||||||
|
private InputStream in;
|
||||||
private SerialPort serial;
|
private OutputStream out;
|
||||||
private InputStream in;
|
private TimedHashSet set; // To check for retransmissions
|
||||||
private OutputStream out;
|
|
||||||
private TimedHashSet set; // To check for retransmissions
|
private TellstickParser parser;
|
||||||
|
private HalSensorReportListener sensorListener;
|
||||||
private TellstickParser parser;
|
private HalEventReportListener eventListener;
|
||||||
private HalSensorReportListener sensorListener;
|
|
||||||
private HalEventReportListener eventListener;
|
private int registeredObjects;
|
||||||
|
|
||||||
private int registeredObjects;
|
|
||||||
|
|
||||||
|
public TellstickSerialComm() {
|
||||||
|
set = new TimedHashSet(TRANSMISSION_UNIQUENESS_TTL);
|
||||||
public TellstickSerialComm() {
|
parser = new TellstickParser();
|
||||||
set = new TimedHashSet(TRANSMISSION_UNIQUENESS_TTL);
|
registeredObjects = 0;
|
||||||
parser = new TellstickParser();
|
}
|
||||||
registeredObjects = 0;
|
|
||||||
}
|
@Override
|
||||||
|
public void initialize() throws Exception {
|
||||||
@Override
|
// Read properties
|
||||||
public void initialize() throws Exception {
|
String port = HalContext.getStringProperty("tellstick.com_port");
|
||||||
// Read properties
|
if (port == null)
|
||||||
String port = HalContext.getStringProperty("tellstick.com_port");
|
port = "COM1"; // defaults
|
||||||
if (port == null)
|
|
||||||
port = "COM1"; // defaults
|
connect(port);
|
||||||
|
}
|
||||||
connect(port);
|
|
||||||
}
|
public void connect(String portName) throws Exception {
|
||||||
|
logger.info("Connecting to com port... ("+ portName +")");
|
||||||
public void connect(String portName) throws Exception {
|
serial = SerialPort.getCommPort(portName);
|
||||||
logger.info("Connecting to com port... ("+ portName +")");
|
serial.setBaudRate(9600);
|
||||||
serial = SerialPort.getCommPort(portName);
|
if(!serial.openPort())
|
||||||
serial.setBaudRate(9600);
|
throw new IOException("Could not open port: "+portName);
|
||||||
if(!serial.openPort())
|
serial.setComPortTimeouts(
|
||||||
throw new IOException("Could not open port: "+portName);
|
SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
|
||||||
serial.setComPortTimeouts(
|
|
||||||
SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
|
in = new InputStreamLogger(serial.getInputStream());
|
||||||
|
out = new OutputStreamLogger(serial.getOutputStream());
|
||||||
in = new InputStreamLogger(serial.getInputStream());
|
|
||||||
out = new OutputStreamLogger(serial.getOutputStream());
|
Executors.newSingleThreadExecutor().execute(this);
|
||||||
|
}
|
||||||
Executors.newSingleThreadExecutor().execute(this);
|
|
||||||
}
|
public void close() {
|
||||||
|
if(serial != null) {
|
||||||
public void close() {
|
try {
|
||||||
if(serial != null) {
|
serial.closePort();
|
||||||
try {
|
in.close();
|
||||||
serial.closePort();
|
out.close();
|
||||||
in.close();
|
} catch (IOException e) {
|
||||||
out.close();
|
logger.log(Level.SEVERE, null, e);
|
||||||
} catch (IOException e) {
|
}
|
||||||
logger.log(Level.SEVERE, null, e);
|
}
|
||||||
}
|
serial = null;
|
||||||
}
|
in = null;
|
||||||
serial = null;
|
out = null;
|
||||||
in = null;
|
}
|
||||||
out = null;
|
|
||||||
}
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
public void run() {
|
String data;
|
||||||
try {
|
|
||||||
String data;
|
while (in != null && (data = readLine()) != null) {
|
||||||
|
if ((data.startsWith("+S") || data.startsWith("+T"))) {
|
||||||
while (in != null && (data = readLine()) != null) {
|
synchronized (this) {
|
||||||
if ((data.startsWith("+S") || data.startsWith("+T"))) {
|
this.notifyAll();
|
||||||
synchronized (this) {
|
}
|
||||||
this.notifyAll();
|
}
|
||||||
}
|
else {
|
||||||
}
|
if(!set.contains(data)) {
|
||||||
else {
|
TellstickProtocol protocol = parser.decode(data);
|
||||||
if(!set.contains(data)) {
|
if(protocol != null) {
|
||||||
TellstickProtocol protocol = parser.decode(data);
|
if (protocol.getTimestamp() < 0)
|
||||||
if(protocol != null) {
|
protocol.setTimestamp(System.currentTimeMillis());
|
||||||
if (protocol.getTimestamp() < 0)
|
set.add(data);
|
||||||
protocol.setTimestamp(System.currentTimeMillis());
|
|
||||||
set.add(data);
|
if (sensorListener != null && protocol instanceof HalSensor)
|
||||||
|
sensorListener.reportReceived((HalSensor) protocol);
|
||||||
if (sensorListener != null && protocol instanceof HalSensor)
|
else if (eventListener != null && protocol instanceof HalEvent)
|
||||||
sensorListener.reportReceived((HalSensor) protocol);
|
eventListener.reportReceived((HalEvent) protocol);
|
||||||
else if (eventListener != null && protocol instanceof HalEvent)
|
}
|
||||||
eventListener.reportReceived((HalEvent) protocol);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
}
|
logger.log(Level.SEVERE, null, e);
|
||||||
} catch (IOException e) {
|
}
|
||||||
logger.log(Level.SEVERE, null, e);
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
* There seems to be an issue with read(...) methods only read() is working
|
||||||
/**
|
*/
|
||||||
* There seems to be an issue with read(...) methods only read() is working
|
private String readLine() throws IOException {
|
||||||
*/
|
StringBuilder str = new StringBuilder(50);
|
||||||
private String readLine() throws IOException {
|
char c = 0;
|
||||||
StringBuilder str = new StringBuilder(50);
|
while((c = (char)in.read()) >= 0){
|
||||||
char c = 0;
|
switch(c) {
|
||||||
while((c = (char)in.read()) >= 0){
|
case '\n':
|
||||||
switch(c) {
|
case '\r':
|
||||||
case '\n':
|
if(str.length() > 0)
|
||||||
case '\r':
|
return str.toString();
|
||||||
if(str.length() > 0)
|
break;
|
||||||
return str.toString();
|
default:
|
||||||
break;
|
str.append(c);
|
||||||
default:
|
}
|
||||||
str.append(c);
|
}
|
||||||
}
|
return str.toString();
|
||||||
}
|
}
|
||||||
return str.toString();
|
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void send(HalEvent event) {
|
||||||
@Override
|
if(event instanceof TellstickProtocol)
|
||||||
public void send(HalEvent event) {
|
write((TellstickProtocol) event);
|
||||||
if(event instanceof TellstickProtocol)
|
}
|
||||||
write((TellstickProtocol) event);
|
public synchronized void write(TellstickProtocol prot) {
|
||||||
}
|
write(prot.encode());
|
||||||
public synchronized void write(TellstickProtocol prot) {
|
try {
|
||||||
write(prot.encode());
|
this.wait();
|
||||||
try {
|
} catch (InterruptedException e) {
|
||||||
this.wait();
|
logger.log(Level.SEVERE, null, e);
|
||||||
} catch (InterruptedException e) {
|
}
|
||||||
logger.log(Level.SEVERE, null, e);
|
}
|
||||||
}
|
public void write(String data) {
|
||||||
}
|
try {
|
||||||
public void write(String data) {
|
for(int i=0; i<data.length();i++)
|
||||||
try {
|
out.write(0xFF & data.charAt(i));
|
||||||
for(int i=0; i<data.length();i++)
|
out.write('\n');
|
||||||
out.write(0xFF & data.charAt(i));
|
out.flush();
|
||||||
out.write('\n');
|
} catch (IOException e) {
|
||||||
out.flush();
|
logger.log(Level.SEVERE, null, e);
|
||||||
} catch (IOException e) {
|
}
|
||||||
logger.log(Level.SEVERE, null, e);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void register(HalEvent event) {++registeredObjects;}
|
||||||
@Override
|
@Override
|
||||||
public void register(HalEvent event) {++registeredObjects;}
|
public void register(HalSensor sensor) {++registeredObjects;}
|
||||||
@Override
|
|
||||||
public void register(HalSensor sensor) {++registeredObjects;}
|
@Override
|
||||||
|
public void deregister(HalSensor sensor) {--registeredObjects;}
|
||||||
@Override
|
@Override
|
||||||
public void deregister(HalSensor sensor) {--registeredObjects;}
|
public void deregister(HalEvent event) {--registeredObjects;}
|
||||||
@Override
|
|
||||||
public void deregister(HalEvent event) {--registeredObjects;}
|
@Override
|
||||||
|
public int size() {
|
||||||
@Override
|
return registeredObjects;
|
||||||
public int size() {
|
}
|
||||||
return registeredObjects;
|
|
||||||
}
|
@Override
|
||||||
|
public void setListener(HalEventReportListener listener) {
|
||||||
@Override
|
eventListener = listener;
|
||||||
public void setListener(HalEventReportListener listener) {
|
}
|
||||||
eventListener = listener;
|
@Override
|
||||||
}
|
public void setListener(HalSensorReportListener listener) {
|
||||||
@Override
|
sensorListener = listener;
|
||||||
public void setListener(HalSensorReportListener listener) {
|
}
|
||||||
sensorListener = listener;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,177 +1,175 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.plugin.tellstick.protocols;
|
package se.hal.plugin.tellstick.protocols;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalEventController;
|
import se.hal.plugin.tellstick.TellstickProtocol;
|
||||||
import se.koc.hal.plugin.tellstick.TellstickProtocol;
|
import se.hal.struct.SwitchEvent;
|
||||||
import se.koc.hal.struct.DimmerEvent;
|
import zutil.ui.Configurator;
|
||||||
import se.koc.hal.struct.SwitchEvent;
|
|
||||||
import zutil.ui.Configurator;
|
/**
|
||||||
|
* Created by Ziver on 2015-02-18.
|
||||||
/**
|
*/
|
||||||
* Created by Ziver on 2015-02-18.
|
public class NexaSelfLearning extends TellstickProtocol implements SwitchEvent {
|
||||||
*/
|
|
||||||
public class NexaSelfLearning extends TellstickProtocol implements SwitchEvent {
|
@Configurator.Configurable("House code")
|
||||||
|
private int house = 0;
|
||||||
@Configurator.Configurable("House code")
|
@Configurator.Configurable("Group code")
|
||||||
private int house = 0;
|
private int group = 0;
|
||||||
@Configurator.Configurable("Group code")
|
@Configurator.Configurable("Unit code")
|
||||||
private int group = 0;
|
private int unit = 0;
|
||||||
@Configurator.Configurable("Unit code")
|
|
||||||
private int unit = 0;
|
private boolean enable = false;
|
||||||
|
|
||||||
private boolean enable = false;
|
|
||||||
|
public NexaSelfLearning() {
|
||||||
|
super("arctech", "selflearning");
|
||||||
public NexaSelfLearning() {
|
}
|
||||||
super("arctech", "selflearning");
|
|
||||||
}
|
|
||||||
|
public String encode(){
|
||||||
|
StringBuilder enc = new StringBuilder();
|
||||||
public String encode(){
|
enc.append(new char[]{'T', 127, 255, 24, 1});
|
||||||
StringBuilder enc = new StringBuilder();
|
|
||||||
enc.append(new char[]{'T', 127, 255, 24, 1});
|
enc.append((char)132);
|
||||||
|
|
||||||
enc.append((char)132);
|
// House
|
||||||
|
StringBuilder m = new StringBuilder();
|
||||||
// House
|
for (int i = 25; i >= 0; --i) {
|
||||||
StringBuilder m = new StringBuilder();
|
m.append( (house & (1 << i)) == 0 ? "01" : "10" );
|
||||||
for (int i = 25; i >= 0; --i) {
|
}
|
||||||
m.append( (house & (1 << i)) == 0 ? "01" : "10" );
|
// Group
|
||||||
}
|
m.append("01");
|
||||||
// Group
|
|
||||||
m.append("01");
|
// On or OFF
|
||||||
|
if (enable)
|
||||||
// On or OFF
|
m.append("10");
|
||||||
if (enable)
|
else
|
||||||
m.append("10");
|
m.append("01");
|
||||||
else
|
|
||||||
m.append("01");
|
// Unit
|
||||||
|
for (int i = 3; i >= 0; --i) {
|
||||||
// Unit
|
m.append( (unit & (1 << i)) == 0 ? "01" : "10" );
|
||||||
for (int i = 3; i >= 0; --i) {
|
}
|
||||||
m.append( (unit & (1 << i)) == 0 ? "01" : "10" );
|
|
||||||
}
|
// The number of data is odd add this to make it even
|
||||||
|
m.append("0");
|
||||||
// The number of data is odd add this to make it even
|
//01011001101001011010100110010101010101101001011010 01 01 1001011010 0
|
||||||
m.append("0");
|
|
||||||
//01011001101001011010100110010101010101101001011010 01 01 1001011010 0
|
char code = 9; // b1001, startcode
|
||||||
|
for (int i = 0; i < m.length(); ++i) {
|
||||||
char code = 9; // b1001, startcode
|
code <<= 4;
|
||||||
for (int i = 0; i < m.length(); ++i) {
|
if (m.charAt(i) == '1') {
|
||||||
code <<= 4;
|
code |= 0x08; // b1000
|
||||||
if (m.charAt(i) == '1') {
|
} else {
|
||||||
code |= 0x08; // b1000
|
code |= 0x0A; // b1010
|
||||||
} else {
|
}
|
||||||
code |= 0x0A; // b1010
|
if (i % 2 == 0) {
|
||||||
}
|
enc.append(code);
|
||||||
if (i % 2 == 0) {
|
code = 0x00;
|
||||||
enc.append(code);
|
}
|
||||||
code = 0x00;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
enc.append("+");
|
||||||
|
return enc.toString();
|
||||||
enc.append("+");
|
}
|
||||||
return enc.toString();
|
|
||||||
}
|
public void decode(byte[] data){
|
||||||
|
// Data positions
|
||||||
public void decode(byte[] data){
|
// house = 0xFFFFFFC0
|
||||||
// Data positions
|
// group = 0x00000020
|
||||||
// house = 0xFFFFFFC0
|
// method = 0x00000010
|
||||||
// group = 0x00000020
|
// unit = 0x0000000F
|
||||||
// method = 0x00000010
|
// ----------------h------------ g m --u-
|
||||||
// unit = 0x0000000F
|
// 0x2CE81990 - 00101100_11101000_00011001_10 0 1 0000 - ON
|
||||||
// ----------------h------------ g m --u-
|
// 0x2CE81980 - 00101100_11101000_00011001_10 0 0 0000 - OFF
|
||||||
// 0x2CE81990 - 00101100_11101000_00011001_10 0 1 0000 - ON
|
|
||||||
// 0x2CE81980 - 00101100_11101000_00011001_10 0 0 0000 - OFF
|
house = 0;
|
||||||
|
house |= (data[3] & 0xFF) << 18;
|
||||||
house = 0;
|
house |= (data[2] & 0xFF) << 10;
|
||||||
house |= (data[3] & 0xFF) << 18;
|
house |= (data[1] & 0xFF) << 2;
|
||||||
house |= (data[2] & 0xFF) << 10;
|
house |= (data[0] & 0xC0) >>> 6;
|
||||||
house |= (data[1] & 0xFF) << 2;
|
|
||||||
house |= (data[0] & 0xC0) >>> 6;
|
group = data[0] & 0x20;
|
||||||
|
group >>>= 5;
|
||||||
group = data[0] & 0x20;
|
|
||||||
group >>>= 5;
|
enable = (data[0] & 0x10) != 0;
|
||||||
|
|
||||||
enable = (data[0] & 0x10) != 0;
|
unit = data[0] & 0x0F;
|
||||||
|
unit++;
|
||||||
unit = data[0] & 0x0F;
|
}
|
||||||
unit++;
|
|
||||||
}
|
|
||||||
|
public int getHouse() {
|
||||||
|
return house;
|
||||||
public int getHouse() {
|
}
|
||||||
return house;
|
public void setHouse(int house) {
|
||||||
}
|
this.house = house;
|
||||||
public void setHouse(int house) {
|
}
|
||||||
this.house = house;
|
public int getGroup() {
|
||||||
}
|
return group;
|
||||||
public int getGroup() {
|
}
|
||||||
return group;
|
public void setGroup(int group) {
|
||||||
}
|
this.group = group;
|
||||||
public void setGroup(int group) {
|
}
|
||||||
this.group = group;
|
public int getUnit() {
|
||||||
}
|
return unit;
|
||||||
public int getUnit() {
|
}
|
||||||
return unit;
|
public void setUnit(int unit) {
|
||||||
}
|
this.unit = unit;
|
||||||
public void setUnit(int unit) {
|
}
|
||||||
this.unit = unit;
|
|
||||||
}
|
public boolean isOn() {
|
||||||
|
return enable;
|
||||||
public boolean isOn() {
|
}
|
||||||
return enable;
|
public void turnOn() {
|
||||||
}
|
enable = true;
|
||||||
public void turnOn() {
|
}
|
||||||
enable = true;
|
public void turnOff() {
|
||||||
}
|
enable = false;
|
||||||
public void turnOff() {
|
}
|
||||||
enable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return "protocol:arctech;model:selflearning;" +
|
||||||
public String toString(){
|
"house:"+house+
|
||||||
return "protocol:arctech;model:selflearning;" +
|
";group:"+group+
|
||||||
"house:"+house+
|
";unit:"+unit+
|
||||||
";group:"+group+
|
";method:"+enable;
|
||||||
";unit:"+unit+
|
}
|
||||||
";method:"+enable;
|
|
||||||
}
|
public boolean equals(Object obj){
|
||||||
|
if(obj instanceof NexaSelfLearning)
|
||||||
public boolean equals(Object obj){
|
return ((NexaSelfLearning) obj).house == house &&
|
||||||
if(obj instanceof NexaSelfLearning)
|
((NexaSelfLearning)obj).unit == unit;
|
||||||
return ((NexaSelfLearning) obj).house == house &&
|
return false;
|
||||||
((NexaSelfLearning)obj).unit == unit;
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public double getData() {
|
||||||
@Override
|
return (enable ? 1 : 0);
|
||||||
public double getData() {
|
}
|
||||||
return (enable ? 1 : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
package se.koc.hal.plugin.tellstick.protocols;
|
package se.hal.plugin.tellstick.protocols;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalSensor;
|
import se.hal.plugin.tellstick.TellstickProtocol;
|
||||||
import se.koc.hal.intf.HalSensorController;
|
import se.hal.struct.PowerConsumptionSensor;
|
||||||
import se.koc.hal.plugin.tellstick.TellstickProtocol;
|
|
||||||
import se.koc.hal.plugin.tellstick.TellstickSerialComm;
|
|
||||||
import se.koc.hal.struct.PowerConsumptionSensor;
|
|
||||||
import zutil.parser.DataNode;
|
|
||||||
import zutil.ui.Configurator;
|
import zutil.ui.Configurator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -20,9 +20,9 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.struct;
|
package se.hal.struct;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalEvent;
|
import se.hal.intf.HalEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-05-07.
|
* Created by Ziver on 2015-05-07.
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package se.koc.hal.struct;
|
package se.hal.struct;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalEvent;
|
import se.hal.intf.HalEvent;
|
||||||
import se.koc.hal.intf.HalEventController;
|
import se.hal.intf.HalEventController;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.bean.DBBean;
|
import zutil.db.bean.DBBean;
|
||||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||||
|
|
@ -10,8 +10,6 @@ import zutil.io.StringOutputStream;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
import zutil.parser.json.JSONObjectInputStream;
|
import zutil.parser.json.JSONObjectInputStream;
|
||||||
import zutil.parser.json.JSONObjectOutputStream;
|
import zutil.parser.json.JSONObjectOutputStream;
|
||||||
import zutil.parser.json.JSONParser;
|
|
||||||
import zutil.parser.json.JSONWriter;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package se.koc.hal.struct;
|
package se.hal.struct;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalSensor;
|
import se.hal.intf.HalSensor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-03.
|
* Created by Ziver on 2015-12-03.
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package se.koc.hal.struct;
|
package se.hal.struct;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.intf.HalSensor;
|
import se.hal.intf.HalSensor;
|
||||||
import se.koc.hal.intf.HalSensorController;
|
import se.hal.intf.HalSensorController;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.bean.DBBean;
|
import zutil.db.bean.DBBean;
|
||||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||||
|
|
@ -10,13 +10,8 @@ import zutil.db.handler.SimpleSQLResult;
|
||||||
import zutil.io.StringInputStream;
|
import zutil.io.StringInputStream;
|
||||||
import zutil.io.StringOutputStream;
|
import zutil.io.StringOutputStream;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
import zutil.parser.DataNode;
|
|
||||||
import zutil.parser.json.JSONObjectInputStream;
|
import zutil.parser.json.JSONObjectInputStream;
|
||||||
import zutil.parser.json.JSONObjectOutputStream;
|
import zutil.parser.json.JSONObjectOutputStream;
|
||||||
import zutil.parser.json.JSONParser;
|
|
||||||
import zutil.parser.json.JSONWriter;
|
|
||||||
import zutil.ui.Configurator;
|
|
||||||
import zutil.ui.Configurator.ConfigurationParam;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
|
@ -20,11 +20,9 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.struct;
|
package se.hal.struct;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalEvent;
|
import se.hal.intf.HalEvent;
|
||||||
import se.koc.hal.plugin.tellstick.TellstickSerialComm;
|
|
||||||
import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-05-07.
|
* Created by Ziver on 2015-05-07.
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package se.koc.hal.struct;
|
package se.hal.struct;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalSensor;
|
import se.hal.intf.HalSensor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-03.
|
* Created by Ziver on 2015-12-03.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.struct;
|
package se.hal.struct;
|
||||||
|
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.bean.DBBean;
|
import zutil.db.bean.DBBean;
|
||||||
|
|
@ -1,123 +1,123 @@
|
||||||
package se.koc.hal.stt;
|
package se.hal.stt;
|
||||||
|
|
||||||
import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
|
import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
|
||||||
import com.darkprograms.speech.recognizer.FlacEncoder;
|
import com.darkprograms.speech.recognizer.FlacEncoder;
|
||||||
import com.darkprograms.speech.recognizer.GSpeechDuplex;
|
import com.darkprograms.speech.recognizer.GSpeechDuplex;
|
||||||
import com.darkprograms.speech.recognizer.GSpeechResponseListener;
|
import com.darkprograms.speech.recognizer.GSpeechResponseListener;
|
||||||
import com.darkprograms.speech.recognizer.GoogleResponse;
|
import com.darkprograms.speech.recognizer.GoogleResponse;
|
||||||
import se.koc.hal.intf.HalSpeachToText;
|
import se.hal.intf.HalSpeachToText;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioFileFormat;
|
import javax.sound.sampled.AudioFileFormat;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class GoogleSTTClient implements HalSpeachToText, GSpeechResponseListener {
|
public class GoogleSTTClient implements HalSpeachToText, GSpeechResponseListener {
|
||||||
private MicrophoneAnalyzer mic;
|
private MicrophoneAnalyzer mic;
|
||||||
private File audioFile;
|
private File audioFile;
|
||||||
private File flacFile;
|
private File flacFile;
|
||||||
private int ambientVolume;
|
private int ambientVolume;
|
||||||
private GSpeechDuplex google;
|
private GSpeechDuplex google;
|
||||||
private String response;
|
private String response;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initSTT() {
|
public void initSTT() {
|
||||||
try{
|
try{
|
||||||
this.mic = new MicrophoneAnalyzer(AudioFileFormat.Type.WAVE);
|
this.mic = new MicrophoneAnalyzer(AudioFileFormat.Type.WAVE);
|
||||||
this.audioFile = File.createTempFile("input", "wav");
|
this.audioFile = File.createTempFile("input", "wav");
|
||||||
this.flacFile = File.createTempFile("input", "flac");
|
this.flacFile = File.createTempFile("input", "flac");
|
||||||
|
|
||||||
this.google = new GSpeechDuplex("AIzaSyBGAQ29aMvts9MObj739_HYa-tvNeEI0X8");
|
this.google = new GSpeechDuplex("AIzaSyBGAQ29aMvts9MObj739_HYa-tvNeEI0X8");
|
||||||
this.google.addResponseListener(this);
|
this.google.addResponseListener(this);
|
||||||
|
|
||||||
/*System.out.println("Messuring ambient noise...");
|
/*System.out.println("Messuring ambient noise...");
|
||||||
mic.captureAudioToFile(audioFile);
|
mic.captureAudioToFile(audioFile);
|
||||||
Thread.sleep(300);
|
Thread.sleep(300);
|
||||||
ambientVolume = mic.getAudioVolume();
|
ambientVolume = mic.getAudioVolume();
|
||||||
Thread.sleep(300);
|
Thread.sleep(300);
|
||||||
mic.close();*/
|
mic.close();*/
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized String listen() {
|
public synchronized String listen() {
|
||||||
try {
|
try {
|
||||||
String request = null;
|
String request = null;
|
||||||
while(request == null){
|
while(request == null){
|
||||||
|
|
||||||
/*mic.captureAudioToFile(audioFile);
|
/*mic.captureAudioToFile(audioFile);
|
||||||
try{Thread.sleep(2000);}catch(Exception e){}
|
try{Thread.sleep(2000);}catch(Exception e){}
|
||||||
mic.close();*/
|
mic.close();*/
|
||||||
|
|
||||||
FlacEncoder flacEncoder = new FlacEncoder();
|
FlacEncoder flacEncoder = new FlacEncoder();
|
||||||
//flacEncoder.convertWaveToFlac(audioFile, flacFile);
|
//flacEncoder.convertWaveToFlac(audioFile, flacFile);
|
||||||
flacEncoder.convertWaveToFlac(FileUtil.find("edu/cmu/sphinx/demo/speakerid/test.wav"), flacFile);
|
flacEncoder.convertWaveToFlac(FileUtil.find("edu/cmu/sphinx/demo/speakerid/test.wav"), flacFile);
|
||||||
|
|
||||||
response = null;
|
response = null;
|
||||||
google.recognize(flacFile, 8000);
|
google.recognize(flacFile, 8000);
|
||||||
this.wait();
|
this.wait();
|
||||||
|
|
||||||
flacFile.delete();
|
flacFile.delete();
|
||||||
audioFile.delete();
|
audioFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String thresholdListen(){
|
public String thresholdListen(){
|
||||||
try{
|
try{
|
||||||
boolean speaking = false;
|
boolean speaking = false;
|
||||||
while(!speaking){
|
while(!speaking){
|
||||||
mic.captureAudioToFile(audioFile);
|
mic.captureAudioToFile(audioFile);
|
||||||
System.out.print("_");
|
System.out.print("_");
|
||||||
|
|
||||||
final int THRESHOLD = 10; //YOUR THRESHOLD VALUE.
|
final int THRESHOLD = 10; //YOUR THRESHOLD VALUE.
|
||||||
mic.open();
|
mic.open();
|
||||||
|
|
||||||
int speakingVolume = -2;
|
int speakingVolume = -2;
|
||||||
|
|
||||||
do{
|
do{
|
||||||
int volume = mic.getAudioVolume();
|
int volume = mic.getAudioVolume();
|
||||||
if(volume>ambientVolume+THRESHOLD){
|
if(volume>ambientVolume+THRESHOLD){
|
||||||
speakingVolume = volume;
|
speakingVolume = volume;
|
||||||
speaking = true;
|
speaking = true;
|
||||||
System.out.print(".");
|
System.out.print(".");
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
if(speaking && volume+THRESHOLD<speakingVolume){
|
if(speaking && volume+THRESHOLD<speakingVolume){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}while(speaking);
|
}while(speaking);
|
||||||
mic.close();
|
mic.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mic.close();
|
mic.close();
|
||||||
|
|
||||||
FlacEncoder flacEncoder = new FlacEncoder();
|
FlacEncoder flacEncoder = new FlacEncoder();
|
||||||
flacEncoder.convertWaveToFlac(audioFile, flacFile);
|
flacEncoder.convertWaveToFlac(audioFile, flacFile);
|
||||||
|
|
||||||
response = null;
|
response = null;
|
||||||
google.recognize(flacFile, 8000);
|
google.recognize(flacFile, 8000);
|
||||||
this.wait();
|
this.wait();
|
||||||
|
|
||||||
flacFile.delete();
|
flacFile.delete();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(GoogleResponse googleResponse) {
|
public void onResponse(GoogleResponse googleResponse) {
|
||||||
response = googleResponse.getResponse();
|
response = googleResponse.getResponse();
|
||||||
this.notifyAll();
|
this.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,49 +1,49 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 ezivkoc
|
* Copyright (c) 2015 ezivkoc
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.stt;
|
package se.hal.stt;
|
||||||
|
|
||||||
import se.koc.hal.intf.HalSpeachToText;
|
import se.hal.intf.HalSpeachToText;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
public class ManualSTTClient implements HalSpeachToText {
|
public class ManualSTTClient implements HalSpeachToText {
|
||||||
private BufferedReader in;
|
private BufferedReader in;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initSTT() {
|
public void initSTT() {
|
||||||
// open up standard input
|
// open up standard input
|
||||||
in = new BufferedReader(new InputStreamReader(System.in));
|
in = new BufferedReader(new InputStreamReader(System.in));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String listen() {
|
public String listen() {
|
||||||
try {
|
try {
|
||||||
return in.readLine();
|
return in.readLine();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,68 +1,68 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.stt;
|
package se.hal.stt;
|
||||||
|
|
||||||
import edu.cmu.sphinx.api.Configuration;
|
import edu.cmu.sphinx.api.Configuration;
|
||||||
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
|
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
|
||||||
import edu.cmu.sphinx.api.SpeechResult;
|
import edu.cmu.sphinx.api.SpeechResult;
|
||||||
import se.koc.hal.intf.HalSpeachToText;
|
import se.hal.intf.HalSpeachToText;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-05-08.
|
* Created by Ziver on 2015-05-08.
|
||||||
*/
|
*/
|
||||||
public class Sphinx4STTClient implements HalSpeachToText {
|
public class Sphinx4STTClient implements HalSpeachToText {
|
||||||
private LiveSpeechRecognizer recognizer;
|
private LiveSpeechRecognizer recognizer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initSTT() {
|
public void initSTT() {
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
|
|
||||||
// Set path to acoustic model.
|
// Set path to acoustic model.
|
||||||
configuration.setAcousticModelPath("resource:/sphinx-models/en-us");
|
configuration.setAcousticModelPath("resource:/sphinx-models/en-us");
|
||||||
// Set path to dictionary.
|
// Set path to dictionary.
|
||||||
configuration.setDictionaryPath("resource:/sphinx-models/cmudict-en-us.dict");
|
configuration.setDictionaryPath("resource:/sphinx-models/cmudict-en-us.dict");
|
||||||
// Set language model.
|
// Set language model.
|
||||||
configuration.setLanguageModelPath("resource:/sphinx-models/en-us.lm.dmp");
|
configuration.setLanguageModelPath("resource:/sphinx-models/en-us.lm.dmp");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
recognizer = new LiveSpeechRecognizer(configuration);
|
recognizer = new LiveSpeechRecognizer(configuration);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String listen() {
|
public String listen() {
|
||||||
// Start recognition process pruning previously cached data.
|
// Start recognition process pruning previously cached data.
|
||||||
recognizer.startRecognition(true);
|
recognizer.startRecognition(true);
|
||||||
|
|
||||||
SpeechResult result = recognizer.getResult();
|
SpeechResult result = recognizer.getResult();
|
||||||
// Pause recognition process. It can be resumed then with startRecognition(false).
|
// Pause recognition process. It can be resumed then with startRecognition(false).
|
||||||
recognizer.stopRecognition();
|
recognizer.stopRecognition();
|
||||||
return result.getHypothesis();
|
return result.getHypothesis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,101 +1,101 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 ezivkoc
|
* Copyright (c) 2013 ezivkoc
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.tts;
|
package se.hal.tts;
|
||||||
|
|
||||||
import com.darkprograms.speech.synthesiser.SynthesiserV2;
|
import com.darkprograms.speech.synthesiser.SynthesiserV2;
|
||||||
import javafx.embed.swing.JFXPanel;
|
import javafx.embed.swing.JFXPanel;
|
||||||
import javafx.scene.media.Media;
|
import javafx.scene.media.Media;
|
||||||
import javafx.scene.media.MediaPlayer;
|
import javafx.scene.media.MediaPlayer;
|
||||||
import se.koc.hal.intf.HalTextToSpeach;
|
import se.hal.intf.HalTextToSpeach;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
* User: ezivkoc
|
* User: ezivkoc
|
||||||
* Date: 2013-12-17
|
* Date: 2013-12-17
|
||||||
* Time: 13:45
|
* Time: 13:45
|
||||||
*/
|
*/
|
||||||
public class GoogleTTSClient implements HalTextToSpeach {
|
public class GoogleTTSClient implements HalTextToSpeach {
|
||||||
private static final String API_KEY = "AIzaSyBGAQ29aMvts9MObj739_HYa-tvNeEI0X8";
|
private static final String API_KEY = "AIzaSyBGAQ29aMvts9MObj739_HYa-tvNeEI0X8";
|
||||||
|
|
||||||
private SynthesiserV2 synthesiser;
|
private SynthesiserV2 synthesiser;
|
||||||
private File tmpAudioFile;
|
private File tmpAudioFile;
|
||||||
|
|
||||||
|
|
||||||
public void initTTS() {
|
public void initTTS() {
|
||||||
try {
|
try {
|
||||||
// JavaFX should be initialized
|
// JavaFX should be initialized
|
||||||
JFXPanel fxPanel = new JFXPanel();
|
JFXPanel fxPanel = new JFXPanel();
|
||||||
|
|
||||||
synthesiser = new SynthesiserV2(API_KEY);
|
synthesiser = new SynthesiserV2(API_KEY);
|
||||||
tmpAudioFile = File.createTempFile("tts", "tmp");
|
tmpAudioFile = File.createTempFile("tts", "tmp");
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void speak(String msg) {
|
public void speak(String msg) {
|
||||||
try{
|
try{
|
||||||
String language = synthesiser.detectLanguage(msg);
|
String language = synthesiser.detectLanguage(msg);
|
||||||
|
|
||||||
InputStream is = synthesiser.getMP3Data(msg);
|
InputStream is = synthesiser.getMP3Data(msg);
|
||||||
BufferedInputStream buff = new BufferedInputStream(is);
|
BufferedInputStream buff = new BufferedInputStream(is);
|
||||||
DataInputStream di = new DataInputStream(buff);
|
DataInputStream di = new DataInputStream(buff);
|
||||||
|
|
||||||
|
|
||||||
FileOutputStream fos = new FileOutputStream(tmpAudioFile);
|
FileOutputStream fos = new FileOutputStream(tmpAudioFile);
|
||||||
while(di.available() != 0){
|
while(di.available() != 0){
|
||||||
fos.write(di.readByte());
|
fos.write(di.readByte());
|
||||||
}
|
}
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
URL resource = tmpAudioFile.toURI().toURL();
|
URL resource = tmpAudioFile.toURI().toURL();
|
||||||
Media media = new Media(resource.toURI().toString());
|
Media media = new Media(resource.toURI().toString());
|
||||||
final MediaPlayer mediaPlayer = new MediaPlayer(media);
|
final MediaPlayer mediaPlayer = new MediaPlayer(media);
|
||||||
mediaPlayer.play();
|
mediaPlayer.play();
|
||||||
|
|
||||||
mediaPlayer.setOnEndOfMedia(new Runnable() {
|
mediaPlayer.setOnEndOfMedia(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
mediaPlayer.stop();
|
mediaPlayer.stop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
while(mediaPlayer.getStatus() != MediaPlayer.Status.STOPPED){
|
while(mediaPlayer.getStatus() != MediaPlayer.Status.STOPPED){
|
||||||
try{Thread.sleep(200);}catch(Exception e){}
|
try{Thread.sleep(200);}catch(Exception e){}
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(URISyntaxException e){
|
}catch(URISyntaxException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,71 +1,71 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.tts;
|
package se.hal.tts;
|
||||||
|
|
||||||
import marytts.LocalMaryInterface;
|
import marytts.LocalMaryInterface;
|
||||||
import marytts.MaryInterface;
|
import marytts.MaryInterface;
|
||||||
import marytts.exceptions.MaryConfigurationException;
|
import marytts.exceptions.MaryConfigurationException;
|
||||||
import marytts.exceptions.SynthesisException;
|
import marytts.exceptions.SynthesisException;
|
||||||
import marytts.util.data.audio.AudioPlayer;
|
import marytts.util.data.audio.AudioPlayer;
|
||||||
import se.koc.hal.intf.HalTextToSpeach;
|
import se.hal.intf.HalTextToSpeach;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioInputStream;
|
import javax.sound.sampled.AudioInputStream;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
* User: ezivkoc
|
* User: ezivkoc
|
||||||
* Date: 2013-12-17
|
* Date: 2013-12-17
|
||||||
* Time: 14:36
|
* Time: 14:36
|
||||||
*/
|
*/
|
||||||
public class MaryLocalTTSClient implements HalTextToSpeach {
|
public class MaryLocalTTSClient implements HalTextToSpeach {
|
||||||
private MaryInterface marytts;
|
private MaryInterface marytts;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initTTS() {
|
public void initTTS() {
|
||||||
try {
|
try {
|
||||||
marytts = new LocalMaryInterface();
|
marytts = new LocalMaryInterface();
|
||||||
Set<String> voices = marytts.getAvailableVoices();
|
Set<String> voices = marytts.getAvailableVoices();
|
||||||
marytts.setVoice(voices.iterator().next());
|
marytts.setVoice(voices.iterator().next());
|
||||||
} catch (MaryConfigurationException e) {
|
} catch (MaryConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void speak(String msg) {
|
public void speak(String msg) {
|
||||||
try {
|
try {
|
||||||
AudioInputStream audio = marytts.generateAudio(msg);
|
AudioInputStream audio = marytts.generateAudio(msg);
|
||||||
AudioPlayer player = new AudioPlayer(audio);
|
AudioPlayer player = new AudioPlayer(audio);
|
||||||
player.start();
|
player.start();
|
||||||
player.join();
|
player.join();
|
||||||
|
|
||||||
} catch (SynthesisException e) {
|
} catch (SynthesisException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,72 +1,72 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 ezivkoc
|
* Copyright (c) 2013 ezivkoc
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.tts;
|
package se.hal.tts;
|
||||||
|
|
||||||
import marytts.MaryInterface;
|
import marytts.MaryInterface;
|
||||||
import marytts.client.RemoteMaryInterface;
|
import marytts.client.RemoteMaryInterface;
|
||||||
import marytts.exceptions.SynthesisException;
|
import marytts.exceptions.SynthesisException;
|
||||||
import marytts.util.data.audio.AudioPlayer;
|
import marytts.util.data.audio.AudioPlayer;
|
||||||
import se.koc.hal.intf.HalTextToSpeach;
|
import se.hal.intf.HalTextToSpeach;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioInputStream;
|
import javax.sound.sampled.AudioInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
* User: ezivkoc
|
* User: ezivkoc
|
||||||
* Date: 2013-12-17
|
* Date: 2013-12-17
|
||||||
* Time: 14:36
|
* Time: 14:36
|
||||||
*/
|
*/
|
||||||
public class MaryRemoteTTSClient implements HalTextToSpeach {
|
public class MaryRemoteTTSClient implements HalTextToSpeach {
|
||||||
private MaryInterface marytts;
|
private MaryInterface marytts;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initTTS() {
|
public void initTTS() {
|
||||||
try {
|
try {
|
||||||
marytts = new RemoteMaryInterface("127.0.0.1", 59125);
|
marytts = new RemoteMaryInterface("127.0.0.1", 59125);
|
||||||
|
|
||||||
Set<String> voices = marytts.getAvailableVoices();
|
Set<String> voices = marytts.getAvailableVoices();
|
||||||
marytts.setVoice(voices.iterator().next());
|
marytts.setVoice(voices.iterator().next());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void speak(String msg) {
|
public synchronized void speak(String msg) {
|
||||||
try {
|
try {
|
||||||
AudioInputStream audio = marytts.generateAudio(msg);
|
AudioInputStream audio = marytts.generateAudio(msg);
|
||||||
AudioPlayer player = new AudioPlayer(audio);
|
AudioPlayer player = new AudioPlayer(audio);
|
||||||
player.start();
|
player.start();
|
||||||
player.join();
|
player.join();
|
||||||
|
|
||||||
} catch (SynthesisException e) {
|
} catch (SynthesisException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.util;
|
package se.hal.util;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package se.koc.hal.plugin.tellstick;
|
package se.hal.plugin.tellstick;
|
||||||
|
|
||||||
import se.koc.hal.plugin.tellstick.protocols.NexaSelfLearning;
|
import se.hal.plugin.tellstick.protocols.NexaSelfLearning;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-11-19.
|
* Created by Ziver on 2015-11-19.
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
package se.koc.hal.plugin.tellstick;
|
package se.hal.plugin.tellstick;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.koc.hal.intf.HalSensor;
|
import se.hal.intf.HalSensor;
|
||||||
import se.koc.hal.intf.HalSensorController;
|
import se.hal.intf.HalSensorReportListener;
|
||||||
import se.koc.hal.intf.HalSensorReportListener;
|
import se.hal.plugin.tellstick.protocols.Oregon0x1A2D;
|
||||||
import se.koc.hal.plugin.tellstick.protocols.Oregon0x1A2D;
|
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.log.CompactLogFormatter;
|
import zutil.log.CompactLogFormatter;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
@ -1,67 +1,67 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.plugin.tellstick.protocols;
|
package se.hal.plugin.tellstick.protocols;
|
||||||
|
|
||||||
import zutil.converters.Converter;
|
import zutil.converters.Converter;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class NexaSelfLearningTest {
|
public class NexaSelfLearningTest {
|
||||||
|
|
||||||
@org.junit.Test
|
@org.junit.Test
|
||||||
public void testEncode() throws Exception {
|
public void testEncode() throws Exception {
|
||||||
NexaSelfLearning nexa = new NexaSelfLearning();
|
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||||
nexa.setHouse(11772006);
|
nexa.setHouse(11772006);
|
||||||
nexa.setUnit(3);
|
nexa.setUnit(3);
|
||||||
nexa.turnOn();
|
nexa.turnOn();
|
||||||
|
|
||||||
assertArrayEquals(
|
assertArrayEquals(
|
||||||
new char[]{
|
new char[]{
|
||||||
84, 127, 255, 24, 1, 132, 154, 138, 136, 170,
|
84, 127, 255, 24, 1, 132, 154, 138, 136, 170,
|
||||||
136, 168, 170, 138, 136, 168, 168, 170, 136, 170,
|
136, 168, 170, 138, 136, 168, 168, 170, 136, 170,
|
||||||
138, 138, 138, 138, 138, 136, 168, 170, 138, 136,
|
138, 138, 138, 138, 138, 136, 168, 170, 138, 136,
|
||||||
168, 170, 138, 136, 170, 138, 136, 168, 170, 43},
|
168, 170, 138, 136, 170, 138, 136, 168, 170, 43},
|
||||||
nexa.encode().toCharArray()
|
nexa.encode().toCharArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@org.junit.Test
|
@org.junit.Test
|
||||||
public void decode_ON() throws Exception {
|
public void decode_ON() throws Exception {
|
||||||
NexaSelfLearning nexa = new NexaSelfLearning();
|
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||||
nexa.decode(Converter.hexToByte("0x2CE81990"));
|
nexa.decode(Converter.hexToByte("0x2CE81990"));
|
||||||
|
|
||||||
assertEquals("House Code", 11772006, nexa.getHouse());
|
assertEquals("House Code", 11772006, nexa.getHouse());
|
||||||
assertEquals("Unit Code", 1, nexa.getUnit());
|
assertEquals("Unit Code", 1, nexa.getUnit());
|
||||||
assertTrue("Enabled", nexa.isOn());
|
assertTrue("Enabled", nexa.isOn());
|
||||||
}
|
}
|
||||||
@org.junit.Test
|
@org.junit.Test
|
||||||
public void decode_OFF() throws Exception {
|
public void decode_OFF() throws Exception {
|
||||||
NexaSelfLearning nexa = new NexaSelfLearning();
|
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||||
nexa.decode(Converter.hexToByte("0x2CE81980"));
|
nexa.decode(Converter.hexToByte("0x2CE81980"));
|
||||||
|
|
||||||
assertEquals("House Code", 11772006, nexa.getHouse());
|
assertEquals("House Code", 11772006, nexa.getHouse());
|
||||||
assertEquals("Unit Code", 1, nexa.getUnit());
|
assertEquals("Unit Code", 1, nexa.getUnit());
|
||||||
assertFalse("Enabled", nexa.isOn());
|
assertFalse("Enabled", nexa.isOn());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,83 +1,83 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.test;
|
package se.hal.test;
|
||||||
|
|
||||||
import zutil.io.DynamicByteArrayStream;
|
import zutil.io.DynamicByteArrayStream;
|
||||||
|
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
* User: ezivkoc
|
* User: ezivkoc
|
||||||
* Date: 2013-12-17
|
* Date: 2013-12-17
|
||||||
* Time: 11:24
|
* Time: 11:24
|
||||||
*/
|
*/
|
||||||
public class GoogleTTSTest {
|
public class GoogleTTSTest {
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
try {
|
try {
|
||||||
/* URL url = new URL("http://translate.google.com/translate_tts?q=I+love+techcrunch");
|
/* URL url = new URL("http://translate.google.com/translate_tts?q=I+love+techcrunch");
|
||||||
InputStream in = url.openStream();
|
InputStream in = url.openStream();
|
||||||
byte[] data = getContent(in);
|
byte[] data = getContent(in);
|
||||||
in.close();
|
in.close();
|
||||||
*/
|
*/
|
||||||
Clip push = AudioSystem.getClip();
|
Clip push = AudioSystem.getClip();
|
||||||
|
|
||||||
URL url = new URL("http://translate.google.com/translate_tts?ie=UTF-8&q=Hello%20World&tl=en-us");
|
URL url = new URL("http://translate.google.com/translate_tts?ie=UTF-8&q=Hello%20World&tl=en-us");
|
||||||
URLConnection con = url.openConnection();
|
URLConnection con = url.openConnection();
|
||||||
con.setRequestProperty("Cookie", "JSESSIONID=UX61oaN8vRhLE5pYXAjTWg; _ga=GA1.3.53937642.1385651778; HSID=AINSMauAFJWBs84WQ; APISID=RgytV3HJnm0dWjVr/AtidsIB_LJQzDmBMc; NID=67=R0kMLqIXXiOkrU8jlk4vgqLUiWUYUZRvxjf1Un0DQbQxGKt9pXXzDv-v0zSCSqLi_YNzcZujTDDr9r_KGsiPhEMfk-oKQSKvHe-DVVuwHZb2UZraJKCBAb6mPJO6AxBExoXHzU2pHd-DI1yIMxuLyVJA9RxhM_2kB4h7U0w9WiWqRNN7sU5DPVeLpF_ScW1VH9_igIR2ACK0WHvmoZXBjXDDrnUiVJt9DjkbMpHxU1o_1PnuUXi5FmfJLjrQspI; SID=DQAAANgAAADcaXZk9dA01UfdydUwIH32OGbA0k6mhbV2GSsiqcGYTUhNqLn_Z9TAlUsizBVoG-3g-ghXzpev46P--fqcR4UACZ2iVawFbfUB44B2hBmQQsFbyjGop1smPLu3cJORBLUKQ4PiZQb23GtXYg28prWlK3IFj8Wc3AHY5yoIpnssRY24k9DybwSSVt2Ww7c4ySzfw4uXxwtbSDTy0q8lmdAorjT4R6DCJwhaCGV4ysexY-vJaQE2kiRe3fPY2z9jQ6Mi9z_XjGRamLTI_AvJj-_XdQIfv0ZSo7JiEEjTUMb10Q; PREF=ID=8bf4d3a7414e8137:U=4ebb392cf34740cf:LD=sv:CR=2:TM=1368543367:LM=1387278509:GM=1:SG=1:S=fpteokIgX46FW8tp");
|
con.setRequestProperty("Cookie", "JSESSIONID=UX61oaN8vRhLE5pYXAjTWg; _ga=GA1.3.53937642.1385651778; HSID=AINSMauAFJWBs84WQ; APISID=RgytV3HJnm0dWjVr/AtidsIB_LJQzDmBMc; NID=67=R0kMLqIXXiOkrU8jlk4vgqLUiWUYUZRvxjf1Un0DQbQxGKt9pXXzDv-v0zSCSqLi_YNzcZujTDDr9r_KGsiPhEMfk-oKQSKvHe-DVVuwHZb2UZraJKCBAb6mPJO6AxBExoXHzU2pHd-DI1yIMxuLyVJA9RxhM_2kB4h7U0w9WiWqRNN7sU5DPVeLpF_ScW1VH9_igIR2ACK0WHvmoZXBjXDDrnUiVJt9DjkbMpHxU1o_1PnuUXi5FmfJLjrQspI; SID=DQAAANgAAADcaXZk9dA01UfdydUwIH32OGbA0k6mhbV2GSsiqcGYTUhNqLn_Z9TAlUsizBVoG-3g-ghXzpev46P--fqcR4UACZ2iVawFbfUB44B2hBmQQsFbyjGop1smPLu3cJORBLUKQ4PiZQb23GtXYg28prWlK3IFj8Wc3AHY5yoIpnssRY24k9DybwSSVt2Ww7c4ySzfw4uXxwtbSDTy0q8lmdAorjT4R6DCJwhaCGV4ysexY-vJaQE2kiRe3fPY2z9jQ6Mi9z_XjGRamLTI_AvJj-_XdQIfv0ZSo7JiEEjTUMb10Q; PREF=ID=8bf4d3a7414e8137:U=4ebb392cf34740cf:LD=sv:CR=2:TM=1368543367:LM=1387278509:GM=1:SG=1:S=fpteokIgX46FW8tp");
|
||||||
con.connect();
|
con.connect();
|
||||||
|
|
||||||
|
|
||||||
AudioInputStream audioPush = AudioSystem.getAudioInputStream(con.getInputStream());
|
AudioInputStream audioPush = AudioSystem.getAudioInputStream(con.getInputStream());
|
||||||
|
|
||||||
push.open(audioPush);
|
push.open(audioPush);
|
||||||
push.start();
|
push.start();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (UnsupportedAudioFileException e) {
|
} catch (UnsupportedAudioFileException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (LineUnavailableException e) {
|
} catch (LineUnavailableException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getContent(InputStream stream) throws IOException{
|
public static byte[] getContent(InputStream stream) throws IOException{
|
||||||
BufferedInputStream in = new BufferedInputStream(stream);
|
BufferedInputStream in = new BufferedInputStream(stream);
|
||||||
byte[] tmp = new byte[256];
|
byte[] tmp = new byte[256];
|
||||||
int len;
|
int len;
|
||||||
DynamicByteArrayStream buff = new DynamicByteArrayStream();
|
DynamicByteArrayStream buff = new DynamicByteArrayStream();
|
||||||
|
|
||||||
while((len=in.read(tmp)) != -1){
|
while((len=in.read(tmp)) != -1){
|
||||||
buff.append(tmp, 0, len);
|
buff.append(tmp, 0, len);
|
||||||
}
|
}
|
||||||
return buff.getBytes();
|
return buff.getBytes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,198 +1,198 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.test;
|
package se.hal.test;
|
||||||
|
|
||||||
import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
|
import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
|
||||||
import com.darkprograms.speech.recognizer.FlacEncoder;
|
import com.darkprograms.speech.recognizer.FlacEncoder;
|
||||||
import com.darkprograms.speech.recognizer.GoogleResponse;
|
import com.darkprograms.speech.recognizer.GoogleResponse;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioFileFormat;
|
import javax.sound.sampled.AudioFileFormat;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class JarvisRecognizerTest {
|
public class JarvisRecognizerTest {
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
try {
|
try {
|
||||||
new JarvisRecognizerTest();
|
new JarvisRecognizerTest();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JarvisRecognizerTest() throws Exception{
|
public JarvisRecognizerTest() throws Exception{
|
||||||
MicrophoneAnalyzer mic = new MicrophoneAnalyzer(AudioFileFormat.Type.WAVE);
|
MicrophoneAnalyzer mic = new MicrophoneAnalyzer(AudioFileFormat.Type.WAVE);
|
||||||
|
|
||||||
File audioFile = new File("bin/tmp.wav");
|
File audioFile = new File("bin/tmp.wav");
|
||||||
|
|
||||||
boolean speaking = false;
|
boolean speaking = false;
|
||||||
while(!speaking){
|
while(!speaking){
|
||||||
mic.captureAudioToFile(audioFile);
|
mic.captureAudioToFile(audioFile);
|
||||||
|
|
||||||
final int THRESHOLD = 10;//YOUR THRESHOLD VALUE.
|
final int THRESHOLD = 10;//YOUR THRESHOLD VALUE.
|
||||||
mic.open();
|
mic.open();
|
||||||
int ambientVolume = mic.getAudioVolume();//
|
int ambientVolume = mic.getAudioVolume();//
|
||||||
int speakingVolume = -2;
|
int speakingVolume = -2;
|
||||||
|
|
||||||
do{
|
do{
|
||||||
int volume = mic.getAudioVolume();
|
int volume = mic.getAudioVolume();
|
||||||
System.out.println(volume);
|
System.out.println(volume);
|
||||||
if(volume>ambientVolume+THRESHOLD){
|
if(volume>ambientVolume+THRESHOLD){
|
||||||
speakingVolume = volume;
|
speakingVolume = volume;
|
||||||
speaking = true;
|
speaking = true;
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
System.out.println("SPEAKING");
|
System.out.println("SPEAKING");
|
||||||
}
|
}
|
||||||
if(speaking && volume+THRESHOLD<speakingVolume){
|
if(speaking && volume+THRESHOLD<speakingVolume){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}while(speaking);
|
}while(speaking);
|
||||||
mic.close();
|
mic.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
mic.close();
|
mic.close();
|
||||||
|
|
||||||
|
|
||||||
FlacEncoder flacEncoder = new FlacEncoder();
|
FlacEncoder flacEncoder = new FlacEncoder();
|
||||||
File flacFile = new File(audioFile + ".flac");
|
File flacFile = new File(audioFile + ".flac");
|
||||||
flacEncoder.convertWaveToFlac(audioFile, flacFile);
|
flacEncoder.convertWaveToFlac(audioFile, flacFile);
|
||||||
audioFile.delete();
|
audioFile.delete();
|
||||||
|
|
||||||
Path path = Paths.get("bin/tmp.wav.flac");
|
Path path = Paths.get("bin/tmp.wav.flac");
|
||||||
|
|
||||||
byte[] data = Files.readAllBytes(path);
|
byte[] data = Files.readAllBytes(path);
|
||||||
|
|
||||||
String request = "https://www.google.com/"+
|
String request = "https://www.google.com/"+
|
||||||
"speech-api/v1/recognize?"+
|
"speech-api/v1/recognize?"+
|
||||||
"xjerr=1&client=speech2text&lang=en-US&maxresults=1";
|
"xjerr=1&client=speech2text&lang=en-US&maxresults=1";
|
||||||
URL url = new URL(request);
|
URL url = new URL(request);
|
||||||
Proxy proxy =new Proxy(Proxy.Type.HTTP, new InetSocketAddress("www-proxy.ericsson.se", 8080));
|
Proxy proxy =new Proxy(Proxy.Type.HTTP, new InetSocketAddress("www-proxy.ericsson.se", 8080));
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setInstanceFollowRedirects(false);
|
connection.setInstanceFollowRedirects(false);
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
|
connection.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
|
||||||
connection.setRequestProperty("User-Agent", "speech2text");
|
connection.setRequestProperty("User-Agent", "speech2text");
|
||||||
connection.setConnectTimeout(60000);
|
connection.setConnectTimeout(60000);
|
||||||
connection.setUseCaches (false);
|
connection.setUseCaches (false);
|
||||||
|
|
||||||
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
|
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
|
||||||
wr.write(data);
|
wr.write(data);
|
||||||
wr.flush();
|
wr.flush();
|
||||||
wr.close();
|
wr.close();
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
flacFile.delete();
|
flacFile.delete();
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
String decodedString = in.readLine();
|
String decodedString = in.readLine();
|
||||||
GoogleResponse googleResponse = new GoogleResponse();
|
GoogleResponse googleResponse = new GoogleResponse();
|
||||||
parseResponse(decodedString, googleResponse);
|
parseResponse(decodedString, googleResponse);
|
||||||
|
|
||||||
System.out.println(googleResponse);
|
System.out.println(googleResponse);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseResponse(String rawResponse, GoogleResponse googleResponse) {
|
private void parseResponse(String rawResponse, GoogleResponse googleResponse) {
|
||||||
if(rawResponse == null)
|
if(rawResponse == null)
|
||||||
return;
|
return;
|
||||||
if (!rawResponse.contains("utterance"))
|
if (!rawResponse.contains("utterance"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String array = substringBetween(rawResponse, "[", "]");
|
String array = substringBetween(rawResponse, "[", "]");
|
||||||
String[] parts = array.split("}");
|
String[] parts = array.split("}");
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for( String s : parts ) {
|
for( String s : parts ) {
|
||||||
if( first ) {
|
if( first ) {
|
||||||
first = false;
|
first = false;
|
||||||
String utterancePart = s.split(",")[0];
|
String utterancePart = s.split(",")[0];
|
||||||
String confidencePart = s.split(",")[1];
|
String confidencePart = s.split(",")[1];
|
||||||
|
|
||||||
String utterance = utterancePart.split(":")[1];
|
String utterance = utterancePart.split(":")[1];
|
||||||
String confidence = confidencePart.split(":")[1];
|
String confidence = confidencePart.split(":")[1];
|
||||||
|
|
||||||
utterance = stripQuotes(utterance);
|
utterance = stripQuotes(utterance);
|
||||||
confidence = stripQuotes(confidence);
|
confidence = stripQuotes(confidence);
|
||||||
|
|
||||||
if( utterance.equals("null") ) {
|
if( utterance.equals("null") ) {
|
||||||
utterance = null;
|
utterance = null;
|
||||||
}
|
}
|
||||||
if( confidence.equals("null") ) {
|
if( confidence.equals("null") ) {
|
||||||
confidence = null;
|
confidence = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//googleResponse.setResponse(utterance);
|
//googleResponse.setResponse(utterance);
|
||||||
//googleResponse.setConfidence(confidence);
|
//googleResponse.setConfidence(confidence);
|
||||||
} else {
|
} else {
|
||||||
String utterance = s.split(":")[1];
|
String utterance = s.split(":")[1];
|
||||||
utterance = stripQuotes(utterance);
|
utterance = stripQuotes(utterance);
|
||||||
if( utterance.equals("null") ) {
|
if( utterance.equals("null") ) {
|
||||||
utterance = null;
|
utterance = null;
|
||||||
}
|
}
|
||||||
googleResponse.getOtherPossibleResponses().add(utterance);
|
googleResponse.getOtherPossibleResponses().add(utterance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String substringBetween(String s, String part1, String part2) {
|
private String substringBetween(String s, String part1, String part2) {
|
||||||
String sub = null;
|
String sub = null;
|
||||||
|
|
||||||
int i = s.indexOf(part1);
|
int i = s.indexOf(part1);
|
||||||
int j = s.indexOf(part2, i + part1.length());
|
int j = s.indexOf(part2, i + part1.length());
|
||||||
|
|
||||||
if (i != -1 && j != -1) {
|
if (i != -1 && j != -1) {
|
||||||
int nStart = i + part1.length();
|
int nStart = i + part1.length();
|
||||||
sub = s.substring(nStart, j);
|
sub = s.substring(nStart, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String stripQuotes(String s) {
|
private String stripQuotes(String s) {
|
||||||
int start = 0;
|
int start = 0;
|
||||||
if( s.startsWith("\"") ) {
|
if( s.startsWith("\"") ) {
|
||||||
start = 1;
|
start = 1;
|
||||||
}
|
}
|
||||||
int end = s.length();
|
int end = s.length();
|
||||||
if( s.endsWith("\"") ) {
|
if( s.endsWith("\"") ) {
|
||||||
end = s.length() - 1;
|
end = s.length() - 1;
|
||||||
}
|
}
|
||||||
return s.substring(start, end);
|
return s.substring(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,85 +1,85 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.test;
|
package se.hal.test;
|
||||||
|
|
||||||
import com.darkprograms.speech.synthesiser.Synthesiser;
|
import com.darkprograms.speech.synthesiser.Synthesiser;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.scene.media.Media;
|
import javafx.scene.media.Media;
|
||||||
import javafx.scene.media.MediaPlayer;
|
import javafx.scene.media.MediaPlayer;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
@SuppressWarnings("restriction")
|
@SuppressWarnings("restriction")
|
||||||
public class JarvisSyntersizerTest extends Application {
|
public class JarvisSyntersizerTest extends Application {
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
try {
|
try {
|
||||||
Application a = new JarvisSyntersizerTest();
|
Application a = new JarvisSyntersizerTest();
|
||||||
a.launch();
|
a.launch();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JarvisSyntersizerTest(){
|
public JarvisSyntersizerTest(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URL to the given file
|
* Returns the URL to the given file
|
||||||
*
|
*
|
||||||
* @param path is the path to the file (no / if not absolute path)
|
* @param path is the path to the file (no / if not absolute path)
|
||||||
* @return A URL object for the file
|
* @return A URL object for the file
|
||||||
*/
|
*/
|
||||||
public static URL findURL(String path){
|
public static URL findURL(String path){
|
||||||
return Thread.currentThread().getContextClassLoader().getResource(path);
|
return Thread.currentThread().getContextClassLoader().getResource(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage arg0) throws Exception {
|
public void start(Stage arg0) throws Exception {
|
||||||
Synthesiser synthesiser = new Synthesiser("auto");
|
Synthesiser synthesiser = new Synthesiser("auto");
|
||||||
String language = synthesiser.detectLanguage("hi what is your name?");
|
String language = synthesiser.detectLanguage("hi what is your name?");
|
||||||
System.out.println(language);
|
System.out.println(language);
|
||||||
|
|
||||||
InputStream is = synthesiser.getMP3Data("hi what is your name?");
|
InputStream is = synthesiser.getMP3Data("hi what is your name?");
|
||||||
BufferedInputStream buff = new BufferedInputStream(is);
|
BufferedInputStream buff = new BufferedInputStream(is);
|
||||||
DataInputStream di = new DataInputStream(buff);
|
DataInputStream di = new DataInputStream(buff);
|
||||||
|
|
||||||
File f = new File("bin\\tmp.mp3");
|
File f = new File("bin\\tmp.mp3");
|
||||||
FileOutputStream fos = new FileOutputStream(f);
|
FileOutputStream fos = new FileOutputStream(f);
|
||||||
while(di.available() != 0){
|
while(di.available() != 0){
|
||||||
fos.write(di.readByte());
|
fos.write(di.readByte());
|
||||||
}
|
}
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
URL resource = findURL("tmp.mp3");
|
URL resource = findURL("tmp.mp3");
|
||||||
Media hit = new Media(resource.toURI().toString());
|
Media hit = new Media(resource.toURI().toString());
|
||||||
MediaPlayer mediaPlayer = new MediaPlayer(hit);
|
MediaPlayer mediaPlayer = new MediaPlayer(hit);
|
||||||
mediaPlayer.play();
|
mediaPlayer.play();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,63 +1,63 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.test;
|
package se.hal.test;
|
||||||
|
|
||||||
import edu.cmu.sphinx.api.Configuration;
|
import edu.cmu.sphinx.api.Configuration;
|
||||||
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
|
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
|
||||||
import edu.cmu.sphinx.api.SpeechResult;
|
import edu.cmu.sphinx.api.SpeechResult;
|
||||||
import edu.cmu.sphinx.result.WordResult;
|
import edu.cmu.sphinx.result.WordResult;
|
||||||
|
|
||||||
public class LiveSpeechRecognizerTest {
|
public class LiveSpeechRecognizerTest {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
System.out.println("Loading models...");
|
System.out.println("Loading models...");
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
// Set path to acoustic model.
|
// Set path to acoustic model.
|
||||||
configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
|
configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
|
||||||
// Set path to dictionary.
|
// Set path to dictionary.
|
||||||
configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
|
configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
|
||||||
// Set language model.
|
// Set language model.
|
||||||
configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.dmp");
|
configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.dmp");
|
||||||
|
|
||||||
System.out.println("Listening...");
|
System.out.println("Listening...");
|
||||||
LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);
|
LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);
|
||||||
// Start recognition process pruning previously cached data.
|
// Start recognition process pruning previously cached data.
|
||||||
recognizer.startRecognition(false);
|
recognizer.startRecognition(false);
|
||||||
SpeechResult result = recognizer.getResult();
|
SpeechResult result = recognizer.getResult();
|
||||||
// Pause recognition process. It can be resumed then with startRecognition(false).
|
// Pause recognition process. It can be resumed then with startRecognition(false).
|
||||||
recognizer.stopRecognition();
|
recognizer.stopRecognition();
|
||||||
|
|
||||||
|
|
||||||
// Print utterance string without filler words.
|
// Print utterance string without filler words.
|
||||||
System.out.println("Hypothesis: " + result.getHypothesis());
|
System.out.println("Hypothesis: " + result.getHypothesis());
|
||||||
|
|
||||||
// Get individual words and their times.
|
// Get individual words and their times.
|
||||||
for (WordResult r : result.getWords()) {
|
for (WordResult r : result.getWords()) {
|
||||||
System.out.println("Word: "+r);
|
System.out.println("Word: "+r);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save lattice in a graphviz format.
|
// Save lattice in a graphviz format.
|
||||||
result.getLattice().dumpDot("lattice.dot", "lattice");
|
result.getLattice().dumpDot("lattice.dot", "lattice");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,50 +1,50 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Ziver
|
* Copyright (c) 2015 Ziver
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.test;
|
package se.hal.test;
|
||||||
|
|
||||||
import marytts.MaryInterface;
|
import marytts.MaryInterface;
|
||||||
import marytts.client.RemoteMaryInterface;
|
import marytts.client.RemoteMaryInterface;
|
||||||
import marytts.util.data.audio.AudioPlayer;
|
import marytts.util.data.audio.AudioPlayer;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioInputStream;
|
import javax.sound.sampled.AudioInputStream;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA.
|
* Created with IntelliJ IDEA.
|
||||||
* User: ezivkoc
|
* User: ezivkoc
|
||||||
* Date: 2013-12-17
|
* Date: 2013-12-17
|
||||||
* Time: 12:39
|
* Time: 12:39
|
||||||
*/
|
*/
|
||||||
public class MaryTTS {
|
public class MaryTTS {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
MaryInterface marytts = new RemoteMaryInterface("127.0.0.1", 59125);
|
MaryInterface marytts = new RemoteMaryInterface("127.0.0.1", 59125);
|
||||||
|
|
||||||
Set<String> voices = marytts.getAvailableVoices();
|
Set<String> voices = marytts.getAvailableVoices();
|
||||||
marytts.setVoice(voices.iterator().next());
|
marytts.setVoice(voices.iterator().next());
|
||||||
AudioInputStream audio = marytts.generateAudio("Hello world.");
|
AudioInputStream audio = marytts.generateAudio("Hello world.");
|
||||||
AudioPlayer player = new AudioPlayer(audio);
|
AudioPlayer player = new AudioPlayer(audio);
|
||||||
player.start();
|
player.start();
|
||||||
player.join();
|
player.join();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.koc.hal.test;
|
package se.hal.test;
|
||||||
|
|
||||||
import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
|
import com.darkprograms.speech.microphone.MicrophoneAnalyzer;
|
||||||
import edu.cmu.sphinx.api.Configuration;
|
import edu.cmu.sphinx.api.Configuration;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package se.koc.hal.util;
|
package se.hal.util;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue