目录

com.huawei.hms.mlsdk.tts.MLTtsEngine

Describes the TTS engine.

Constant Summary

TypeNameDesc

int

EXTERNAL_PLAYBACK

The audio synthesized by the TTS engine is not automatically played by the internal player.

int

OPEN_STREAM

The audio synthesized by the TTS engine is returned to the app through onAudioAvailable.

intQUEUE_APPENDSerial queuing mode. In this mode, multiple TTS tasks are executed in the call sequence.
intQUEUE_FLUSHQueue clear mode. In this mode, the TTS tasks to be executed are cleared, the TTS task being executed is stopped, and a specified TTS task is executed.

Public Constructor Summary

Constructor name
MLTtsEngine(MLTtsConfig config)Constructor.

Public Method Summary

Return typeMethod name
voidpause()
voidresume()
voidsetTtsCallback(MLTtsCallback callback)
voidshutdown()
Stringspeak(String text, int mode)
voidstop()
voidupdateConfig(MLTtsConfig mlConfigs)

Constants

Constant
public static final int EXTERNAL_PLAYBACK

The audio synthesized by the TTS engine is not automatically played by the internal player.

Constant value: 2

Constant
public static final int OPEN_STREAM

The audio synthesized by the TTS engine is returned to the app through onAudioAvailable.

Constant value: 4

Constant
public static final int QUEUE_APPEND

Serial queuing mode. In this mode, multiple TTS tasks are executed in the call sequence.

Constant value: 0

Constant

public static final int QUEUE_FLUSH

Queue clear mode. In this mode, the TTS tasks to be executed are cleared, the TTS task being executed is stopped, and a specified TTS task is executed.

Constant value: 1

Public Constructors

Method
public MLTtsEngine(MLTtsConfig config)
Constructor.

Parameters

Parameter nameParameter desc
configParameter.

Public Methods

Method

public void pause()

Pauses playback.
Method

public void resume()

Resumes playback.
Method

public void setTtsCallback(MLTtsCallback callback)

Sets the callback API of the TTS engine.

Parameters

Parameter nameParameter desc
callbackCallback API instance for listening to TTS task progress.
Method

public void shutdown()

Releases engine resources when the engine is not required. The engine is unavailable after this method is called.
Method

public String speak(String text, int queueMode)

Implements TTS and plays speech in real time.

Queuing mode. After a TTS task is generated, the TTS task is processed as follows:

-If a TTS task is being played, the new TTS task is added to the queue for execution in sequence.

-If playback of a TTS task is paused, the playback is resumed, and then the new TTS task is added to the queue for execution in sequence.

-If there is no playback task currently, the new TTS task is executed immediately.

Queue clear mode. The synthesis task and playback task being executed are stopped immediately, all TTS tasks in the queue are cleared, and the new TTS task is immediately executed.

Parameters

Parameter nameParameter desc
textText to be converted to speech. The text can contain a maximum of 500 characters. That is, the value of text.length() cannot be greater than 500. The text encoding format is UTF-8.
queueModeTTS playback mode. Currently, QUEUE_APPEND and QUEUE_FLUSH are supported.

Return

Typedesc
StringID of a TTS task.
Method

public void stop()

Stops the current TTS task, clears all tasks (tasks that are being played and have not been played) in the queue, and retains the TTS engine.
Method

public void updateConfig(MLTtsConfig mlConfigs)

Updates TTS engine configurations. The configurations take effect when the next TTS task is executed.

Parameters

Parameter nameParameter desc
mlConfigsConfiguration instance.