Describes the TTS engine.
| Type | Name | Desc |
int | The audio synthesized by the TTS engine is not automatically played by the internal player. | |
int | The audio synthesized by the TTS engine is returned to the app through onAudioAvailable. | |
| int | QUEUE_APPEND | Serial queuing mode. In this mode, multiple TTS tasks are executed in the call sequence. |
| 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. |
| Constructor name |
| MLTtsEngine(MLTtsConfig config)Constructor. |
| Return type | Method name |
| void | pause() |
| void | resume() |
| void | setTtsCallback(MLTtsCallback callback) |
| void | shutdown() |
| String | speak(String text, int mode) |
| void | stop() |
| void | updateConfig(MLTtsConfig mlConfigs) |
| 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 |
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 |
| Method |
| public MLTtsEngine(MLTtsConfig config) |
| Constructor. |
Parameters
| Parameter name | Parameter desc |
| config | Parameter. |
| Method |
| Pauses playback. |
| Method |
| Resumes playback. |
| Method |
public void setTtsCallback(MLTtsCallback callback) |
Sets the callback API of the TTS engine.
Parameters
| Parameter name | Parameter desc |
| callback | Callback API instance for listening to TTS task progress. |
| Method |
| Releases engine resources when the engine is not required. The engine is unavailable after this method is called. |
| Method |
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 name | Parameter desc |
| text | Text 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. |
| queueMode | TTS playback mode. Currently, QUEUE_APPEND and QUEUE_FLUSH are supported. |
Return
| Type | desc |
| String | ID of a TTS task. |
| Method |
| 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 name | Parameter desc |
| mlConfigs | Configuration instance. |