This repository was archived by the owner on May 6, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +28
-6
lines changed
main/java/io/spokestack/spokestack
test/java/io/spokestack/spokestack Expand file tree Collapse file tree 4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change 260260 <useSystemClassLoader >false</useSystemClassLoader >
261261 <argLine >${argLine} -Djava.library.path=./target -XX:-OmitStackTraceInFastThrow</argLine >
262262 <trimStackTrace >false</trimStackTrace >
263- <forkCount >4</forkCount >
264- <reuseForks >false</reuseForks >
265263 </configuration >
266264 </plugin >
267265
Original file line number Diff line number Diff line change @@ -72,11 +72,11 @@ public final class SpeechPipeline implements AutoCloseable {
7272 private final List <String > stageClasses ;
7373 private final SpeechConfig config ;
7474 private final SpeechContext context ;
75+ private volatile boolean running ;
76+ private volatile boolean paused ;
7577 private SpeechInput input ;
7678 private List <SpeechProcessor > stages ;
7779 private Thread thread ;
78- private boolean running ;
79- private boolean paused ;
8080 private boolean managed ;
8181
8282 /**
@@ -227,7 +227,7 @@ private void attachBuffer() throws Exception {
227227 }
228228
229229 private void startThread () throws Exception {
230- this .thread = new Thread (this ::run );
230+ this .thread = new Thread (this ::run , "Spokestack-speech-pipeline" );
231231 this .running = true ;
232232 this .thread .start ();
233233 }
@@ -300,6 +300,9 @@ private void step() {
300300 } else {
301301 dispatch ();
302302 }
303+ if (Thread .currentThread ().isInterrupted ()) {
304+ this .running = false ;
305+ }
303306 }
304307
305308 private void dispatch () {
Original file line number Diff line number Diff line change 88import androidx .annotation .NonNull ;
99import io .spokestack .spokestack .android .AudioRecordError ;
1010import io .spokestack .spokestack .util .EventTracer ;
11+ import org .junit .After ;
1112import org .junit .Before ;
1213import org .junit .Test ;
1314import org .junit .jupiter .api .function .Executable ;
@@ -37,6 +38,16 @@ public void before() {
3738 this .events .clear ();
3839 }
3940
41+ @ After
42+ public void after () {
43+ // shut down any stray speech pipeline background threads
44+ for (Thread thread : Thread .getAllStackTraces ().keySet ()) {
45+ if (thread .getName ().contains ("Spokestack" )) {
46+ thread .interrupt ();
47+ }
48+ }
49+ }
50+
4051 @ Test
4152 public void testBuilder () throws Exception {
4253 // default config
Original file line number Diff line number Diff line change 1111import io .spokestack .spokestack .tts .TTSTestUtils ;
1212import io .spokestack .spokestack .util .EventTracer ;
1313import org .jetbrains .annotations .NotNull ;
14+ import org .junit .After ;
1415import org .junit .Test ;
1516import org .junit .runner .RunWith ;
1617import org .powermock .core .classloader .annotations .PrepareForTest ;
1718import org .powermock .modules .junit4 .PowerMockRunner ;
1819
19- import java .nio .ByteBuffer ;
2020import java .util .ArrayList ;
2121import java .util .concurrent .LinkedBlockingQueue ;
2222import java .util .concurrent .TimeUnit ;
3030@ PrepareForTest ({SystemClock .class })
3131public class SpokestackTest {
3232
33+ @ After
34+ public void after () {
35+ // shut down any stray speech pipeline background threads
36+ for (Thread thread : Thread .getAllStackTraces ().keySet ()) {
37+ if (thread .getName ().contains ("Spokestack" )) {
38+ thread .interrupt ();
39+ }
40+ }
41+ }
42+
3343 @ Test
3444 public void testBuild () throws Exception {
3545 // missing all required config
You can’t perform that action at this time.
0 commit comments