public class AndroidSpeechRecognizer extends Object implements SpeechProcessor
This component uses the built-in Android SpeechRecognizer
to process
user speech.
As part of normal operation, SpeechRecognizer
plays system sounds
both when it starts and stops actively listening to the user, just like the
built-in Google Assistant. This behavior is not optional; it can be
suppressed by having the AudioManager
mute the music stream, but it
muting and restoring the volume of that stream at exactly the right times is
error-prone, so such behavior has been omitted from this component.
Note that this component requires an Android Context
to be attached
to the pipeline that has created it. If the pipeline is meant to persist
across different Activity
s, the Context
used must either be
the application context, or it must be re-set on the pipeline's
SpeechContext
object when the Activity context changes.
Implementation of SpeechRecognizer
is left up to devices, and even
though the API exists, an actual recognizer may not be present on all
devices. If using this component, it's a good idea to call SpeechRecognizer.isRecognitionAvailable()
before adding it to the pipeline
to determine whether it will be viable on the current device.
In addition, testing has shown that some older devices may return true
for the preceding call but have outdated implementations that
consistently throw errors. For this reason, it's a good idea to have an
OnSpeechEventListener
set up to detect
SpeechRecognizerError
s and have an appropriate fallback strategy in
place.
This pipeline component supports the following configuration property, though it should be left at its default setting in most circumstances:
Constructor and Description |
---|
AndroidSpeechRecognizer(SpeechConfig speechConfig)
Initializes a new recognizer.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
process(SpeechContext context,
ByteBuffer frame)
processes the current speech frame.
|
void |
reset()
resets all state internal to the stage.
|
public AndroidSpeechRecognizer(SpeechConfig speechConfig)
speechConfig
- Spokestack pipeline configurationpublic void process(SpeechContext context, ByteBuffer frame)
SpeechProcessor
process
in interface SpeechProcessor
context
- the current speech contextframe
- the received audio framepublic void reset()
SpeechProcessor
reset
in interface SpeechProcessor
public void close()
close
in interface AutoCloseable
Copyright © 2021. All rights reserved.