# Text to Speech (TTS)
Text to speech (TTS) functions.
# Manifest Declaration
You need to declare the use of this API in the manifest's features member:
{"name": "system.tts"}
# Module Import
Before using this service in a component, you need to import the module in the script section of the UX document.
import tts from '@system.tts'
Or
let tts = require("@system.tts")
# Methods
This service has the following method:
# speak({text,queueMode,volume,success,fail,complete})
This method speaks the specified text.
# Arguments
This method requires an object with the following attributes:
text(string). Mandatory attribute with the content to be spoken.queueMode(number). Optional attribute with the mode of the queue (1for add to the queue and0to flush the queue). The default value is1(add).volume(number). Optional attribute with the audio volume from0.0(silence) to1.0(highest). By default the system volume will be used.success(function(res)). Optional callback function for success.fail(function(code)). Optional callback function for failure, with the potential codes:200General error.202Invalid parameter.1001Network connection error.1002Network connection timed out.1003Voice data download is not completed.1004Failed to play the audio on an audio device.1005The TTS service failed.1006Text to speech failed.
complete(function()). Optional callback function for completion.
Example:
tts.speak ({
text: 'Testing, testing',
volume: 1,
queueMode: 0,
success: function(data) {
console.log("handling success");
},
fail: function(data, code) {
console.log("handling fail, code=" + code);
}
})