Help Center> > API Reference > TTS API >TTS

TTS

Function

TTS converts text into lifelike voices. Users can access and call the API to synthesize the input text into audio and obtain the voice synthesis result in real time. TTS provides speech services with customizable timbres, speech volumes, and speeds for enterprises and individuals.

URI

URI format

POST /v1.0/voice/tts

Request

For details about the request parameters, see Table 1.
Table 1 Request parameter description

Parameter

Mandatory

Type

Description

text

Yes

String

Indicates the text to be synthesized, which can contain a maximum of 500 characters.

voice_name

No

String

Indicates the identifier of the synthesized voice:
  • Xiaoyan: female voice. It is the default voice identifier.
  • Xiaoqi: female voice
  • Xiaoyu: male voice

volume

No

Integer

Indicates the volume. Its value ranges from -20 to 20. The default value is 0.

sample_rate

No

String

Indicates the sampling rate.

8k indicates 8 kHz and 16k indicates 16 kHz. Currently, only 16 kHz is supported.

speech_speed

No

Integer

Indicates the speech speed. Its value ranges from -500 to 500. The default value is 0.

pitch_rate

No

Integer

Indicates the pitch. Its value ranges from -500 to 500. The default value is 0.

Response

For details about the response parameters, see Table 2.
Table 2 Response parameter description

Parameter

Type

Description

result

Object

Indicates the synthesized speech content when the API is successfully called.

This parameter is not included when the API fails to be called.

data

String

Indicates the synthesized speech data, which is returned in Base64 encoding format.

NOTE:

The voice data is output in .wav format.

error_code

String

Indicates the error code when the API fails to be called. For details, see Error Code.

This parameter is not included when the API is successfully called.

error_msg

String

Indicates the error message when the API fails to be called.

This parameter is not included when the API is successfully called.

Example

  • Request example
    POST https://{endpoint}/v1.0/voice/tts
       
    Request Header:  
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    
    Request Body:
    {
      "text":"This is a test sample.",
      "voice_name":"xiaoyan",
      "volume":"0",
      "sample_rate":"16k",
      "speech_speed":"0",
      "pitch_rate":"0"
    }
  • Successful response example
    {
      "result":{ 
      "data":"/+MgxAAUeHpMAUkQAANhuRACAIAgKHKQmRisVo0aNAgQIIQyCgGBiwfB8H4IAgCAJg+D4Ph+IAQBBywfB8HwQDGAwfB8Hwf..."
      }
    }  
  • Failed response example
    {
        "error_code": "SIS.0005",
        "error_msg": "The service does not exist."
    }

Status Code

For details about the status code, see Status Code.

Error Code

For details about the error code, see Error Code.