- Third-party
xAI 的 Grok 文本转语音模型。可使用 5 种富有表现力的音色(eve、ara、rex、sal、leo)生成高保真语音,支持 20 多种语言。支持用于笑声、耳语和停顿的内联语音标签。
| 模型信息 | |
|---|---|
| 条款和许可证 | 链接 ↗ |
| 更多信息 | 链接 ↗ |
| 定价 | 在 Cloudflare 仪表板中查看定价 ↗ |
用法
const response = await env.AI.run(
'xai/grok-tts',
{ text: 'Hello! Welcome to the xAI Text to Speech API.', language: 'en' },
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-tts",
"input": {
"text": "Hello! Welcome to the xAI Text to Speech API.",
"language": "en"
}
}'{
"state": "Completed",
"result": {
"audio": "https://examples.aig.cloudflare.com/xai/grok-tts/simple-generation.mp3"
},
"gatewayMetadata": {
"keySource": "Unified"
}
}示例
不同音色 — 使用温暖、对话感强的 `ara` 音色
const response = await env.AI.run(
'xai/grok-tts',
{ text: 'Thank you for calling. How can I help you today?', voice_id: 'ara', language: 'en' },
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-tts",
"input": {
"text": "Thank you for calling. How can I help you today?",
"voice_id": "ara",
"language": "en"
}
}'{
"state": "Completed",
"result": {
"audio": "https://examples.aig.cloudflare.com/xai/grok-tts/different-voice.mp3"
},
"gatewayMetadata": {
"keySource": "Unified"
}
}高保真 MP3 — 适用于生产环境的 44.1 kHz / 192 kbps MP3
const response = await env.AI.run(
'xai/grok-tts',
{
text: 'Crystal clear audio at maximum quality.',
voice_id: 'rex',
language: 'en',
output_format: { codec: 'mp3', sample_rate: 44100, bit_rate: 192000 },
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-tts",
"input": {
"text": "Crystal clear audio at maximum quality.",
"voice_id": "rex",
"language": "en",
"output_format": {
"codec": "mp3",
"sample_rate": 44100,
"bit_rate": 192000
}
}
}'{
"state": "Completed",
"result": {
"audio": "https://examples.aig.cloudflare.com/xai/grok-tts/high-fidelity-mp3.mp3"
},
"gatewayMetadata": {
"keySource": "Unified"
}
}电话(mulaw) — 8 kHz 的 G.711 μ-law,用于 SIP / PSTN 集成
const response = await env.AI.run(
'xai/grok-tts',
{
text: 'Hello, thank you for calling. How can I help you today?',
voice_id: 'ara',
language: 'en',
output_format: { codec: 'mulaw', sample_rate: 8000 },
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-tts",
"input": {
"text": "Hello, thank you for calling. How can I help you today?",
"voice_id": "ara",
"language": "en",
"output_format": {
"codec": "mulaw",
"sample_rate": 8000
}
}
}'{
"state": "Completed",
"result": {
"audio": "https://examples.aig.cloudflare.com/xai/grok-tts/telephony-law.mp3"
},
"gatewayMetadata": {
"keySource": "Unified"
}
}富有表现力的演绎 — 用于笑声、停顿和耳语的内联语音标签
const response = await env.AI.run(
'xai/grok-tts',
{
text: 'So I walked in and [pause] there it was. [laugh] I honestly could not believe it! <whisper>It was a secret the whole time.</whisper>',
voice_id: 'eve',
language: 'en',
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-tts",
"input": {
"text": "So I walked in and [pause] there it was. [laugh] I honestly could not believe it! <whisper>It was a secret the whole time.</whisper>",
"voice_id": "eve",
"language": "en"
}
}'{
"state": "Completed",
"result": {
"audio": "https://examples.aig.cloudflare.com/xai/grok-tts/expressive-delivery.mp3"
},
"gatewayMetadata": {
"keySource": "Unified"
}
}文本规范化 — 将书面形式的数字和缩写转换为口语形式
const response = await env.AI.run(
'xai/grok-tts',
{
text: 'The total is $1,234.56 and the meeting is at 3pm on Jan 15th.',
voice_id: 'rex',
language: 'en',
text_normalization: true,
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-tts",
"input": {
"text": "The total is $1,234.56 and the meeting is at 3pm on Jan 15th.",
"voice_id": "rex",
"language": "en",
"text_normalization": true
}
}'{
"state": "Completed",
"result": {
"audio": "https://examples.aig.cloudflare.com/xai/grok-tts/text-normalization.mp3"
},
"gatewayMetadata": {
"keySource": "Unified"
}
}参数
text
stringminLength: 1maxLength: 15000要转换为语音的文本。最多 15,000 个字符。支持内联语音标签:[pause]、[laugh]、<whisper>…</whisper> 等。REST 模式下必填,与 websocket 互斥。language
stringrequiredBCP-47 语言代码(例如 "en"、"zh"、"pt-BR"),或使用 "auto" 自动检测语言。REST 和 WebSocket 模式均必填。支持的代码:auto、en、ar-EG、ar-SA、ar-AE、bn、zh、fr、de、hi、id、it、ja、ko、pt-BR、pt-PT、ru、es-MX、es-ES、tr、vi。websocket
boolean为文本转语音启用 WebSocket 流式传输。为 true 时,将建立双向 WebSocket 连接。与 text 互斥。voice_id
stringminLength: 1用于合成的音色。默认为 "eve"。内置音色:eve(活力)、ara(温暖)、rex(自信)、sal(均衡)、leo(权威)。也接受来自 /v1/tts/voices 的自定义音色 ID。不区分大小写——"Eve"、"EVE" 和 "eve" 是等效的。▶output_format{}
object输出音频格式。省略时默认为 24 kHz / 128 kbps 的 MP3。▶optimize_streaming_latency
one oftext_normalization
boolean为 true 时,在合成前将书面形式的文本规范化为口语形式(例如 "Dr." → "Doctor"、"100" → "one hundred")。默认为 false。speed
numberminimum: 0.7maximum: 1.5语速倍数。1.0 为正常语速。范围:0.7 到 1.5。默认为 1.0。仅在 WebSocket 模式下使用。audio
string生成音频文件的预签名 R2 URL。MIME 类型与所请求的编解码器对应(mp3 为 audio/mpeg,wav 为 audio/wav,依此类推)。