- Third-party
xAI 的 Grok 语音转文本模型。可将 25 种语言的音频文件转录为文本,支持词级时间戳、多声道转录、说话人分离和关键词偏置。
| 模型信息 | |
|---|---|
| 条款和许可证 | 链接 ↗ |
| 更多信息 | 链接 ↗ |
| 定价 | 在 Cloudflare 仪表板中查看定价 ↗ |
用法
const response = await env.AI.run(
'xai/grok-stt',
{ url: 'https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3' },
)
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-stt",
"input": {
"url": "https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3"
}
}'How old is the Brooklyn Bridge?
{
"state": "Completed",
"result": {
"text": "How old is the Brooklyn Bridge?",
"language": "English",
"duration": 1.85,
"words": [
{
"text": "How",
"start": 0.14,
"end": 0.28
},
{
"text": "old",
"start": 0.4,
"end": 0.6
},
{
"text": "is",
"start": 0.65,
"end": 0.75
},
{
"text": "the",
"start": 0.81,
"end": 0.89
},
{
"text": "Brooklyn",
"start": 0.95,
"end": 1.29
},
{
"text": "Bridge?",
"start": 1.35,
"end": 1.69
}
]
},
"gatewayMetadata": {
"keySource": "Unified"
}
}示例
指定语言和格式化 — 启用逆文本规范化,使口述数字转换为阿拉伯数字
const response = await env.AI.run(
'xai/grok-stt',
{
url: 'https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3',
language: 'en',
format: 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-stt",
"input": {
"url": "https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3",
"language": "en",
"format": true
}
}'How old is the Brooklyn Bridge?
{
"state": "Completed",
"result": {
"text": "How old is the Brooklyn Bridge?",
"language": "English",
"duration": 1.85,
"words": [
{
"text": "How",
"start": 0.14,
"end": 0.28
},
{
"text": "old",
"start": 0.4,
"end": 0.6
},
{
"text": "is",
"start": 0.65,
"end": 0.75
},
{
"text": "the",
"start": 0.81,
"end": 0.89
},
{
"text": "Brooklyn",
"start": 0.95,
"end": 1.29
},
{
"text": "Bridge?",
"start": 1.35,
"end": 1.69
}
]
},
"gatewayMetadata": {
"keySource": "Unified"
}
}带关键词的说话人分离 — 识别说话人,并使转录偏向专有名词
const response = await env.AI.run(
'xai/grok-stt',
{
url: 'https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3',
language: 'en',
diarize: true,
keyterm: ['Brooklyn', 'Manhattan'],
},
)
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-stt",
"input": {
"url": "https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3",
"language": "en",
"diarize": true,
"keyterm": [
"Brooklyn",
"Manhattan"
]
}
}'How old is the Brooklyn Bridge?
{
"state": "Completed",
"result": {
"text": "How old is the Brooklyn Bridge?",
"language": "English",
"duration": 1.85,
"words": [
{
"text": "How",
"start": 0.14,
"end": 0.28,
"speaker": 0
},
{
"text": "old",
"start": 0.4,
"end": 0.6,
"speaker": 0
},
{
"text": "is",
"start": 0.65,
"end": 0.75,
"speaker": 0
},
{
"text": "the",
"start": 0.81,
"end": 0.89,
"speaker": 0
},
{
"text": "Brooklyn",
"start": 0.95,
"end": 1.29,
"speaker": 0
},
{
"text": "Bridge?",
"start": 1.35,
"end": 1.69,
"speaker": 0
}
]
},
"gatewayMetadata": {
"keySource": "Unified"
}
}保留填充词 — 在转录文本中保留填充词(uh、um、er),而不是将其删除
const response = await env.AI.run(
'xai/grok-stt',
{
url: 'https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3',
language: 'en',
filler_words: 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-stt",
"input": {
"url": "https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3",
"language": "en",
"filler_words": true
}
}'How old is the Brooklyn Bridge?
{
"state": "Completed",
"result": {
"text": "How old is the Brooklyn Bridge?",
"language": "English",
"duration": 1.85,
"words": [
{
"text": "How",
"start": 0.14,
"end": 0.28
},
{
"text": "old",
"start": 0.4,
"end": 0.6
},
{
"text": "is",
"start": 0.65,
"end": 0.75
},
{
"text": "the",
"start": 0.81,
"end": 0.89
},
{
"text": "Brooklyn",
"start": 0.95,
"end": 1.29
},
{
"text": "Bridge?",
"start": 1.35,
"end": 1.69
}
]
},
"gatewayMetadata": {
"keySource": "Unified"
}
}Data URI 上传 — 将音频文件直接作为 base64 data URI 传入(与 `url` 互斥)
const response = await env.AI.run(
'xai/grok-stt',
{ file: 'data:audio/wav;base64,<...>' },
)
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-stt",
"input": {
"file": "data:audio/wav;base64,<...>"
}
}'{
"state": "Completed",
"result": {
"text": "",
"language": "",
"duration": 1
},
"gatewayMetadata": {
"keySource": "Unified"
}
}参数
file
string音频文件,可以是 data URI(data:audio/...;base64,...),也可以是由网关获取并上传的 HTTPS URL。支持的容器格式:flac、mp3、mp4、m4a、mkv、ogg、opus、wav、aac。也接受原始格式(pcm、mulaw、alaw)——需提供 audio_format 和 sample_rate。网关端大小限制:25 MB。与 `url` 互斥。url
stringformat: uri供 xAI 在服务器端获取的音频文件 HTTPS URL。与 `file` 和 `websocket` 互斥。不受网关端大小限制。websocket
boolean为语音转文本启用 WebSocket 流式传输。为 true 时,将建立双向 WebSocket 连接以进行实时音频转录。与 `file` 和 `url` 互斥。audio_format
stringenum: pcm, mulaw, alaw原始/无文件头音频的格式提示。pcm、mulaw、alaw 必填。容器格式(mp3、wav 等)请省略——xAI 会自动检测。sample_rate
integerminimum: -9007199254740991maximum: 9007199254740991采样率(Hz)。设置了 audio_format 时必填。language
string语言代码(例如 "en"、"fr"、"de")。与 format=true 一起使用以启用逆文本规范化。无论是否提供,xAI 都会转录任何语言——提供此参数可在转录文本中启用数字/货币格式化。format
boolean为 true 时,启用逆文本规范化——口述的数字和货币会转换为书面形式(例如 "one hundred dollars" → "$100")。需要设置 language。diarize
boolean为 true 时,启用说话人分离。响应中的每个词都包含一个 `speaker` 整数,用于标识检测到的说话人。filler_words
boolean为 true 时,转录文本中会包含填充词(uh、um、er)。默认为 false——填充词会被删除。multichannel
boolean为 true 时,每个音频声道会被独立转录。结果在 `channels` 数组中返回。要求声道数 ≥ 2。channels
integerminimum: 2maximum: 8音频声道数(2–8)。仅多声道原始音频需要提供;容器格式会自动检测。▶keyterm[]
arraymaxItems: 100使转录偏向的关键词(例如产品名称、专有名词)。每个关键词最多 50 个字符,最多 100 个关键词。以重复的表单字段发送:keyterm=Term+One&keyterm=Term+Two。text
string完整的转录文本。language
string检测到的语言名称(例如 "English"、"French")。duration
number音频时长(秒,保留 2 位小数)。▶words[]
array词级片段。每一项包含 text、start、end(秒)。当 diarize=true 时还包含 speaker 整数。▶channels[]
array当 multichannel=true 时的各声道转录文本。