如何生成语音
把文本转换为语音音频。
快速开始
语音生成速度够快,适合用同步模式:
bash
curl -X POST "https://api.get3w.com/v1/elevenlabs/eleven-3/text-to-speech?sync=true" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Welcome to Get3W, the unified AI platform."
}'python
import requests
response = requests.post(
"https://api.get3w.com/v1/elevenlabs/eleven-3/text-to-speech?sync=true",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
json={"text": "Welcome to Get3W, the unified AI platform."}
)
data = response.json()
print(data["outputs"][0])javascript
const response = await fetch(
"https://api.get3w.com/v1/elevenlabs/eleven-3/text-to-speech?sync=true",
{
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
text: "Welcome to Get3W, the unified AI platform."
})
}
);
const data = await response.json();
console.log(data.outputs[0]);outputs 数组包含生成音频文件的 URL。
可用模型
| Slug | 说明 |
|---|---|
elevenlabs/eleven-3/text-to-speech | 质量高,支持多语言 |
bilibili/index-tts-2/text-to-speech | 中文音色表现出色 |
bytedance/seed-audio-1/text-to-speech | 自然语言描述生成人声、音效、配乐,最长 120 秒;支持参考音频(@音频1)、音色 ID 或参考图片。¥1.1/分钟 |
音色选择、语速和语言选项因模型而异。在硬编码取值前,请先到 get3w.com/models 查看对应模型页面的参数 schema。
音乐生成
生成音乐(而非语音)请使用 text-to-music run type:
bash
curl -X POST "https://api.get3w.com/v1/minimax/music-2.6/text-to-music?sync=true" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Upbeat acoustic guitar, warm and optimistic, 120 bpm"
}'| Slug | 说明 |
|---|---|
minimax/music-2.6/text-to-music | 支持人声与纯乐器 |
elevenlabs/eleven-music/text-to-music | 纯乐器配乐 |
ace-step/ace-step-1.5/text-to-music | 生成速度快 |
语音转写
反方向的能力是 speech-to-text:
bash
curl -X POST "https://api.get3w.com/v1/openai/whisper-large-v3-turbo/speech-to-text?sync=true" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"audio_url": "https://your-cdn.com/recording.mp3"
}'对于 speech-to-text,outputs 中每一项是转写对象而不是文件 URL。Whisper 的 text 为完整文本,segments 为带时间戳(秒)的句级片段:
json
{
"outputs": [
{
"text": "你好,我们今天讨论项目进度。好的,我先汇报一下。",
"segments": [
{ "index": 1, "start": 0.1, "end": 3.82, "text": "你好,我们今天讨论项目进度。" },
{ "index": 2, "start": 3.82, "end": 6.5, "text": "好的,我先汇报一下。" }
]
}
]
}用 Qwen-Audio ASR 转写长音频
alibaba/qwen-audio-3.1-asr-flash-filetrans/speech-to-text 支持最长 12 小时的音视频。输入和输出与阿里云官方录音文件识别 API 一致:官方 input 和 parameters 里的字段直接平铺在请求体顶层,名称和取值不变。
bash
curl -X POST "https://api.get3w.com/v1/alibaba/qwen-audio-3.1-asr-flash-filetrans/speech-to-text" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"file_urls": ["https://your-cdn.com/meeting.mp3"],
"language_hints": ["zh", "en"],
"diarization_enabled": true
}'| 字段 | 类型 | 说明 |
|---|---|---|
file_urls | array of string | 必填,恰好 1 个可公网访问的 HTTP/HTTPS 音视频 URL |
language_hints | array of string | 最多 4 个语言代码,如 ["zh", "en"];不传则自动识别 |
diarization_enabled | boolean | 说话人分离(仅单声道,建议不超过 2 小时),开启后句子带 speaker_id |
speaker_count | integer | 说话人数量参考值,2-100,仅在 diarization_enabled 为 true 时生效 |
keep_dialect | boolean | 保留方言表达,不转为普通话,默认 false |
channel_id | array of integer | 要识别的音轨,默认 [0],每个音轨独立计费 |
vocabulary | object | 即时热词 {"词": 权重},权重 1-5 或 50(超级热词) |
context | array of object | 上下文增强,格式与官方消息结构一致 |
special_word_filter | string | 敏感词处理规则 |
outputs[0] 是官方识别结果 JSON 原文,外加顶层 text。时间单位为毫秒,words 为词级时间戳:
json
{
"outputs": [
{
"text": "你好,我们今天讨论项目进度。",
"file_url": "https://your-cdn.com/meeting.mp3",
"properties": { "audio_format": "pcm_s16le", "channels": [0], "original_sampling_rate": 16000, "original_duration_in_milliseconds": 3834 },
"transcripts": [
{
"channel_id": 0,
"content_duration_in_milliseconds": 3720,
"text": "你好,我们今天讨论项目进度。",
"sentences": [
{
"begin_time": 100, "end_time": 3820, "text": "你好,我们今天讨论项目进度。", "sentence_id": 1, "speaker_id": 0,
"words": [
{ "begin_time": 100, "end_time": 596, "text": "你好", "punctuation": "," },
{ "begin_time": 596, "end_time": 844, "text": "我们", "punctuation": "" }
]
}
]
}
]
}
]
}与官方 API 的差异:请求体平铺;outputs[0] 多一个 text;不支持 vocabulary_id(请用 vocabulary);不返回 task_id、transcription_url 等任务元数据;按 Get3W 价格计费。