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 |
isRunning() |
void |
removeListener(OnSpeechEventListener listener)
Remove a pipeline listener, allowing it to be garbage collected.
|
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 AutoCloseable
public SpeechConfig getConfig()
public SpeechContext getContext()
public boolean isRunning()
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 stop()
Copyright © 2020. All rights reserved.