public final class SpeechPipeline extends Object implements AutoCloseable
This is the primary client entry point to the Spokestack framework. It dynamically binds to configured components that implement the pipeline interfaces for reading audio frames and performing speech recognition tasks.
Clients initialize the pipeline using the SpeechPipeline.Builder class. The
following is an example pipeline that reads the android microphone and
performs voice activity detection (VAD).
SpeechPipeline pipeline = new SpeechPipeline.Builder()
.setInputClass("io.spokestack.spokestack.android.MicrophoneInput")
.addStageClass("io.spokestack.spokestack.webrtc.VoiceActivityTrigger")
.addStageClass("io.spokestack.spokestack.ActivationTimeout")
.setProperty("sample-rate", 16000)
.setProperty("frame-width", 20)
.setProperty("buffer-width", 300)
.addOnSpeechEventListener(this)
.build();
pipeline.start();
The pipeline may be stopped/restarted any number of times during its lifecycle. While stopped, the pipeline consumes as few resources as possible. The pipeline runs asynchronously on a dedicated thread, so it does not block the caller to perform I/O or speech processing.
When running, the pipeline communicates with the client via the event interface on the speech context. All calls to event handlers are made in the context of the pipeline's thread, so event handlers should not perform blocking operations, and should use message passing when communicating with UI components, etc.
| Modifier and Type | Class and Description |
|---|---|
static class |
SpeechPipeline.Builder
speech pipeline builder.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_WIDTH
audio frame buffer width, in ms.
|
static int |
DEFAULT_FRAME_WIDTH
audio frame width, in ms.
|
static int |
DEFAULT_SAMPLE_RATE
audio sample rate default, in samples/sec.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activate()
manually activate the speech pipeline.
|
void |
addListener(OnSpeechEventListener listener)
Add a new listener to receive events from the speech pipeline.
|
void |
close()
shuts down the pipeline and releases its resources.
|
void |
deactivate()
manually deactivate the speech pipeline.
|
SpeechConfig |
getConfig() |
SpeechContext |
getContext() |
boolean |
isPaused() |
boolean |
isRunning() |
void |
pause()
Pauses the speech pipeline, temporarily stopping passive listening.
|
void |
removeListener(OnSpeechEventListener listener)
Remove a pipeline listener, allowing it to be garbage collected.
|
void |
resume()
Resumes a paused speech pipeline, returning the pipeline to a passive
listening state.
|
void |
start()
starts up the speech pipeline.
|
void |
stop()
stops the speech pipeline and releases all resources.
|
public static final int DEFAULT_SAMPLE_RATE
public static final int DEFAULT_FRAME_WIDTH
public static final int DEFAULT_BUFFER_WIDTH
public void close()
close in interface AutoCloseablepublic SpeechConfig getConfig()
public SpeechContext getContext()
public boolean isRunning()
public boolean isPaused()
public void activate()
public void deactivate()
public void addListener(OnSpeechEventListener listener)
listener - The listener to add.public void removeListener(OnSpeechEventListener listener)
listener - The listener to remove.public void start()
throws Exception
Exception - on configuration/startup errorpublic void pause()
Note that active listening (an active ASR stage) cannot be paused, so
the pipeline is deactivated before it is paused. This may prevent the
delivery of a
SpeechContext.Event.RECOGNIZE event if
an ASR request is currently in progress.
While paused, the pipeline will not respond to the wakeword, but
in order to support a quick resume(), it will retain control
of the microphone. No audio is explicitly read or analyzed. To fully
release the pipeline's resources, see stop().
public void resume()
public void stop()
Copyright © 2021. All rights reserved.