public abstract class UtteranceProgressListener extends Object
TextToSpeech.speak(java.lang.CharSequence, int, android.os.Bundle, java.lang.String)
or TextToSpeech.synthesizeToFile(java.lang.CharSequence, android.os.Bundle, java.io.File, java.lang.String)
with an
associated utterance identifier, as per TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID
.
The callbacks specified in this method can be called from multiple threads.Constructor and Description |
---|
UtteranceProgressListener() |
Modifier and Type | Method and Description |
---|---|
void |
onAudioAvailable(String utteranceId,
byte[] audio)
This is called when a chunk of audio is ready for consumption.
|
void |
onBeginSynthesis(String utteranceId,
int sampleRateInHz,
int audioFormat,
int channelCount)
Called when the TTS engine begins to synthesize the audio for a request.
|
abstract void |
onDone(String utteranceId)
Called when an utterance has successfully completed processing.
|
abstract void |
onError(String utteranceId)
Deprecated.
Use
onError(String,int) instead |
void |
onError(String utteranceId,
int errorCode)
Called when an error has occurred during processing.
|
abstract void |
onStart(String utteranceId)
Called when an utterance "starts" as perceived by the caller.
|
void |
onStop(String utteranceId,
boolean interrupted)
Called when an utterance has been stopped while in progress or flushed from the
synthesis queue.
|
public abstract void onStart(String utteranceId)
TextToSpeech.speak(java.lang.CharSequence, int, android.os.Bundle, java.lang.String)
or before the first bytes of a file are written to the file system in the case
of TextToSpeech.synthesizeToFile(java.lang.CharSequence, android.os.Bundle, java.io.File, java.lang.String)
.utteranceId
- The utterance ID of the utterance.public abstract void onDone(String utteranceId)
onStart(String)
.utteranceId
- The utterance ID of the utterance.@Deprecated public abstract void onError(String utteranceId)
onError(String,int)
insteadonStart(String)
for specified utteranceId but there will never
be a call to both onDone(String)
and onError(String)
for
the same utterance.utteranceId
- The utterance ID of the utterance.public void onError(String utteranceId, int errorCode)
onStart(String)
for specified utteranceId but there will never
be a call to both onDone(String)
and onError(String,int)
for
the same utterance. The default implementation calls onError(String)
.utteranceId
- The utterance ID of the utterance.errorCode
- one of the ERROR_* codes from TextToSpeech
public void onStop(String utteranceId, boolean interrupted)
TextToSpeech.stop()
or uses TextToSpeech.QUEUE_FLUSH
as an argument with the
TextToSpeech.speak(java.lang.CharSequence, int, android.os.Bundle, java.lang.String)
or TextToSpeech.synthesizeToFile(java.lang.CharSequence, android.os.Bundle, java.io.File, java.lang.String)
methods.utteranceId
- The utterance ID of the utterance.interrupted
- If true, then the utterance was interrupted while being synthesized
and its output is incomplete. If false, then the utterance was flushed
before the synthesis started.public void onBeginSynthesis(String utteranceId, int sampleRateInHz, int audioFormat, int channelCount)
It provides information about the format of the byte array for subsequent
onAudioAvailable(java.lang.String, byte[])
calls.
This is called when the TTS engine starts synthesizing audio for the request. If an application wishes to know when the audio is about to start playing, {#onStart(String)} should be used instead.
utteranceId
- The utterance ID of the utterance.sampleRateInHz
- Sample rate in hertz of the generated audio.audioFormat
- Audio format of the generated audio. Should be one of
AudioFormat.ENCODING_PCM_8BIT
, AudioFormat.ENCODING_PCM_16BIT
or
AudioFormat.ENCODING_PCM_FLOAT
.channelCount
- The number of channels.public void onAudioAvailable(String utteranceId, byte[] audio)
The audio parameter is a copy of what will be synthesized to the speakers (when synthesis was
initiated with a TextToSpeech.speak(java.lang.CharSequence, int, android.os.Bundle, java.lang.String)
call) or written to the file system (for
TextToSpeech.synthesizeToFile(java.lang.CharSequence, android.os.Bundle, java.io.File, java.lang.String)
). The audio bytes are delivered in one or more chunks;
if onDone(java.lang.String)
or onError(java.lang.String)
is called all chunks have been received.
The audio received here may not be played for some time depending on buffer sizes and the amount of items on the synthesis queue.
utteranceId
- The utterance ID of the utterance.audio
- A chunk of audio; the format can be known by listening to
onBeginSynthesis(String, int, int, int)
.