> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dreamto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Suno 创建自定义音色

> 提交用户朗读验证短语的录音，校验通过后生成可复用的自定义音色（Voice）。

`ai-music-api/create-voice` 是 Suno 自定义音色流程的第二步：用户朗读“生成验证短语”任务返回的短语并录音，把该任务的 `task_id` 和录音地址 `verify_url` 一起提交，系统校验录音后生成一个可复用的自定义音色，之后生成音乐时就能用这个声音演唱。

录音建议用**唱**的方式读出短语，干净的清唱人声效果最好。还可以附上音色名称、描述、风格和演唱水平等信息。

**Voice ID 就是验证短语任务的 `task_id`**（也会出现在本任务结果 `response.resultUrls[0]` 中），不是本接口返回的任务 ID。本任务创建后很快就会成功，这只表示请求已受理；音色是否可用要看验证短语任务：变为 `success` 表示音色已就绪（通常一分钟内），变为 `fail` 表示录音未通过校验。就绪后，在“生成音乐”等接口中传 `persona_id`（Voice ID）与 `persona_model: "voice_persona"` 即可使用。

## 接入

Suno 系列接口使用异步任务协议，所有接口共用 `POST /api/v1/jobs/createTask` 创建任务（`model` 选择接口，参数放在 `input` 中）和 `GET /api/v1/jobs/recordInfo?taskId=` 查询任务，传 `callBackUrl` 时任务结束后向该地址推送结果；流程、链式调用和文件保存期限见 [Suno 模型介绍](https://docs.dreamto.ai/music/suno.md)。服务地址为 `https://api.dreamto.ai`，API Key 放在 `Authorization: Bearer` 请求头。

所有响应的 HTTP 状态码都是 200，以响应体中的 `code` 判断结果：`200` 为成功，其余为错误（见各接口的响应示例）。

| 接口 | 用途 |
| - | - |
| [`POST /api/v1/jobs/createTask`](https://docs.dreamto.ai/api-reference/suno-voice-create/create-task) | 创建任务 |
| [`GET /api/v1/jobs/recordInfo?taskId=...`](https://docs.dreamto.ai/api-reference/suno-voice-create/query-task) | 查询任务 |
| [`POST callBackUrl`](https://docs.dreamto.ai/api-reference/suno-voice-create/task-callback) | 任务完成回调 |

## 参数范围

`model` 填 `ai-music-api/create-voice`，参数放在 `input` 中。不符合规则的请求返回 `code: 422`，不建任务、不扣费。

| 字段 | 取值 |
| - | - |
| `task_id` | 必填，“生成验证短语”任务的 `taskId`（等待录音中或已成功），即 Voice ID |
| `verify_url` | 必填，用户朗读验证短语的录音地址（`http` / `https`），建议唱出短语 |
| `voice_name` | 可选，音色名称 |
| `description` | 可选，音色描述 |
| `style` | 可选，音色风格 |
| `singer_skill_level` | 可选，`beginner`（默认）/ `intermediate` / `advanced` / `professional` |

## 计费

按次计费：每个成功的任务计一次费用，单价以控制台显示的模型价格为准。创建任务时按单价预检余额，余额不足返回 `code: 402`；参数错误、生成失败的任务不扣费。

## 快速开始

创建任务拿到 `data.taskId`，每 10 秒左右查询一次，`state` 为 `success` 时从 `response` 读取结果；也可以传 `callBackUrl` 在完成时接收回调。示例中的 `$DREAMTO_API_KEY` 为你的 API Key。

```bash cURL theme={null}
# 1. 创建任务
curl -X POST "https://api.dreamto.ai/api/v1/jobs/createTask" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ai-music-api/create-voice",
    "callBackUrl": "https://your-domain.com/api/callback",
    "input": {
      "task_id": "c2a81e5f09d34b7e8f61a2d4c9b03e75",
      "verify_url": "https://example.com/recordings/verify-phrase.mp3",
      "voice_name": "我的声音",
      "description": "温暖明亮的女中音",
      "style": "pop",
      "singer_skill_level": "intermediate"
    }
  }'

# 2. 查询任务
curl "https://api.dreamto.ai/api/v1/jobs/recordInfo?taskId=7d3f0a9c41e85b2f6a1c9e04b8d27f53" \
  -H "Authorization: Bearer $DREAMTO_API_KEY"
```

```python Python theme={null}
import os
import time

import requests

BASE_URL = "https://api.dreamto.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['DREAMTO_API_KEY']}"}

payload = {
    "model": "ai-music-api/create-voice",
    "callBackUrl": "https://your-domain.com/api/callback",
    "input": {
        "task_id": "c2a81e5f09d34b7e8f61a2d4c9b03e75",
        "verify_url": "https://example.com/recordings/verify-phrase.mp3",
        "voice_name": "我的声音",
        "description": "温暖明亮的女中音",
        "style": "pop",
        "singer_skill_level": "intermediate"
    }
}

created = requests.post(f"{BASE_URL}/api/v1/jobs/createTask", headers=HEADERS, json=payload, timeout=60).json()
if created["code"] != 200:
    raise SystemExit(f"{created['code']}: {created['msg']}")
task_id = created["data"]["taskId"]
while True:
    record = requests.get(f"{BASE_URL}/api/v1/jobs/recordInfo", headers=HEADERS, params={"taskId": task_id}, timeout=60).json()["data"]
    if record["state"] in ("success", "fail"):
        break
    time.sleep(10)
if record["state"] == "success":
    print("Voice ID:", record["response"]["resultUrls"][0])
else:
    print(record["failCode"], record["failMsg"])
```

## 任务回调

创建任务时传 `callBackUrl`（公网 `http` / `https` 地址），任务成功或失败后 DreamTo 向该地址 `POST` 一次结果（[回调格式](https://docs.dreamto.ai/api-reference/suno-voice-create/task-callback.md)）：成功时为 `{"code": 200, "msg": "success", "data": {"taskId", "status": "success", "errorCode": null, "errorMessage": ""}}`，`data.taskId` 为 Voice ID（验证短语任务的 `task_id`）；失败时 `code` 与 `data.errorCode` 为失败代码（非 `200`），`msg` 与 `data.errorMessage` 为原因，`data.status` 为 `fail`，`data.taskId` 同样为 Voice ID。签名使用本任务（创建音色任务）的 `taskId`，即创建响应中的 `data.taskId`，而不是回调体中的 Voice ID。本回调只表示创建请求已受理或失败；音色最终是否就绪请以验证短语任务的状态或其回调为准。

请求头带 `X-DreamTo-Event: task.completed`、`X-DreamTo-Timestamp`（UTC，RFC 3339）和 `X-DreamTo-Signature`：

```
X-DreamTo-Signature = hex( HMAC-SHA256( 密钥, X-DreamTo-Timestamp + "." + taskId + "." + status ) )
```

`status` 在任务成功时为 `success`，失败时为 `failed`。密钥在 DreamTo 控制台生成；未生成密钥时不发送签名头。返回任意 `2xx` 表示已收到，否则会重试。

## 使用说明

* 本任务的结果 `response.resultUrls` 只有一个元素：Voice ID（即验证短语任务的 `task_id`），不是文件链接。
* 音色是否就绪以验证短语任务为准：轮询它的查询任务接口，或在创建验证短语任务时传 `callBackUrl` 接收其最终回调（`status` 为 `success` 或 `fail`）。
* 如果录音未通过校验，可用“重新生成验证短语”接口为原任务换一句新短语，重新录音后再次提交本接口。
* `taskId` 由 DreamTo 生成（32 位十六进制），只能用同一账号的 API Key 查询；任务不存在或超过保存期限时查询返回 `code: 422`、`msg: recordInfo is null`。
* 请求体只接受 `model`、`callBackUrl`、`input`；`input` 中未声明的字段、类型错误和不符合规则的取值返回 `code: 422`，`msg` 为英文原因，不建任务、不扣费。
* 结果中的所有文件链接（音频、封面、视频等）都是 DreamTo 下载地址（`/v1/tasks/{task_id}/artifacts/...`），无需 API Key 即可下载，支持 `Range`；文件在任务创建后保留 14 天，请及时下载保存。
* `param` 原样回显创建任务时的请求，其中 `input` 是 JSON 字符串，需要再解析一次；查询结果不返回消耗积分，费用以 DreamTo 控制台账单为准。
* 失败任务的 `failCode` / `failMsg` 来自模型服务（如内容审核未通过、源音频无法下载）；服务内部错误统一为 `failCode: "500"`、`failMsg: "Internal Error, Please try again later."`。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.