音频端点
POST /v1/audio/speech 把文本转成语音(OpenAI 的请求格式,另加音色设计、克隆、语言和情绪),/v1/audio/voices 保存用于克隆的声音样本——创建、列出、获取、重命名、下载和删除。
合成语音#
/v1/audio/speech朗读 input 并返回音频文件。音频秒数在 x-lovely-audio-seconds 响应头里,调用 id 在 x-lovely-request-id 里。按生成音频的秒数计费(至少 1 秒);失败的请求不收费。
请求体参数
modelstring必填qwen3-tts 或 zonos2(GET /v1/models 会列出它们及价格)。
inputstring必填要朗读的文本,最长 4,096 个字符。
voicestring or object模型的预置音色、OpenAI 音色名(alloy、nova、onyx 等会映射到预置音色),或已保存声音的 id(voice_…,也可写成 {"id": "voice_…"})。可选:不传时模型按 language 选预置音色,或 qwen3-tts 按 instructions 设计音色。
instructionsstring仅 qwen3-tts,最长 1,000 个字符。有音色时:说话方式(情绪、语速、音量、耳语)。没有音色时:要生成的声音的描述。
languagestringISO 语言代码(en、zh、ja、ko、de、fr、pt-br 等)或 auto(默认)。对短文本和数字有帮助。
response_formatstring默认 mp3mp3、opus、aac、flac、wav 或 pcm(16 位,24 kHz 单声道)。
speednumber默认 1.00.25 到 4.0;音高不变。
emotionstring or object仅 zonos2:happy、sad、angry 或 surprised,或 0 到 1 的权重,例如 {"happy": 0.7}。
seedinteger用于可复现的输出,0 到 2147483647。
reference_audiostring一次性克隆的声音:3–15 秒录音的 https URL、data: URL 或 base64(WAV、MP3、M4A、OGG、FLAC 或 WebM,最大 10 MB)。不能与 voice 同时使用。
reference_textstringreference_audio 里说的内容(有了它 qwen3-tts 克隆得更接近)。
consentboolean使用 reference_audio 时必填:你确认这是你自己的声音,或已获得说话人的许可。
错误使用通用格式:400 invalid_request_error,param 指出出错的字段(未知音色、在 zonos2 上传 instructions、在 qwen3-tts 上传 emotion、缺少 consent);余额不足为 402;未知模型或他人的声音为 404;合成失败为 502(不收费)。
curl https://lovelyrouter.com/v1/audio/speech \
-H "Authorization: Bearer $LOVELY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-tts",
"input": "Hello! Nice to meet you.",
"voice": "serena",
"instructions": "Friendly and upbeat"
}' \
--output hello.mp3声音对象#
属性
idstringvoice_ 加 24 个字符。作为 voice 使用。
objectstring固定为 voice。
namestring最长 80 个字符。
transcriptstring | null样本里说的内容。
typestring样本的格式,例如 audio/wav。
bytesinteger样本大小。
audio_urlstring下载样本(需要 API 密钥)。
created_atintegerUnix 秒。
{
"id": "voice_8f2c4a1e9b7d3f60a5c2e1d4",
"object": "voice",
"name": "Narrator",
"transcript": "Thanks for listening. See you next week on the show.",
"type": "audio/wav",
"bytes": 482044,
"audio_url": "https://lovelyrouter.com/v1/audio/voices/voice_8f2c4a1e9b7d3f60a5c2e1d4/audio",
"created_at": 1792915200
}保存声音#
/v1/audio/voices保存声音样本,返回 201 和声音对象。用 multipart(样本作为 file)或 JSON(audio 为 https 或 data: URL)发送。免费;每个账户最多 100 个,删除前一直保留。
请求体参数
namestring必填最长 80 个字符。
filefile (or `audio` string)必填3 到 15 秒、单人清晰说话、没有音乐:WAV、MP3、M4A、OGG/Opus、FLAC 或 WebM,最大 10 MB。
transcriptstring样本里说的内容,最长 1,000 个字符。
consentboolean必填true:这是你自己的声音,或你已获得说话人的克隆许可。
curl https://lovelyrouter.com/v1/audio/voices \
-H "Authorization: Bearer $LOVELY_API_KEY" \
-F name="Narrator" \
-F transcript="Thanks for listening. See you next week on the show." \
-F consent=true \
-F file=@narrator.wav删除声音#
/v1/audio/voices/{id}永久删除声音及其样本:{"id": "voice_…", "object": "voice", "deleted": true}。使用它的角色将不再有声音。