Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Commit

Permalink
Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Mar 20, 2018
1 parent 96b1977 commit d16d58b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 18 deletions.
7 changes: 6 additions & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.piegames</groupId>
<artifactId>voicepi</artifactId>
<name>VoicePi</name>
<version>0.1.0</version>
<version>0.2.0</version>
<description>A cross-platform voice control application primarily targetting Raspberry Pi</description>
<url>https://github.com/piegamesde/VoicePi/</url>
<issueManagement>
Expand Down Expand Up @@ -55,6 +55,11 @@
<descriptor>src/assembly/dep.xml</descriptor>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</build>
<repositories>
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.piegames</groupId>
<artifactId>voicepi</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>
<name>VoicePi</name>
<description>A cross-platform voice control application primarily targetting Raspberry Pi</description>
<build>
<!-- resources> <resource> <directory>src/main/resources</directory> </resource> <resource> <directory>src/test/resources</directory> </resource> <resource> <directory>libraries</directory> </resource> </resources -->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/assembly/dep.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<outputDirectory>./</outputDirectory>
<includes>
<include>README*</include>
<include>config.json</include>
<include>scripts/*</include>
<include>sounds/*</include>
</includes>
</fileSet>
<fileSet>
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/de/piegames/voicepi/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package de.piegames.voicepi;

import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -53,16 +54,20 @@ public Path getDefaultPath() {
}

public void loadDefaultConfig() {
log.info("Loading default configuration");
// TODO fix path
config = new JsonParser().parse(new InputStreamReader(getClass().getResourceAsStream("../../../defaultconfig.json"))).getAsJsonObject();
modulesConfig = config.getAsJsonObject("modules");
sttConfig = config.getAsJsonObject("stt");
ttsConfig = config.getAsJsonObject("tts");
settingsConfig = config;
log.info("Loading default configuration at " + getClass().getResource("/defaultconfig.json"));
try {
FileSystems.newFileSystem(getClass().getResource("/defaultconfig.json").toURI(), new HashMap<>());
loadConfig(Paths.get(getClass().getResource("/defaultconfig.json").toURI()));
} catch (IOException | URISyntaxException e) {
log.fatal("Cannot load default configuration. Please copy the defaultconfig.json from the jar to config.json manually and restart the application", e);
}
}

public void loadConfig() throws IOException {
loadConfig(path);
}

private void loadConfig(Path path) throws IOException {
// Load config
log.info("Loading configuration from file " + path.toAbsolutePath());
config = new JsonParser().parse(Files.newBufferedReader(path.toAbsolutePath())).getAsJsonObject();
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/de/piegames/voicepi/VoicePi.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public void run() {
log.debug("Available commands: " + stateMachine.getAvailableCommands());
} else if (!stateMachine.isWaitingForActivation() && stateMachine.isActivationNeeded()) {
log.info("Timed out");
stt.pauseRecognition();
settings.onTimeout.execute(this, log, "onTimeout");
stt.resumeRecognition();
stateMachine.resetState();
}
} catch (InterruptedException e) {
Expand Down Expand Up @@ -106,9 +108,11 @@ public void onCommandSpoken(Collection<String> possibleCommand) {
break;
}
}
if (state == stateMachine.getRoot() && stateMachine.isActivationNeeded()) {
if (stateMachine.isActivationNeeded() && state == stateMachine.getRoot()) {
log.info("Activated.");
stt.pauseRecognition();
settings.onActivation.execute(this, log, "onActivation");
stt.resumeRecognition();
return;
}
if (responsible != null) {
Expand All @@ -117,9 +121,13 @@ public void onCommandSpoken(Collection<String> possibleCommand) {
// initialState: The state before this command was spoken and thus the state this command belongs to
responsible.onCommandSpoken(initialState, command);
stt.resumeRecognition();
} else if (stateMachine.isActivationNeeded() && initialState == stateMachine.getStart()) {
log.info("You need to activate first");
} else {
log.info("What you just said makes no sense, sorry");
stt.pauseRecognition();
settings.onWrongCommand.execute(this, log, "onWrongCommand");
stt.resumeRecognition();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public PlaySoundAction(JsonObject data) {
@Override
public void execute(VoicePi control) throws IOException, InterruptedException {
try {
log.debug("Playing " + soundfile);
SpeechEngine.playSound(AudioSystem.getAudioInputStream(new File(soundfile)));
} catch (LineUnavailableException | UnsupportedAudioFileException e) {
log.warn("Could not play sound " + soundfile, e);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/piegames/voicepi/stt/SphinxRecognizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void load(Set<String> commands) throws IOException {
public void run() {
SpeechResult result;
while (!Thread.currentThread().isInterrupted()) {
log.debug("Listening");
if ((result = stt.getResult()) != null) {
log.info("You said: " + result.getHypothesis());
Collection<String> best = result.getNbest(Integer.MAX_VALUE);
Expand All @@ -122,17 +123,20 @@ public void run() {
commandsSpoken.offer(best);
}
}
log.debug("Not listening anymore");
}

@Override
public void startRecognition() {
log.debug("Starting SphinxRecognizer");
stt.startRecognition(true);
thread = new Thread(this);
thread.start();
}

@Override
public void stopRecognition() {
log.debug("Stopping SphinxRecognizer");
thread.interrupt();
Thread.yield();
// Sorry, no other possibility here. Sphinx does not provide anything to stop it while recognizing.
Expand All @@ -147,6 +151,7 @@ public void stopRecognition() {

@Override
public void pauseRecognition() {
log.debug("Pausing SphinxRecognizer");
// stt.stopRecognition();
// TODO starting and stopping takes quite a lot of time. Instead, don't stop it and just discard the results. (This needs to be tested because it might
// not work)
Expand All @@ -155,6 +160,7 @@ public void pauseRecognition() {

@Override
public void resumeRecognition() {
log.debug("Resuming SphinxRecognizer");
// stopRecognition();
// stt.startRecognition(true);
ignoreCommands = false;
Expand Down
7 changes: 2 additions & 5 deletions src/test/java/de/piegames/voicepi/VoicePiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public class VoicePiTest {
*/
@Test
public void testTest() throws URISyntaxException, IOException, InterruptedException {
// TODO fix path
Configuration config = new Configuration(Paths.get(getClass().getResource("../../../testconfig.json").toURI()));
Configuration config = new Configuration(Paths.get(getClass().getResource("/testconfig.json").toURI()));
VoicePi control = new VoicePi(config);
control.reload();
QueueRecognizer stt = (QueueRecognizer) control.getSTT();
Expand All @@ -30,7 +29,6 @@ public void testTest() throws URISyntaxException, IOException, InterruptedExcept

assertEquals("Starting VoicePi", tts.spoken.poll(timeout, TimeUnit.SECONDS));
stt.commandSpoken("TEST");
assertEquals("BOOOO", tts.spoken.poll(timeout, TimeUnit.SECONDS));
stt.commandSpoken("ACTIVATE");
assertEquals("Yes, sir", tts.spoken.poll(timeout, TimeUnit.SECONDS));
stt.commandSpoken("TEST");
Expand Down Expand Up @@ -62,8 +60,7 @@ public void testTest() throws URISyntaxException, IOException, InterruptedExcept
/** This test will load the same configuration, but use a more advanced ActionModule with different state. */
@Test
public void multistateTest() throws URISyntaxException, IOException, InterruptedException {
// TODO fix path
Configuration config = new Configuration(Paths.get(getClass().getResource("../../../testconfig.json").toURI()));
Configuration config = new Configuration(Paths.get(getClass().getResource("/testconfig.json").toURI()));
VoicePi control = new VoicePi(config);
control.reload();
QueueRecognizer stt = (QueueRecognizer) control.getSTT();
Expand Down

0 comments on commit d16d58b

Please sign in to comment.