From 57e6854d996e94fa279be91c63241f9cdeb34490 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 8 Mar 2021 12:54:07 -0500 Subject: [PATCH] fix: typo in Spokestack ASR profile (#140) --- .../profile/PushToTalkSpokestackASR.java | 2 +- .../spokestack/SpeechPipelineTest.java | 38 ++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/spokestack/spokestack/profile/PushToTalkSpokestackASR.java b/src/main/java/io/spokestack/spokestack/profile/PushToTalkSpokestackASR.java index 5c48fd2..66c6024 100644 --- a/src/main/java/io/spokestack/spokestack/profile/PushToTalkSpokestackASR.java +++ b/src/main/java/io/spokestack/spokestack/profile/PushToTalkSpokestackASR.java @@ -40,7 +40,7 @@ public SpeechPipeline.Builder apply(SpeechPipeline.Builder builder) { stages.add("io.spokestack.spokestack.webrtc.VoiceActivityDetector"); stages.add("io.spokestack.spokestack.ActivationTimeout"); stages.add( - "io.spokestack.spokestack.android.SpokestackCloudRecognizer"); + "io.spokestack.spokestack.asr.SpokestackCloudRecognizer"); return builder .setInputClass("io.spokestack.spokestack.android.MicrophoneInput") diff --git a/src/test/java/io/spokestack/spokestack/SpeechPipelineTest.java b/src/test/java/io/spokestack/spokestack/SpeechPipelineTest.java index a7f8f1d..de12092 100644 --- a/src/test/java/io/spokestack/spokestack/SpeechPipelineTest.java +++ b/src/test/java/io/spokestack/spokestack/SpeechPipelineTest.java @@ -1,5 +1,6 @@ package io.spokestack.spokestack; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.concurrent.Semaphore; @@ -105,17 +106,44 @@ public void testBuilder() throws Exception { } @Test - public void testProfiles() { + @SuppressWarnings("unchecked") + public void testProfiles() throws Exception { assertThrows(IllegalArgumentException.class, () -> new SpeechPipeline.Builder() .useProfile("io.spokestack.InvalidProfile") ); - // no pre-set profiles should throw errors on use - // (use instantiates the associated profile class) + SpeechConfig config = new SpeechConfig(); + Field stageField = SpeechPipeline.Builder.class + .getDeclaredField("stageClasses"); + stageField.setAccessible(true); + + // all classes from all profiles should be accessible on the classpath for (Class profileClass : PROFILES) { - new SpeechPipeline.Builder() - .useProfile(profileClass.getCanonicalName()); + SpeechPipeline.Builder builder = + new SpeechPipeline.Builder() + .useProfile(profileClass.getCanonicalName()); + + List stages = (List) stageField.get(builder); + + for (String stageName : stages) { + try { + SpeechProcessor processor = (SpeechProcessor) Class + .forName(stageName) + .getConstructor(SpeechConfig.class) + .newInstance(new Object[]{config}); + } catch (ClassNotFoundException e) { + // we're checking for typos in the fully qualified stage + // names here, so this is the only error we care about + fail("stage " + stageName + " not found for profile " + + profileClass); + } catch (Exception | Error e) { + // various errors are expected because + // this test doesn't provide a proper runtime environment + // or configuration for the stages, + // so do nothing here + } + } } // The implicated class requires a config property