文件
AI Music_音樂生成(Beta-v2)
Service: https://arts.api.yating.tw/v1
輸入文字 prompt,AI 幫你產生音樂。
發起請求
Request
URL: /textToMusic
Method: POST
Header
| Name | Type | Info | 
|---|---|---|
| *key | String | |
| *Content-Type | String | Only “application/json” | 
Body
| Name | Type | Info | 
|---|---|---|
| *text | string | prompt,只允許英文和空格,例如 guitar solo bossa nova C minor | 
| *config | JSON | length: 音檔長度,允許 1~12 的整數 | 
Request Body Example
{
   "text": "guitar solo bossa nova C minor",
   "config":{
      "length": 8 
   }
}
      Response Body Example
{
    "uid": "33e90b1d-81d3-4656-91c4-a5c626cbc396",
    "status": "pending",
    "createdAt": "2024-03-06T14:42:57.607Z",
    "updatedAt": "2024-03-06T14:42:57.000Z"
}
      取得音檔結果
從 POST Method 的 response 取得任務 uid ,當作這個 endpoint 的 parameter,便可取得任務狀態。
需要不斷呼叫此方法,直到 response status 顯示為 completed 或者是 error,只要 status 是 completed,即可從 response 中的 audioUrl 取得處理後的音檔連結,並進行下載。
Request
URL: /textToMusic/{uid}
Method: GET
Header
| Name | Type | Info | 
|---|---|---|
| *key | String | 
Query parameter
| Name | Info | 
|---|---|
| uid | POST method  response 取得的任務 uid,如上述例子的 313fb766-cf44-421c-b818-6127ed91d739 | 
Response Body Example
{
    "uid": "33e90b1d-81d3-4656-91c4-a5c626cbc396",
    "status": "completed",
    "text": "guitar solo bossa nova C minor",
    "config": {
        "length": 8
    },
    "audioUrl": "SOME_URL_HERE"
}
      取得任務列表及狀態
此 endpoint 可一次列出多項任務的狀態及 response,透過以下參數決定顯示的範圍。
Request
URL: /textToMusic?page=1&perPage=10&status=pending
Method: GET
Header
| Name | Type | Info | 
|---|---|---|
| *key | String | 
Query parameter
| Name | Type | Info | 
|---|---|---|
| page | number | 頁數,如輸入 N 即會得到第 N 頁的結果 | 
| perPage | number | 每頁顯示的任務數量 | 
| status | string | 只顯示此種 status 的任務,只允許輸入 pending, ongoing, completed, error | 
{
    "page": 1,
    "perPage": 10,
    "total": 2,
    "nextPage": null,
    "data": [
        {
            "uid": "4d4a2cf1-1e9f-41a7-998d-23d4ad55b8b6",
            "taskId": "02b4a999-fabe-49e4-ae50-bc897fd0aec8",
            "status": "completed",
            "createdAt": "2024-03-06T04:54:49.577Z",
            "updatedAt": "2024-03-06T04:55:19.000Z",
            "text": "guitar solo bossa nova C minor",
            "config": {
                "length": 8
            },
            "audioUrl": "SOME_URL_HERE_1"
        },
        {
            "uid": "33e90b1d-81d3-4656-91c4-a5c626cbc396",
            "taskId": "567fe604-ad64-49ef-bd62-ebe852508b12",
            "status": "completed",
            "createdAt": "2024-03-06T14:42:57.607Z",
            "updatedAt": "2024-03-06T14:43:47.000Z",
            "text": "guitar solo bossa nova C minor",
            "config": {
                "length": 8
            },
            "audioUrl": "SOME_URL_HERE_2"
        }
    ]
}