Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Feature: Allow start call on a running pipeline
Browse files Browse the repository at this point in the history
This changes the semantics of `SpeechPipeline.start()` to make it
roughly idempotent: If a pipeline is running, `start` will emit an
info trace event, but no error will be thrown.
  • Loading branch information
space-pope committed Jul 28, 2020
1 parent 82bfb38 commit ac46af6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/main/java/io/spokestack/spokestack/SpeechPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public void deactivate() {
*/
public void start() throws Exception {
if (this.running) {
throw new IllegalStateException("already running");
this.context.traceInfo(
"attempting to start a running pipeline; ignoring");
return;
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.ByteBuffer;

import androidx.annotation.NonNull;
import io.spokestack.spokestack.util.EventTracer;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.function.Executable;
Expand Down Expand Up @@ -118,6 +119,7 @@ public void testStartStop() throws Exception {
.setProperty("sample-rate", 16000)
.setProperty("frame-width", 20)
.setProperty("buffer-width", 300)
.setProperty("trace-level", EventTracer.Level.INFO.value())
.addOnSpeechEventListener(this)
.build();

Expand All @@ -128,10 +130,9 @@ public void testStartStop() throws Exception {
assertEquals(0, Input.counter);
assertTrue(Stage.open);

// invalid restart
assertThrows(IllegalStateException.class, new Executable() {
public void execute() throws Exception { pipeline.start(); }
});
// idempotent restart
pipeline.start();
assertEquals(SpeechContext.Event.TRACE, this.events.get(0));

// first frame
transact(false);
Expand Down

0 comments on commit ac46af6

Please sign in to comment.