public interface SynthesisCallback
start(int, int, int)
, then audioAvailable(byte[], int, int)
until all audio has been provided, then finally
done()
.
error()
can be called at any stage in the synthesis process to
indicate that an error has occurred, but if the call is made after a call
to done()
, it might be discarded.
done()
must be called at the end of synthesis, regardless of errors.
All methods can be only called on the synthesis thread.Modifier and Type | Interface and Description |
---|---|
static interface |
SynthesisCallback.SupportedAudioFormat |
Modifier and Type | Method and Description |
---|---|
int |
audioAvailable(byte[] buffer,
int offset,
int length)
The service should call this method when synthesized audio is ready for consumption.
|
int |
done()
The service should call this method when all the synthesized audio for a request has
been passed to
audioAvailable(byte[], int, int) . |
void |
error()
The service should call this method if the speech synthesis fails.
|
void |
error(int errorCode)
The service should call this method if the speech synthesis fails.
|
int |
getMaxBufferSize() |
boolean |
hasFinished()
Check if
done() was called or not. |
boolean |
hasStarted()
Check if
start(int, int, int) was called or not. |
int |
start(int sampleRateInHz,
int audioFormat,
int channelCount)
The service should call this when it starts to synthesize audio for this
request.
|
int getMaxBufferSize()
audioAvailable(byte[], int, int)
. Calls to audioAvailable(byte[], int, int)
with data lengths
larger than this value will not succeed.int start(int sampleRateInHz, int audioFormat, int channelCount)
TextToSpeechService.onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
.sampleRateInHz
- Sample rate in HZ of the generated audio.audioFormat
- Audio format of the generated audio. Must be one of
AudioFormat.ENCODING_PCM_8BIT
or
AudioFormat.ENCODING_PCM_16BIT
. Can also be
AudioFormat.ENCODING_PCM_FLOAT
when targetting Android N and
above.channelCount
- The number of channels. Must be 1
or 2
.TextToSpeech.SUCCESS
, TextToSpeech.ERROR
or
TextToSpeech.STOPPED
.int audioAvailable(byte[] buffer, int offset, int length)
TextToSpeechService.onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
.buffer
- The generated audio data. This method will not hold on to buffer
,
so the caller is free to modify it after this method returns.offset
- The offset into buffer
where the audio data starts.length
- The number of bytes of audio data in buffer
. This must be
less than or equal to the return value of getMaxBufferSize()
.TextToSpeech.SUCCESS
, TextToSpeech.ERROR
or
TextToSpeech.STOPPED
.int done()
audioAvailable(byte[], int, int)
.
This method should only be called on the synthesis thread,
while in TextToSpeechService.onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
.
This method has to be called if start(int, int, int)
and/or error()
was called.TextToSpeech.SUCCESS
, TextToSpeech.ERROR
or
TextToSpeech.STOPPED
.void error()
TextToSpeechService.onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
.void error(int errorCode)
TextToSpeechService.onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
.errorCode
- Error code to pass to the client. One of the ERROR_ values from
TextToSpeech
boolean hasStarted()
start(int, int, int)
was called or not.
This method should only be called on the synthesis thread,
while in TextToSpeechService.onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
.
Useful for checking if a fallback from network request is possible.boolean hasFinished()
done()
was called or not.
This method should only be called on the synthesis thread,
while in TextToSpeechService.onSynthesizeText(android.speech.tts.SynthesisRequest, android.speech.tts.SynthesisCallback)
.
Useful for checking if a fallback from network request is possible.