推送語音播報 API
註: 透過此 API 建立的語音播報,只能透過 API 進行取得、修改或刪除。
註: 語音檔案語言類型目前僅支援 "en"、"zh-Hans"、"zh-Hant"。
呼叫驗證
更多詳情請參考 REST API 概述中的驗證方式。
建立/更新語音播報
如果語音播報不存在,則建立;如果已存在,則更新。
呼叫位址
POST v4/voices
POST v4/voices
此代碼塊在浮窗中顯示
請求範例
請求標頭
POST /v4/voices
Authorization: Basic (base64 auth string)
Content-Type: multipart/form-data
Accept: multipart/form-data
POST /v4/voices
Authorization: Basic (base64 auth string)
Content-Type: multipart/form-data
Accept: multipart/form-data
此代碼塊在浮窗中顯示
請求資料
--form 'language="en"'
--form 'file="file"'
--form 'language="en"'
--form 'file="file"'
此代碼塊在浮窗中顯示
請求資料說明
language:指定語音播報檔案的語言,用於選擇使用者所需的語音播報語言。file:需要進行語音播報的 zip 檔案,包含所有必要的 mp3 檔案。
回應範例
成功回應
HTTP/1.1 200 OK
Server: fasthttp
Date: Thu, 01 Dec 2022 07:17:45 GMT
Content-Type: application/json
Content-Length: 85
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": ""
}
此代碼塊在浮窗中顯示
file_url:上傳檔案在華為雲 OBS 的下載位址。
失敗回應
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json; charset=utf-8
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json; charset=utf-8
此代碼塊在浮窗中顯示
{
"error": {
"code": 28400,
"message": "error message"
}
}
{
"error": {
"code": 28400,
"message": "error message"
}
}
此代碼塊在浮窗中顯示
語音檔案格式說明
本 API 支援的語音播報檔案需依指定的數字和單字進行命名,每個檔案格式為 .mp3。以下為支援的檔案命名細節:
英語(en):
- 數字:"0" 到 "20"、"30"、"40"、"50"、"60"、"70"、"80"、"90"、"100"、"1000"、"1000000"、"1000000000"
- 單字:"point"、"and"
中文(zh):
- 數字:"0" 到 "10"、"100"、"1000"、"10000"、"100000000"
- 單字:"point"
請確保所有檔案均為 MP3 格式,以便與系統正確整合。
取得語音播報列表
呼叫位址
GET v4/voices
請求範例
請求標頭
GET /v4/voices
Authorization: Basic (base64 auth string)
GET /v4/voices
Authorization: Basic (base64 auth string)
此代碼塊在浮窗中顯示
- 排序規則:依更新時間由新到舊排序。
回傳範例
成功回傳
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
此代碼塊在浮窗中顯示
[
{
"language":"en",
"file_url":""
}
]
[
{
"language":"en",
"file_url":""
}
]
此代碼塊在浮窗中顯示
- 回傳該應用程式下有效的語音播報列表。
- 回傳的
language為建立/更新時客戶請求的語言。 - 回傳的
file_url為建立/更新時客戶上傳檔案對應的華為雲 OBS 下載位址。
取得語音播報詳情
呼叫位址
GET v4/voices/{language}
請求範例
請求標頭
GET /v4/voices/en
Authorization: Basic (base64 auth string)
GET /v4/voices/en
Authorization: Basic (base64 auth string)
此代碼塊在浮窗中顯示
回傳範例
成功回傳
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
此代碼塊在浮窗中顯示
回傳資料
{
"file_url": ""
}
{
"file_url": ""
}
此代碼塊在浮窗中顯示
- 若
language不存在,則回傳 404;否則回傳實際的file_url,即上傳檔案對應的華為雲 OBS 下載位址。
刪除語音檔案
呼叫位址
DELETE v4/voices/{language}
請求範例
DELETE /v4/voices/en
Authorization: Basic (base64 auth string)
DELETE /v4/voices/en
Authorization: Basic (base64 auth string)
此代碼塊在浮窗中顯示
回傳範例
成功回傳
HTTP/1.0 200
Content-Type: application/json
Content-Length: 0
HTTP/1.0 200
Content-Type: application/json
Content-Length: 0
此代碼塊在浮窗中顯示
失敗回傳
language無效,或language不存在。
HTTP/1.0 404 Not Found
Content-Type: application/json
HTTP/1.0 404 Not Found
Content-Type: application/json
此代碼塊在浮窗中顯示
- 更新操作不合法
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json; charset=utf-8
HTTP/1.1 400 BAD REQUEST
Content-Type: application/json; charset=utf-8
此代碼塊在浮窗中顯示
{
"error": {
"code": 23903,
"message": "voice does not exist"
}
}
{
"error": {
"code": 23903,
"message": "voice does not exist"
}
}
此代碼塊在浮窗中顯示
錯誤碼
| Code | HTTP | 描述 | Error Message | 詳細解釋 |
|---|---|---|---|---|
| 28000 | 200 | 正確回傳 | nil | 成功狀態碼 |
| 28101 | 401 | 驗證失敗 | Basic authentication failed. | appkey、mastersecret 不相符。 |
| 28200 | 500 | 系統內部錯誤 | Server Internal error. | 發生未預期錯誤。 |
| 28203 | 503 | 系統內部錯誤,建議稍後重試 | Execute action timeout, please try later again | 與 schedule-server 通訊錯誤。 |
| 23903 | 404 | 請求參數錯誤 | voice does not exist | 語音播報不存在 |
| 23904 | 400 | 請求參數錯誤 | voice does not support this | 語音播報不支援此語言 |
