Push-to-Speech API
Note: Voice broadcasts created through this API can only be accessed, modified, or deleted via the API. Note: The voice file language type currently only supports "en", "zh-Hans", "zh-Hant".
Authentication
For more details, please refer to the REST API overview section on Authentication Methods.
Create/Update Voice Broadcast
Creates a new voice broadcast if it does not exist; updates it if it does.
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, used to select the required voice broadcast language.file
: The zip file needed for voice broadcast, containing all necessary mp3 files.
Response Example
Success 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 on Huawei Cloud OBS.
Failure Response
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json; charset=utf-8
{
"error": {
"code": 28400,
"message": "error message"
}
}
Audio File Specifications
The audio files for this API should be named according to specified numbers and words, each file format being .mp3
. Below are the naming details 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"
Ensure all files are MP3 format for correct system integration.
Retrieve Voice Broadcast List
Endpoint
GET v4/voices
Request Example
Request Headers
GET /v4/voices
Authorization: Basic (base64 auth string)
- Sort order: Newest updates first.
Response Example
Successful Return
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
{
"language":"en",
"file_url":""
}
]
- Returns the list of valid voice broadcasts under that application.
language
is as requested during creation/update.file_url
is the Huawei Cloud OBS download URL of the uploaded file.
Retrieve Voice Broadcast Details
Endpoint
GET v4/voices/{language}
Request Example
Request Headers
GET /v4/voices/en
Authorization: Basic (base64 auth string)
Response Example
Successful Return
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Response Data
{
"file_url": ""
}
- If
language
does not exist, returns 404, otherwise returns the actualfile_url
which is the Huawei Cloud OBS download URL of 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 Return
HTTP/1.0 200
Content-Type: application/json
Content-Length: 0
Failure Return
- If
language
is invalid or does not exist.
HTTP/1.0 404 Not Found
Content-Type: application/json
- If the update operation is illegal.
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json; charset=utf-8
{
"error": {
"code": 28400,
"message": "error message"
}
}
Error Codes
Code | HTTP Status | Description | Error Message | Detailed Explanation |
---|---|---|---|---|
28000 | 200 | Successful response | nil | Success status code |
28101 | 401 | Authentication failure | Basic authentication failed. | Appkey and masterscrect do not match. |
28200 | 500 | Internal server error | Server Internal error. | An unanticipated error occurred. |
28203 | 503 | Internal server error, please try again later | Execute action timeout, please try later again | Communication error with schedule-server. |