Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public interface

SynthesisCallback

android.speech.tts.SynthesisCallback

Class Overview

A callback to return speech data synthesized by a text to speech engine. The engine can provide streaming audio by calling 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. After start(int, int, int) been called, done() must be called regardless of errors.

Summary

Public Methods
abstract int audioAvailable (byte[] buffer, int offset, int length)
The service should call this method when synthesized audio is ready for consumption.
abstract int done ()
The service should call this method when all the synthesized audio for a request has been passed to audioAvailable(byte[], int, int) .
abstract void error ()
The service should call this method if the speech synthesis fails.
abstract int getMaxBufferSize ()
abstract int start (int sampleRateInHz, int audioFormat, int channelCount)
The service should call this when it starts to synthesize audio for this request.

Public Methods

public abstract int audioAvailable (byte[] buffer, int offset, int length)

The service should call this method when synthesized audio is ready for consumption. This method should only be called on the synthesis thread, while in onSynthesizeText(SynthesisRequest, SynthesisCallback) .

Parameters
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() .
Returns

public abstract int done ()

The service should call this method when all the synthesized audio for a request has been passed to audioAvailable(byte[], int, int) . This method should only be called on the synthesis thread, while in onSynthesizeText(SynthesisRequest, SynthesisCallback) . This method has to be called if start(int, int, int) was called.

Returns

public abstract void error ()

The service should call this method if the speech synthesis fails. This method should only be called on the synthesis thread, while in onSynthesizeText(SynthesisRequest, SynthesisCallback) .

public abstract int getMaxBufferSize ()

Returns

public abstract int start (int sampleRateInHz, int audioFormat, int channelCount)

The service should call this when it starts to synthesize audio for this request. This method should only be called on the synthesis thread, while in onSynthesizeText(SynthesisRequest, SynthesisCallback) .

Parameters
sampleRateInHz Sample rate in HZ of the generated audio.
audioFormat Audio format of the generated audio. Must be one of the ENCODING_ constants defined in AudioFormat .
channelCount The number of channels. Must be 1 or 2 .
Returns