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

Commit

Permalink
feat: convenience method to set pipeline profile
Browse files Browse the repository at this point in the history
  • Loading branch information
space-pope committed Mar 31, 2021
1 parent 1797131 commit 8ba7ef6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/main/java/io/spokestack/spokestack/Spokestack.java
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,23 @@ public Builder setConfig(SpeechConfig config) {
return this;
}

/**
* Uses a {@link PipelineProfile} to configure the speech pipeline,
* returning the modified builder. Subsequent calls to {@code
* withPipelineProfile} or {@code setProperty} can override
* configuration set by a profile.
*
* @param profileClass class name of the profile to apply.
* @return the updated builder
* @throws IllegalArgumentException if the specified profile does not
* exist
*/
public Builder withPipelineProfile(String profileClass)
throws IllegalArgumentException {
this.pipelineBuilder.useProfile(profileClass);
return this;
}

/**
* Sets a configuration value.
*
Expand Down Expand Up @@ -772,9 +789,7 @@ public Builder withoutSpeechPipeline() {
* Signal that Spokestack's TensorFlow Lite wakeword detector should not
* be used. This is equivalent to calling
* <pre>
* builder
* .getPipelineBuilder()
* .useProfile(
* builder.withPipelineProfile(
* "io.spokestack.spokestack.profile.PushToTalkAndroidASR");
* </pre>
* <p>
Expand All @@ -787,8 +802,7 @@ public Builder withoutSpeechPipeline() {
public Builder withoutWakeword() {
String profileClass =
"io.spokestack.spokestack.profile.PushToTalkAndroidASR";
this.pipelineBuilder.useProfile(profileClass);
return this;
return this.withPipelineProfile(profileClass);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/io/spokestack/spokestack/SpokestackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ public void testSpeechPipeline() throws Exception {
assertFalse(spokestack.getSpeechPipeline().isRunning());
}

@Test
public void testPipelineProfile() {
// this only tests that the convenience method properly dispatches to
// the pipeline version, failing with an invalid profile;
// the valid profiles are tested by the speech pipeline test
assertThrows(IllegalArgumentException.class, () ->
new Spokestack.Builder()
.withPipelineProfile("io.spokestack.InvalidProfile")
);
}

@Test
public void testNlu() throws Exception {
TestAdapter listener = new TestAdapter();
Expand Down

0 comments on commit 8ba7ef6

Please sign in to comment.