文件

TTS 多人聲音配音

Service: https://tts.api.yating.tw/

藉由文本及參數,讓音檔內的文字對話轉換為其他語言的配音。


發起需求

在處理完所有輸入後,一般情況下,回應時間是音檔長度的一半。

Request

URL: /v3/dubs
Method: POST

Header

Name Type Info
*key String
*Content-Type String Only “application/json”

Body

Name Type Info
*audioUri String 放入音檔連結,並確保聯結是公開的,並且可以被我方下載。
*sentences sentence[ ] 有關每個音檔的內容格式請看「Sentence 設定」
*audioConfig JSON 有關產出的聲音格式請看「audioConfig 設定」

Sentence設定

Variables Type Info
*speakerId String 使用者自訂義的語者名稱,Candy, Cindy …etc.
*modelSpeakerId String 系統支援的語者模型,放入指定的聲音模型,除支援以下模型外,可帶入由
/cloning/speaker 取得的 speaker id
zh_en_chao_ai
speaker_id from /cloning/speaker
若是未設定數值,系統將會將依照
speakerId 跟 modelSpeakerId是一對一關係,一次request中,相同的 speaker Id 需要對應一樣 modelSpeakerId,系統會判斷
是否有重複的 speakerId,並依設定自動帶入其 modelSpeakerId
無任何對應的modelSpeakerId,則由系統自動分群,產生最佳的modelSpeakerId
*sentence 要生成音頻的文本。要生成音頻的文本。
如果是一般文字內容,最大文本長度為 600 個字符。
請注意,一個中文字用 2 個字符計算,全形符號兩個字符,半形符號與空格一個字符。
*lang String 語言列表
英文 (en_us)
日文 (ja_jp)
法文 (fr_fr)
德文 (de_de)
韓文 (ko_kr)
波蘭文 (pl_pl)
葡萄牙文 (pt_br)
俄文 (ru_ru)
西班牙文 (es_es)
印尼文(id_id)
瑞典文(sv_se)
泰文(th_th)
土耳其文(tr_tr)
越南文(vi_vn)
匈牙利文 (hu_hu)
義大利文 (it_it)
中文 (zh_tw)
*start int 起始時間
單位為ms
*end int 結束時間
單位為ms

AudioConfig 設定

Variables Type Info
*encoding String 查看「音訊編碼」

Encoding 音訊編碼
除了聲音類型,還可以選擇音頻輸出格式。 目前支持 MP3 和 LINEAR16。

codec Name Note
LINEAR16 Linear PCM WAV音檔編碼格式。16 位線性脈衝編碼調製 (PCM) 編碼。 標頭必須包含採樣率。
MP3 MP3 MP3格式」

Request Body Example

{
    "audioUri":"http://...",
    "sentences":[
        {
            "speakerId": "aaa",
            "modelSpeakerId": "cc123",
            "sentence": "this is an Apple",
            "lang":"en_us",
            "start": 99,
            "end": 5094
        },
        {
            "speakerId": "aaa",
            "modelSpeakerId": "",
            "sentence": "this is an Apple",
            "lang":"en_us",
            "start": 5027,
            "end": 22728
        }
    ],
    "audioConfig":{
        "encoding":"MP3"
    }
}

Response Body Example

{
    "uid": "4deb52c3-9f22-4415-b515-858d2caeb7f1",
    "audioUri": "http://...",
    "audioEncoding": "MP3",
    "taskId": "81e79a1c-fc9e-4780-bd1b-ad37352262b4",
    "status": "completed",
    "createdAt": "2022-11-22T16:49:25.835Z",
    "updatedAt": "2022-11-22T16:49:35.000Z",
    "sentences": [
        {
            "sentence": "2022-11-22T16:49:35.000Z",
            "speakerId": "2022-11-22T16:49:35.000Z",
            "modelSpeakerId": "2022-11-22T16:49:35.000Z",
            "lang": "en_us",
            "start": 5027,
            "end": 22728
            "audioFile": {
                "fileName": "tts-audio/audio.mp3",
                "fileHash": "23bb4f6526c6254c73e12009b8d25591edfb32e8",
                "url": "http://...",
                "expiredAt": ""
            }
        },
    ]
}

處理狀態查詢

提交後,“狀態”鍵將從“待處理”變為“處理中”,最後變為“完成”。 如果出現問題,就會進入“錯誤”。 您可以發出 GET 請求,如下所示,以檢查轉錄狀態的更新。

您必須重複 GET 請求,直到您的狀態為“完成”或“錯誤”。 一旦狀態鍵顯示為“已完成”,您就可以從 path 拿到新的連結,並且可以直接下載檔案。

Request

URL: /v3/dubs?page=1&perPage=10&status=pending
Method: GET

Header

Name Type Info
*key String

Query String Parameter

Name Info
page number
perPage number
status pending, ongoing, completed, error. If no value, get all list

Response Body Example

{
   "page":2,
   "perPage":10,
   "total":21,
   "nextPage":3,
   "data":[
      {
         "uid":"61e019c0-9586-4a7e-afe5-ea2cbc3670f2",
         "audioUri":"http://...",
         "audioEncoding": "LINEAR16",
         "taskId":"74fb6122-af46-4578-acd1-eb25aac8a893",
         "status":"ongoing",
         "createdAt":"2022-11-22T16:49:25.835Z",
         "updatedAt":"2022-11-22T16:49:35.000Z"
      }
   ]
}

取得配音結果

只要你的音檔狀態是 completed,你即可從以下 resultUrl 中取得處理後的音檔連結,並進行下載。

請注意,一但音檔完成後,因為安全問題,檔案只會保留 24 小時,超過就漚會自動刪除。

Request

URL: /v3/dubs/{uid}
Method: GET

Header

Name Type Info
*key String

Path Parameter

Name Info
uid string, uid.

Response Body Example

{
   "audioUrl":"http://...",
   "content":[
      {
         "speakerId":"aaa",
         "sentence":"this is an Apple",
         "language":"en"
         "start":99,
         "end":5004,
         "modelSpeakerId":"aaa1",
         "audioUrl":"http://..."
      },
      {
         "speakerId":"ccc",
         "sentence":"this is an Apple",
         "language":"en"
         "start":5027,
         "end":22728,
         "modelSpeakerId":"ccc1",
         "audioUrl":"http://..."
      }
   ],
   "config":{
      "encoding":"LINEAR16"
   },
   "resultUrl":"http://..."
   "taskId":"74fb6122-af46-4578-acd1-eb25aac8a893",
   "status":"ongoing",
   "createdAt":"2022-11-22T16:49:25.835Z",
   "updatedAt":"2022-11-22T16:49:35.000Z"
}