- Third-party
- Zero data retention
| 模型信息 | |
|---|---|
| 零数据保留 | 是 |
| 定价 | 在 Cloudflare 仪表板中查看定价 ↗ |
用法
const response = await env.AI.run(
'google/gemini-3.1-flash-tts',
{ text: 'Hello, welcome to Cloudflare AI Gateway!' },
)
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": "google/gemini-3.1-flash-tts",
"input": {
"text": "Hello, welcome to Cloudflare AI Gateway!"
}
}'{
"audio": "data:audio/l16;base64,...",
"gatewayMetadata": {
"keySource": "Unified"
}
}示例
自定义语音 — 使用指定语音生成语音
const response = await env.AI.run(
'google/gemini-3.1-flash-tts',
{ text: 'The quick brown fox jumps over the lazy dog.', voice: 'Puck' },
)
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": "google/gemini-3.1-flash-tts",
"input": {
"text": "The quick brown fox jumps over the lazy dog.",
"voice": "Puck"
}
}'{
"audio": "data:audio/l16;base64,...",
"gatewayMetadata": {
"keySource": "Unified"
}
}较长文本 — 将较长文本转换为语音
const response = await env.AI.run(
'google/gemini-3.1-flash-tts',
{
text: 'Artificial intelligence has transformed the way we interact with technology. From voice assistants to autonomous vehicles, AI is reshaping our daily lives and creating new possibilities for innovation.',
voice: 'Charon',
},
)
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": "google/gemini-3.1-flash-tts",
"input": {
"text": "Artificial intelligence has transformed the way we interact with technology. From voice assistants to autonomous vehicles, AI is reshaping our daily lives and creating new possibilities for innovation.",
"voice": "Charon"
}
}'{
"audio": "data:audio/l16;base64,...",
"gatewayMetadata": {
"keySource": "Unified"
}
}叙述语音 — 以叙述风格生成语音
const response = await env.AI.run(
'google/gemini-3.1-flash-tts',
{
text: 'Once upon a time, in a kingdom far away, there lived a brave knight who sought to protect the realm from all dangers.',
voice: 'Kore',
},
)
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": "google/gemini-3.1-flash-tts",
"input": {
"text": "Once upon a time, in a kingdom far away, there lived a brave knight who sought to protect the realm from all dangers.",
"voice": "Kore"
}
}'{
"audio": "data:audio/l16;base64,...",
"gatewayMetadata": {
"keySource": "Unified"
}
}参数
text
stringrequiredmaxLength: 10000要转换为语音的文本。最多 10,000 个字符。voice
stringenum: Zephyr, Puck, Charon, Kore, Fenrir, Leda, Orus, Aoede, Callirrhoe, Autonoe, Enceladus, Iapetus, Umbriel, Algieba, Despina, Erinome, Algenib, Rasalgethi, Laomedeia, Achernar, Alnilam, Schedar, Gacrux, Pulcherrima, Achird, Zubenelgenubi, Vindemiatrix, Sadachbia, Sadaltager, Sulafat用于语音合成的语音temperature
numberminimum: 0maximum: 2控制生成的随机性(0-2)topP
numberminimum: 0maximum: 1核采样阈值(0-1)。会考虑累积概率不超过 topP 的 tokentopK
integerexclusiveMinimum: 0maximum: 9007199254740991仅从概率最高的 K 个 token 中采样。K 越小越集中,K 越大越多样maxOutputTokens
integerexclusiveMinimum: 0maximum: 9007199254740991要生成的最大 token 数▶stopSequences[]
array模型遇到后将停止继续生成 token 的序列audio
stringBase64 编码的音频数据(WAV 格式)