public interface SynthesisCallback
| android.speech.tts.SynthesisCallback |
回传文本到语音引擎合成的语音数据。 引擎可以通过调用start(int, int, int) ,然后audioAvailable(byte[], int, int)提供流式音频,直到提供了所有音频,然后最终done() 。 可以在综合过程的任何阶段调用error()以指示发生了错误,但是如果在调用done()之后进行调用,则可能会丢弃它。 必须在综合结束时调用done() ,而不管错误。 所有方法只能在综合线程上调用。
公共方法(Public methods) |
|
|---|---|
abstract int |
audioAvailable(byte[] buffer, int offset, int length) 当合成音频准备好消耗时,该服务应该调用此方法。 |
abstract int |
done() 当请求的所有合成音频已传递到 |
abstract void |
error(int errorCode) 如果语音合成失败,该服务应该调用此方法。 |
abstract void |
error() 如果语音合成失败,该服务应该调用此方法。 |
abstract int |
getMaxBufferSize() |
abstract boolean |
hasFinished() 检查是否 |
abstract boolean |
hasStarted() 检查是否 |
abstract int |
start(int sampleRateInHz, int audioFormat, int channelCount) 当服务开始为这个请求合成音频时,该服务应该调用它。 |
int audioAvailable (byte[] buffer,
int offset,
int length)
当合成音频准备好消耗时,该服务应该调用此方法。 此方法只应在合成线程上调用,而在onSynthesizeText(SynthesisRequest, SynthesisCallback) 。
| 参数(Parameters) | |
|---|---|
buffer |
byte: 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 |
int: The offset into buffer where the audio data starts. |
length |
int: The number of bytes of audio data in buffer. This must be less than or equal to the return value of getMaxBufferSize(). |
| 返回(Returns) | |
|---|---|
int |
SUCCESS, ERROR or STOPPED. |
int done ()
当请求的所有合成音频已传递到audioAvailable(byte[], int, int)时,该服务应调用此方法。 此方法只应在合成线程上调用,而在onSynthesizeText(SynthesisRequest, SynthesisCallback) 。 如果调用start(int, int, int)和/或error()则必须调用此方法。
| 返回(Returns) | |
|---|---|
int |
SUCCESS, ERROR or STOPPED. |
void error (int errorCode)
如果语音合成失败,该服务应该调用此方法。 此方法只应在合成线程上调用,而在onSynthesizeText(SynthesisRequest, SynthesisCallback) 。
| 参数(Parameters) | |
|---|---|
errorCode |
int: Error code to pass to the client. One of the ERROR_ values from TextToSpeech |
void error ()
如果语音合成失败,该服务应该调用此方法。 该方法只应在合成线程上调用,而在onSynthesizeText(SynthesisRequest, SynthesisCallback) 。
int getMaxBufferSize ()
| 返回(Returns) | |
|---|---|
int |
the maximum number of bytes that the TTS engine can pass in a single call of audioAvailable(byte[], int, int). Calls to audioAvailable(byte[], int, int) with data lengths larger than this value will not succeed. |
boolean hasFinished ()
检查done()被调用。 此方法只应在合成线程上调用,而在onSynthesizeText(SynthesisRequest, SynthesisCallback) 。 用于检查是否可以从网络请求回退。
| 返回(Returns) | |
|---|---|
boolean |
|
boolean hasStarted ()
检查是否start(int, int, int) 。 此方法只应在合成线程上调用,而在onSynthesizeText(SynthesisRequest, SynthesisCallback) 。 用于检查是否可以从网络请求回退。
| 返回(Returns) | |
|---|---|
boolean |
|
int start (int sampleRateInHz,
int audioFormat,
int channelCount)
当服务开始为这个请求合成音频时,该服务应该调用它。 此方法只应在合成线程上调用,而在onSynthesizeText(SynthesisRequest, SynthesisCallback) 。
| 参数(Parameters) | |
|---|---|
sampleRateInHz |
int: Sample rate in HZ of the generated audio. |
audioFormat |
int: Audio format of the generated audio. Must be one of ENCODING_PCM_8BIT or ENCODING_PCM_16BIT. Can also be ENCODING_PCM_FLOAT when targetting Android N and above. |
channelCount |
int: The number of channels. Must be 1 or 2. |
| 返回(Returns) | |
|---|---|
int |
SUCCESS, ERROR or STOPPED. |