public class SpokestackTTSOutput extends SpeechOutput implements com.google.android.exoplayer2.Player.EventListener, android.media.AudioManager.OnAudioFocusChangeListener
The Spokestack audio player uses
ExoPlayer
to handle automatic playback of TTS responses. Note that it
does not provide a UI. It is designed to be used within a TTS subsystem
controlled by a TTSManager
in an app that wants to delegate all
media management to Spokestack; if fine control over
playback is desired, consider adding a TTSListener
to the TTSManager
and managing audio via its methods.
Additionally, this component requires an Android Context
to be
attached to the manager that has created it. If the manager 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
manager when the Activity context changes.
Constructor and Description |
---|
SpokestackTTSOutput(SpeechConfig config)
Creates a new audio output component.
|
Modifier and Type | Method and Description |
---|---|
void |
audioReceived(AudioResponse response)
Notifies the component that audio is available for immediate playback or
caching at the specified location.
|
void |
close() |
com.google.android.exoplayer2.ExoPlayer |
getMediaPlayer()
Gets the current media player instance.
|
void |
onAudioFocusChange(int focusChange) |
void |
onIsPlayingChanged(boolean isPlaying) |
void |
onPlayerError(com.google.android.exoplayer2.ExoPlaybackException error) |
void |
pauseContent()
Pause playback of any current content, storing the player's state
internally for later resumption.
|
void |
playContent()
Start or resume playback of any TTS responses.
|
void |
prepare()
Establish the media player and allocate its internal resources.
|
void |
setAndroidContext(android.content.Context androidContext)
Sets the output's Android context.
|
void |
stopPlayback()
Stops playback of any currently playing and queued synthesis results and
clears the play queue.
|
eventReceived
addListener, dispatch, removeListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onLoadingChanged, onPlaybackParametersChanged, onPlaybackSuppressionReasonChanged, onPlayerStateChanged, onPositionDiscontinuity, onRepeatModeChanged, onSeekProcessed, onShuffleModeEnabledChanged, onTimelineChanged, onTimelineChanged, onTracksChanged
public SpokestackTTSOutput(SpeechConfig config)
config
- A configuration object. This class does not require any
configuration properties, but this constructor is required
for participation in the TTS subsystem.public void setAndroidContext(@NonNull android.content.Context androidContext)
SpeechOutput
setAndroidContext
in class SpeechOutput
androidContext
- The Android context.@Nullable public com.google.android.exoplayer2.ExoPlayer getMediaPlayer()
public void prepare()
public void close()
close
in interface AutoCloseable
public void audioReceived(AudioResponse response)
SpeechOutput
audioReceived
in class SpeechOutput
response
- The TTS response containing the URI of the synthesized
audio.public void stopPlayback()
SpeechOutput
stopPlayback
in class SpeechOutput
public void onIsPlayingChanged(boolean isPlaying)
onIsPlayingChanged
in interface com.google.android.exoplayer2.Player.EventListener
public void onPlayerError(@NotNull com.google.android.exoplayer2.ExoPlaybackException error)
onPlayerError
in interface com.google.android.exoplayer2.Player.EventListener
public void onAudioFocusChange(int focusChange)
onAudioFocusChange
in interface android.media.AudioManager.OnAudioFocusChangeListener
public void playContent()
public void pauseContent()
Copyright © 2021. All rights reserved.