Push-to-Speech API
Note: Voice broadcasts created through this API can only be retrieved, modified, or deleted through the API.
Note: The currently supported language types for voice files are "en", "zh-Hans", and "zh-Hant" only.
Authentication
For more details, refer to the Authentication Method section in the REST API Overview.
Create/Update Voice Broadcast
If the voice broadcast does not exist, it will be created. If it already exists, it will be updated.
Endpoint
POST v4/voices
Request Example
Request Headers
POST /v4/voices
Authorization: Basic (base64 auth string)
Content-Type: multipart/form-data
Accept: multipart/form-data
Request Data
--form 'language="en"'
--form 'file="file"'
Request Data Description
language: Specifies the language of the voice broadcast file and is used to select the voice broadcast language required by the user.file: The ZIP file used for voice broadcast, containing all required MP3 files.
Response Example
Successful Response
HTTP/1.1 200 OK
Server: fasthttp
Date: Thu, 01 Dec 2022 07:17:45 GMT
Content-Type: application/json
Content-Length: 85
{
"file_url": ""
}
file_url: The download URL of the uploaded file in Huawei Cloud OBS.
Failed Response
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json; charset=utf-8
{
"error": {
"code": 28400,
"message": "error message"
}
}
Voice File Format Description
Voice broadcast files supported by this API must be named according to the specified numbers and words, and each file must use the .mp3 format. The following naming conventions are supported:
English (en):
- Numbers: "0" to "20", "30", "40", "50", "60", "70", "80", "90", "100", "1000", "1000000", "1000000000"
- Words: "point", "and"
Chinese (zh):
- Numbers: "0" to "10", "100", "1000", "10000", "100000000"
- Words: "point"
Make sure all files are in MP3 format to ensure proper system integration.
Get Voice Broadcast List
Endpoint
GET v4/voices
Request Example
Request Headers
GET /v4/voices
Authorization: Basic (base64 auth string)
- Sorting rule: Ordered by update time, with the most recent first.
Response Example
Successful Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
{
"language": "en",
"file_url": ""
}
]
- Returns a list of valid voice broadcasts under this application.
- The returned
languageis the language requested by the client during creation or update. - The returned
file_urlis the Huawei Cloud OBS download URL corresponding to the file uploaded by the client during creation or update.
Get Voice Broadcast Details
Endpoint
GET v4/voices/{language}
Request Example
Request Headers
GET /v4/voices/en
Authorization: Basic (base64 auth string)
Response Example
Successful Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Response Data
{
"file_url": ""
}
- If the language does not exist,
404is returned. Otherwise, the actualfile_urlreturned is the Huawei Cloud OBS download URL corresponding to the uploaded file.
Delete Voice File
Endpoint
DELETE v4/voices/{language}
Request Example
DELETE /v4/voices/en
Authorization: Basic (base64 auth string)
Response Example
Successful Response
HTTP/1.0 200
Content-Type: application/json
Content-Length: 0
Failed Response
- Invalid language, or the language does not exist.
HTTP/1.0 404 Not Found
Content-Type: application/json
- Invalid update operation.
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json; charset=utf-8
{
"error": {
"code": 23903,
"message": "voice does not exist"
}
}
Error Codes
| Code | HTTP | Description | Error Message | Detailed Explanation |
|---|---|---|---|---|
| 28000 | 200 | Correct response returned | nil | Success status code |
| 28101 | 401 | Authentication failed | Basic authentication failed. | appkey and mastersecret do not match. |
| 28200 | 500 | Internal system error | Server Internal error. | An unexpected error occurred. |
| 28203 | 503 | Internal system error; retrying later is recommended | Execute action timeout, please try later again | Communication error with schedule-server. |
| 23903 | 404 | Request parameter error | voice does not exist | The voice broadcast does not exist |
| 23904 | 400 | Request parameter error | voice does not support this | The voice broadcast does not support this language |
