语音翻译Speech Translation

上传音频文件,自动进行语音识别(ASR)并翻译为目标语言文本。支持多种音频格式和语言,满足会议翻译、访谈翻译、课程翻译等多种场景需求。Upload audio files for automatic speech recognition (ASR) and translation into target language text. Supports multiple formats and languages for meetings, interviews, courses, and more.

快速概览

Quick Overview

属性Attribute说明Description
端点EndpointPOST /v1/speech/translate
认证AuthenticationBearer Token(Authorization 请求头)Bearer Token in Authorization header
输入方式Input Method本地文件上传(multipart/form-data)或音频 URLLocal file upload (multipart/form-data) or audio URL
音频上限Audio Limit最大 100MB,最长 2 小时Max 100MB, max 2 hours
源语言检测Source Language支持自动检测,也支持手动指定Auto-detection supported, manual specification also available
输出模式Output Modestext(纯译文)/ srt(字幕)/ full(完整信息)text (translation only) / srt (subtitles) / full (complete info)
支持语言Supported Languages中文、英语、日语、韩语、法语、德语、西班牙语、葡萄牙语等 30+ 种语言Chinese, English, Japanese, Korean, French, German, Spanish, Portuguese, and 30+ more
超时时间Timeout同步模式 60 秒,超长音频建议使用异步回调60s synchronous timeout; use async callback for long audio

请求端点

Endpoint

POST/v1/speech/translate

认证

Authentication

所有 API 请求需在 HTTP Header 中携带 Access Token,不支持 URL 参数传递。

All API requests must include an Access Token in the HTTP Header. URL parameter passing is not supported.

Authorization: Bearer {access_token}

请求头

Request Headers

请求头Header必填Required说明Description
Authorizationrequired格式 Bearer {access_token},用于身份认证Format: Bearer {access_token}, used for authentication
Content-Typerequiredmultipart/form-data,由 HTTP 客户端自动设置multipart/form-data, auto-set by HTTP client

请求参数

Request Parameters

参数Parameter类型Type必填Required说明Description
filefilerequired音频文件,最大 100MB,最长 2 小时Audio file, max 100MB, max 2 hours
audio_urlstringoptional音频文件的公网可访问 URL(与 file 二选一)Publicly accessible URL of the audio file (alternative to file)
target_langstringrequired目标翻译语言代码,如 enjakoTarget language code, e.g. en, ja, ko
source_langstringoptional源语言代码,不传则自动检测。已知语言建议显式指定以获得更优效果Source language code, auto-detected if omitted. Explicit specification recommended for better accuracy
audio_formatstringoptional音频格式:wav / mp3 / flac / ogg / aac / m4a,默认从文件头自动识别Audio format: wav/mp3/flac/ogg/aac/m4a, auto-detected by default
output_typestringoptional输出类型:text(仅翻译文本)/ srt(返回字幕文件)/ full(转录+翻译+时间戳),默认 textOutput: text/srt/full, default text
formalitystringoptional翻译语气:default(默认)/ formal(正式)/ informal(非正式)。仅部分目标语言支持Translation tone: default/formal/informal. Available for select target languages
glossary_idstringoptional关联的术语库 ID,翻译时将应用自定义术语映射Glossary ID to apply custom term mappings during translation
enable_diarizationbooleanoptional是否开启说话人分离,默认 false。适合多人对话场景Enable speaker diarization, default false. Best for multi-speaker scenarios
speaker_countintegeroptional预期的说话人数量(1-10)。配合 enable_diarization 使用,可提升分离精度Expected speaker count (1-10). Use with enable_diarization to improve accuracy
enable_timestampsbooleanoptional是否返回词级/句级时间戳,默认 trueReturn word/sentence-level timestamps, default true
srt_max_charsintegeroptionalSRT 字幕每行最大字符数,仅 output_type=srt 时生效,默认 42Max characters per SRT line, only for output_type=srt, default 42
srt_bilingualbooleanoptional是否生成双语字幕(源语言+译文本),仅 output_type=srt 时生效,默认 falseGenerate bilingual subtitles (source + translation), only for output_type=srt, default false
callback_urlstringoptional异步回调地址,处理完成后 POST 结果到此 URL。适合超长音频Async callback URL, receives POST result upon completion. Best for long audio
modelstringoptionalASR 模型选择:default(通用)/ phone_call(电话)/ video(视频),默认 defaultASR model: default/phone_call/video, default default

输出模式

Output Modes

output_type 参数控制返回数据的格式,三种模式各有侧重:

The output_type parameter controls the response format. Each mode serves a different purpose:

模式Mode返回内容Returns适用场景Use Case
text仅翻译文本字符串Translation text only快速了解内容含义、文本摘要Quick content understanding, text summarization
srtSRT 格式字幕文件内容 + 翻译文本SRT subtitle content + translation text视频字幕制作、双语字幕Video subtitling, bilingual subtitles
full完整转录 + 翻译 + 时间戳 + 说话人信息Full transcript + translation + timestamps + speaker info详细分析、会议纪要生成、数据对接Detailed analysis, meeting minutes, data integration

支持的音频格式

Supported Audio Formats

格式FormatMIME Type说明Notes
mp3audio/mpeg最常用格式,兼容性强,文件体积适中Most common format, good compatibility, moderate file size
wavaudio/wav无损格式,音质最高但文件大,适合高精度需求Lossless format, highest quality but large files, best for high-accuracy needs
flacaudio/flac无损压缩,兼顾音质与体积Lossless compression, balances quality and size
aacaudio/aac高效压缩格式,Apple 生态常用Efficient compression, common in Apple ecosystem
oggaudio/ogg开源格式,Opus 编码识别率更佳Open format, Opus codec yields better recognition
m4aaudio/mp4iOS 录音默认格式,支持直接上传iOS default recording format, supported natively
💡 格式建议
  • 追求识别精度:使用 WAV(16kHz/24kHz 采样率)或 FLAC 格式
  • For accuracy: use WAV (16kHz/24kHz sample rate) or FLAC
  • 追求传输效率:使用 MP3(128kbps 以上码率)或 OGG/Opus 格式
  • For efficiency: use MP3 (128kbps+ bitrate) or OGG/Opus
  • 避免使用过度压缩或采样率低于 8kHz 的音频
  • Avoid heavily compressed audio or sample rates below 8kHz

请求示例

Request Examples

# 基础翻译:上传文件,中文转英文
curl -X POST https://api.itranslator.cc/v1/speech/translate \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -F "file=@meeting.mp3" \
  -F "target_lang=en" \
  -F "source_lang=zh" \
  -F "output_type=full"

# 从 URL 翻译并生成双语字幕
curl -X POST https://api.itranslator.cc/v1/speech/translate \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -F "audio_url=https://cdn.example.com/lecture.mp3" \
  -F "target_lang=ja" \
  -F "source_lang=en" \
  -F "output_type=srt" \
  -F "srt_bilingual=true"

# 多人对话 + 术语库 + 说话人分离
curl -X POST https://api.itranslator.cc/v1/speech/translate \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -F "file=@interview.wav" \
  -F "target_lang=zh" \
  -F "source_lang=en" \
  -F "enable_diarization=true" \
  -F "speaker_count=2" \
  -F "glossary_id=gls_abc123" \
  -F "formality=formal"

响应参数

Response Parameters

字段Field类型Type说明Description
translated_textstring完整的翻译后文本Complete translated text
transcriptstringASR 识别后的原始转录文本Original ASR transcription text
source_langstring检测到的或请求指定的源语言代码Detected or requested source language code
target_langstring目标翻译语言代码Target language code
durationnumber音频时长(秒)Audio duration in seconds
segmentsarray分段详情,包含 start/end/source/translationSegment details with start/end/source/translation
segments[].startnumber分段起始时间(秒)Segment start time in seconds
segments[].endnumber分段结束时间(秒)Segment end time in seconds
segments[].sourcestring原始转录文本Original transcription
segments[].translationstring对应的翻译文本Corresponding translation
segments[].speakerstring说话人标识(开启说话人分离时返回),如 speaker_0speaker_1Speaker label (when diarization enabled), e.g. speaker_0, speaker_1
segments[].confidencenumberASR 识别置信度(0-1)ASR confidence score (0-1)
srt_contentstringSRT 格式字幕内容(仅 output_type=srt 时返回)SRT subtitle content (only when output_type=srt)
billed_durationnumber计费时长(秒),为实际计费的音频长度Billed duration in seconds

响应示例

Response Examples

text 模式 — 仅翻译文本

text Mode — Translation Only

{
  "translated_text": "Today we will discuss the plan for next quarter.",
  "source_lang": "zh",
  "target_lang": "en",
  "duration": 6.5,
  "billed_duration": 7.0
}

full 模式 — 完整信息(含时间戳)

full Mode — Complete Info (with timestamps)

{
  "translated_text": "Today we will discuss the plan for next quarter.",
  "transcript": "今天我们要讨论下个季度的计划。",
  "source_lang": "zh",
  "target_lang": "en",
  "duration": 6.5,
  "billed_duration": 7.0,
  "segments": [
    {
      "start": 0.0,
      "end": 3.2,
      "source": "今天我们要讨论",
      "translation": "Today we will discuss",
      "confidence": 0.98
    },
    {
      "start": 3.2,
      "end": 6.5,
      "source": "下个季度的计划。",
      "translation": "the plan for next quarter.",
      "confidence": 0.95
    }
  ]
}

full 模式 + 说话人分离

full Mode + Speaker Diarization

{
  "translated_text": "Good morning everyone. I'd like to start with sales report. Last month we saw a 15% growth.",
  "transcript": "大家早上好。我想先说一下销售报告。上个月我们增长了15%。",
  "source_lang": "zh",
  "target_lang": "en",
  "duration": 12.3,
  "segments": [
    {
      "start": 0.0, "end": 4.5,
      "speaker": "speaker_0",
      "source": "大家早上好。",
      "translation": "Good morning everyone.",
      "confidence": 0.99
    },
    {
      "start": 4.5, "end": 9.0,
      "speaker": "speaker_1",
      "source": "我想先说一下销售报告。",
      "translation": "I'd like to start with sales report.",
      "confidence": 0.96
    },
    {
      "start": 9.0, "end": 12.3,
      "speaker": "speaker_1",
      "source": "上个月我们增长了15%。",
      "translation": "Last month we saw a 15% growth.",
      "confidence": 0.97
    }
  ]
}

srt 模式 — 双语字幕

srt Mode — Bilingual Subtitles

{
  "source_lang": "zh",
  "target_lang": "en",
  "duration": 6.5,
  "translated_text": "Today we will discuss the plan for next quarter.",
  "srt_content": "1\n00:00:00,000 --> 00:00:03,200\n今天我们要讨论\nToday we will discuss\n\n2\n00:00:03,200 --> 00:00:06,500\n下个季度的计划。\nthe plan for next quarter.\n"
}

错误码

Error Codes

Status错误码Code说明Description
400MISSING_PARAM缺少必填参数(file 或 target_lang)Missing required parameter (file or target_lang)
400UNSUPPORTED_AUDIO不支持的音频格式Unsupported audio format
400AUDIO_TOO_LONG音频超过 2 小时限制Audio exceeds 2-hour limit
400AUDIO_TOO_LARGE音频文件超过 100MB 限制Audio file exceeds 100MB limit
400NO_SPEECH_DETECTED未检测到语音内容No speech detected
400INVALID_AUDIO_URL音频 URL 无法访问或下载超时Audio URL inaccessible or download timeout
400UNSUPPORTED_LANG不支持的语言代码Unsupported language code
400LOW_CONFIDENCE音频质量过低,识别置信度不足Audio quality too low, insufficient confidence
401UNAUTHORIZEDAccess Token 无效或已过期Invalid or expired Access Token
403FORBIDDEN无权限访问该资源或超出套餐配额No permission or quota exceeded
413PAYLOAD_TOO_LARGE请求体超过大小限制Request body exceeds size limit
429RATE_LIMITED请求频率超限,请降低并发或稍后重试Rate limit exceeded, reduce concurrency or retry later
456QUOTA_EXCEEDED套餐配额已用尽,请升级或等待重置Plan quota exhausted, upgrade or wait for reset
500INTERNAL_ERROR服务器内部错误,请稍后重试Internal server error, please retry later
503SERVICE_UNAVAILABLE服务暂时不可用,建议重试Service temporarily unavailable, retry recommended

最佳实践

Best Practices

  • 指定源语言:已知源语言时务必显式传入 source_lang,避免自动检测可能带来的偏差,识别准确率可提升 5-10%。
  • Specify source language: Always provide source_lang when known to avoid auto-detection errors and improve accuracy by 5-10%.
  • 选择合适的模型:电话录音使用 phone_call 模型,视频内容使用 video 模型,通用场景保持 default
  • Choose the right model: Use phone_call for phone recordings, video for video content, default for general scenarios.
  • 音频预处理:确保音频清晰、背景噪音低、说话人音量适中。单声道 16kHz 采样率可达到最佳性价比。
  • Audio preprocessing: Ensure clear audio with low background noise and moderate volume. Mono 16kHz offers the best cost-performance ratio.
  • 超长音频使用异步模式:超过 10 分钟的音频建议使用 callback_url 异步回调,避免同步请求超时。
  • Use async for long audio: For audio over 10 minutes, use callback_url for async processing to avoid timeouts.
  • 说话人分离技巧:预先估算对话人数,通过 speaker_count 提供参考值,可显著提升多人场景下的分离准确度。
  • Speaker diarization tips: Estimate speaker count in advance and provide via speaker_count to significantly improve diarization accuracy.
  • 术语库配合使用:行业专有名词、产品名、人名等建议通过术语库统一管理,确保翻译一致性。
  • Use glossaries: Manage industry terms, product names, and person names via glossaries for translation consistency.
  • 安全提醒:请勿在客户端代码中暴露 Access Token,建议通过后端代理调用 API。
  • Security: Do not expose Access Token in client-side code; use a backend proxy for API calls.

应用场景

Use Cases

场景Scenario推荐配置Recommended Config说明Notes
🏢 跨国会议🌐 International Meetings output_type=full + 说话人分离 多人轮流发言,需区分说话人并保留时间戳用于纪要整理 Multi-speaker turns, need speaker labels and timestamps for minutes
📞 客服通话📞 Customer Service Calls model=phone_call + 说话人分离(2人) 电话音质专用模型,客户与客服对话结构清晰 Phone-optimized model with clear agent-customer dialogue structure
🎬 视频字幕🎬 Video Subtitling output_type=srt + srt_bilingual=true 直接输出可直接导入视频编辑软件的双语字幕文件 Direct output of bilingual SRT files for video editors
📚 在线课程📚 Online Courses model=video + formality=formal 讲课式音频,正式语气翻译,适合学术场景 Lecture-style audio, formal tone for academic contexts
🎙️ 访谈播客🎙️ Interviews & Podcasts output_type=full + 术语库 + 说话人分离 访谈涉及专业术语,需术语映射保证翻译准确 Domain terminology needs glossary mapping for accuracy
📱 实时同传📱 Real-time Interpretation source_lang=auto + output_type=text 短音频流式翻译,自动识别语种快速输出译文 Short audio streaming, auto-detect and fast translation output
🏥 医疗问诊🏥 Medical Consultations formality=formal + 医学术语库 医患对话需准确翻译专业术语,保持正式严谨 Doctor-patient dialogue requires accurate medical term translation

与语音识别 API 的对比

Comparison with Speech Recognition API

语音翻译与语音识别是两个互补的 API,选择取决于你的目标:

Speech Translation and Speech Recognition are complementary APIs. Choose based on your goal:

对比维度Dimension语音识别Speech Recognition语音翻译Speech Translation
核心功能Core Function语音 → 同语言文本Speech → Same-language text语音 → 翻译后文本Speech → Translated text
输出内容Output转录文本 + 时间戳 + 置信度Transcript + timestamps + confidence转录 + 译文 + 时间戳 + 双语字幕Transcript + translation + timestamps + bilingual subtitles
处理步骤ProcessingASR 一步完成One-step ASRASR → 翻译,两步流水线Two-step pipeline: ASR → Translation
响应速度Speed快,仅需识别Fast, recognition only较慢,需额外翻译处理Slower, additional translation step
特色能力Special FeaturesITN、关键词识别、部分结果流式返回ITN, keyword spotting, partial streaming results术语库、语气控制、双语字幕、说话人翻译Glossary, tone control, bilingual subtitles, speaker-aware translation
推荐场景Best For同语言转文字、语音搜索、命令控制Same-language transcription, voice search, commands跨语言交流、字幕翻译、多语种内容制作Cross-language communication, subtitle translation, multilingual content
使用说明
  • 文件上传使用 multipart/form-data 编码,Content-Type 请勿手动设置,让 HTTP 客户端自动生成。
  • Use multipart/form-data encoding; let the HTTP client auto-generate Content-Type.
  • 大文件建议分片上传或使用异步任务模式,避免请求超时。
  • For large files, use chunked upload or async task mode to avoid timeouts.
  • 请勿在客户端代码中暴露 Access Token,建议通过后端代理调用。
  • Do not expose your Access Token in client-side code; use a backend proxy.
  • 音频 URL 必须是公网可访问的直链地址,不支持需登录或验证的私有存储。
  • Audio URL must be a publicly accessible direct link; private storage requiring authentication is not supported.