public abstract class UtteranceProgressListener
extends Object
| java.lang.Object | |
| android.speech.tts.UtteranceProgressListener | |
监听者通过合成队列发现与话语进展有关的事件。 每个发声与到的呼叫相关联speak(CharSequence, int, Bundle, String)或synthesizeToFile(CharSequence, Bundle, File, String)与相关联的发声标识符,作为每KEY_PARAM_UTTERANCE_ID 。 此方法中指定的回调可以从多个线程中调用。
Public constructors |
|
|---|---|
UtteranceProgressListener() |
|
公共方法(Public methods) |
|
|---|---|
void |
onAudioAvailable(String utteranceId, byte[] audio) 这是在一大块音频准备好用于消费时调用的。 |
void |
onBeginSynthesis(String utteranceId, int sampleRateInHz, int audioFormat, int channelCount) 当TTS引擎开始综合请求的音频时调用。 |
abstract void |
onDone(String utteranceId) 当话语已成功完成处理时调用。 |
abstract void |
onError(String utteranceId) 此方法在API级别21中已弃用。请改为使用 |
void |
onError(String utteranceId, int errorCode) 在处理过程中发生错误时调用。 |
abstract void |
onStart(String utteranceId) 当主叫方感知到话语“开始”时调用。 |
void |
onStop(String utteranceId, boolean interrupted) 当话语在进行中停止或从综合队列中清除时调用。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
void onAudioAvailable (String utteranceId, byte[] audio)
这是在一大块音频准备好用于消费时调用的。
音频参数是合成到扬声器的内容的副本(当以speak(CharSequence, int, Bundle, String)调用启动合成时)或写入文件系统(对于synthesizeToFile(CharSequence, Bundle, File, String) )。 音频字节以一个或多个块传送; 如果onDone(String)或onError(String)则已收到所有组块。
此处接收的音频可能无法播放一段时间,具体取决于缓冲区大小和合成队列上的项目数量。
| 参数(Parameters) | |
|---|---|
utteranceId |
String: The utterance ID of the utterance. |
audio |
byte: A chunk of audio; the format can be known by listening to onBeginSynthesis(String, int, int, int). |
void onBeginSynthesis (String utteranceId, int sampleRateInHz, int audioFormat, int channelCount)
当TTS引擎开始综合请求的音频时调用。
它提供有关后续 onAudioAvailable(String, byte[])调用的字节数组格式的信息。
这在TTS引擎开始为请求合成音频时被调用。 如果应用程序希望知道音频什么时候开始播放,则应该使用{#onStart(String)}。
| 参数(Parameters) | |
|---|---|
utteranceId |
String: The utterance ID of the utterance. |
sampleRateInHz |
int: Sample rate in hertz of the generated audio. |
audioFormat |
int: Audio format of the generated audio. Should be one of ENCODING_PCM_8BIT, ENCODING_PCM_16BIT or ENCODING_PCM_FLOAT. |
channelCount |
int: The number of channels. |
void onDone (String utteranceId)
当话语已成功完成处理时调用。 所有音频都将在此点播放以进行声音输出,并且所有输出都将写入磁盘以进行文件合成请求。 保证在onStart(String)之后调用此请求。
| 参数(Parameters) | |
|---|---|
utteranceId |
String: The utterance ID of the utterance. |
void onError (String utteranceId)
此方法在API级别21中已弃用。
改为使用onError(String, int)
在处理过程中发生错误时调用。 这可以在合成过程的任何时候调用。 请注意,对于指定的发音号码可能会有onStart(String)的呼叫,但对于相同的发音,绝不会同时呼叫onDone(String)和onError(String) 。
| 参数(Parameters) | |
|---|---|
utteranceId |
String: The utterance ID of the utterance. |
void onError (String utteranceId, int errorCode)
在处理过程中发生错误时调用。 这可以在合成过程的任何时候调用。 请注意,对于指定的发音onStart(String)可能会有onStart(String)的呼叫,但对于相同的发音,绝不会同时呼叫onDone(String)和onError(String, int) 。 默认实现调用onError(String) 。
| 参数(Parameters) | |
|---|---|
utteranceId |
String: The utterance ID of the utterance. |
errorCode |
int: one of the ERROR_* codes from TextToSpeech |
void onStart (String utteranceId)
当主叫方感知到话语“开始”时调用。 在speak(CharSequence, int, Bundle, String)的情况下,或者在speak(CharSequence, int, Bundle, String)的情况下文件的第一个字节被写入文件系统之前,这将很快synthesizeToFile(CharSequence, Bundle, File, String) 。
| 参数(Parameters) | |
|---|---|
utteranceId |
String: The utterance ID of the utterance. |
void onStop (String utteranceId, boolean interrupted)
当话语在进行中停止或从综合队列中清除时调用。 如果客户端调用stop()或使用QUEUE_FLUSH作为speak(CharSequence, int, Bundle, String)或synthesizeToFile(CharSequence, Bundle, File, String)方法的参数,则会发生这种情况。
| 参数(Parameters) | |
|---|---|
utteranceId |
String: The utterance ID of the utterance. |
interrupted |
boolean: 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. |