语音识别 (ASR)Speech Recognition (ASR)

基于端到端深度学习的语音识别 API,支持 100+ 语言,提供批量识别和实时流式两种模式。支持说话人分离、关键词检测、标点还原、数字规范化等高级能力。End-to-end deep learning ASR API for 100+ languages. Supports batch recognition and real-time streaming modes, with speaker diarization, keyword spotting, punctuation restoration, and inverse text normalization.

快速概览
端点EndpointPOST /v1/speech/recognize
认证方式AuthBearer Token
输入方式Input文件上传 (multipart) / Base64 / 音频 URLFile upload (multipart) / Base64 / Audio URL
音频上限Max Size100 MB
最长时长Max Duration4 小时(WAV/MP3/AAC)/ 2 小时(FLAC)4 hours (WAV/MP3/AAC) / 2 hours (FLAC)
支持语言Languages100+ 语言
超时时间Timeout60 秒

请求端点

Endpoint

POST/v1/speech/recognize

认证

Authentication

Authorization: Bearer {access_token}

请求头

Request Headers

请求头Header必填Required说明Description
AuthorizationrequiredBearer 认证,格式:Bearer {access_token}Bearer authentication, format: Bearer {access_token}
Content-Typerequired文件上传时使用 multipart/form-data;JSON 模式使用 application/jsonUse multipart/form-data for file upload; application/json for JSON mode

请求参数

Request Parameters

参数Parameter类型Type必填Required说明Description
audiofile / stringrequired音频文件(multipart 上传)、Base64 编码字符串或音频 URL(JSON 模式)。≤100MBAudio file (multipart), Base64 string, or audio URL (JSON). ≤100MB
langstringoptional音频语言代码,默认 auto 自动检测。显式指定可提升准确率并减少处理时间。详见语种列表Language code; default auto. Explicitly specifying improves accuracy and speed. See Language List
formatstringoptional音频格式:wav / mp3 / flac / aac / ogg / opus / m4a。默认根据文件头自动检测Audio format: wav / mp3 / flac / aac / ogg / opus / m4a. Auto-detected by default
sample_rateintegeroptional音频采样率(Hz),如 8000、16000、44100、48000。默认从文件头读取,若文件头信息缺失则建议指定Audio sample rate (Hz), e.g., 8000, 16000, 44100, 48000. Read from file header by default; specify if header info is missing
modelstringoptional声学模型:default(通用,默认)、phone_call(电话语音,8kHz 优化)、video(视频场景,远场优化)、medical(医疗专业领域)Acoustic model: default (general), phone_call (telephony, 8kHz optimized), video (far-field), medical (medical domain)
enable_timestampsbooleanoptional是否返回词级/段级时间戳(开始/结束时间),默认 falseReturn word/segment-level timestamps (start/end), default false
enable_punctuationbooleanoptional是否自动添加标点符号和大小写修正,默认 trueAuto-add punctuation and case correction, default true
enable_itnbooleanoptional是否开启逆文本归一化(将"一千二百三十四"转为"1234","百分之五十"转为"50%"),默认 trueEnable inverse text normalization (e.g., "twelve thirty-four" → "1234"), default true
enable_diarizationbooleanoptional是否开启说话人分离(区分不同说话人),默认 false。开启后每段文本会标注 speaker_idEnable speaker diarization (identify different speakers), default false. Each segment will have speaker_id
speaker_countintegeroptional预期说话人数量,仅 enable_diarization=true 时有效。范围 1–10,未指定时自动估算Expected number of speakers, only when enable_diarization=true. Range 1–10, auto-estimated if not specified
enable_keywordsarrayoptional关键词识别列表,传入需要重点识别的一组词/短语,可提高这些词的识别优先级。如 ["人工智能", "机器学习"]Keyword spotting list: provide words/phrases to boost their recognition priority. E.g., ["AI", "machine learning"]
enable_profanity_filterbooleanoptional是否开启敏感词过滤,将识别结果中的不当词语替换为 ***,默认 falseFilter profanity, replacing inappropriate words with ***, default false
enable_partial_resultsbooleanoptional是否返回阶段性结果(流式模式下有效),默认 falseReturn partial/interim results (streaming mode), default false
callback_urlstringoptional异步回调地址。长音频(>10 分钟)建议使用此模式,识别完成后通过 HTTP POST 推送结果Async callback URL. Recommended for long audio (>10 min); results pushed via HTTP POST on completion

声学模型选择

Acoustic Model Selection

model适用场景Use Case采样率建议Sample Rate特点Features
default通用场景:会议、演讲、播客General: meetings, speeches, podcasts16kHz泛化能力最强,适用大多数场景Best generalization, fits most scenarios
phone_call电话录音、呼叫中心、VoIPPhone recordings, call centers, VoIP8kHz针对窄带电话语音优化,8kHz 下准确率最高Optimized for narrowband telephony; highest accuracy at 8kHz
video视频配音、直播、远场拾音Video dubbing, live streaming, far-field16-48kHz远场优化,支持背景噪音抑制和多声道处理Far-field optimized with noise suppression and multi-channel support
medical医疗听写、病历语音录入Medical dictation, EHR voice input16kHz内置医学术语词库,对药品名、疾病名有更高识别率Built-in medical lexicon; higher accuracy on drug/disease names

支持音频格式

Supported Audio Formats

格式FormatMIME 类型MIME Type采样率Sample Rate最大时长Max Duration说明Notes
WAVaudio/wav8-48kHz4 小时4 hours无损、推荐格式,支持 PCM/ALAW/ULAW 编码Lossless, recommended; supports PCM/ALAW/ULAW encoding
MP3audio/mpeg16-48kHz4 小时4 hours最通用压缩格式,建议码率 ≥ 64kbpsMost common compressed format; recommend ≥64kbps bitrate
FLACaudio/flac8-48kHz2 小时2 hours无损压缩,高保真场景首选Lossless compression; preferred for high-fidelity scenarios
AACaudio/aac16-48kHz4 小时4 hours高效压缩,移动端录制常用Efficient compression; common for mobile recordings
OGG / Opusaudio/ogg8-48kHz2 小时2 hoursWebRTC 流媒体常用,低延迟场景适用Common in WebRTC streaming; suitable for low-latency scenarios
M4Aaudio/mp416-48kHz4 小时4 hoursiOS 录音默认格式,内部通常为 AAC 编码Default iOS recording format; typically AAC-encoded

请求示例

Request Examples

cURL — 基础识别(文件上传)

cURL — Basic Recognition (File Upload)

curl -X POST https://api.itranslator.cc/v1/speech/recognize \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -F "audio=@meeting.mp3" \
  -F "lang=zh" \
  -F "enable_timestamps=true" \
  -F "enable_punctuation=true"

cURL — 高级识别(说话人分离 + 关键词)

cURL — Advanced (Diarization + Keywords)

curl -X POST https://api.itranslator.cc/v1/speech/recognize \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -F "audio=@conference.wav" \
  -F "lang=zh" \
  -F "model=default" \
  -F "enable_diarization=true" \
  -F "speaker_count=4" \
  -F "enable_itn=true" \
  -F "enable_punctuation=true"

cURL — URL 模式 + 异步回调

cURL — URL Mode + Async Callback

curl -X POST https://api.itranslator.cc/v1/speech/recognize \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "audio": "https://cdn.example.com/lecture.mp3",
    "lang": "en",
    "enable_timestamps": true,
    "enable_diarization": true,
    "callback_url": "https://myapp.com/webhook/asr-result"
  }'

Python — 文件上传

Python — File Upload

import requests

with open("meeting.mp3", "rb") as audio:
    resp = requests.post(
        "https://api.itranslator.cc/v1/speech/recognize",
        headers={"Authorization": f"Bearer {token}"},
        files={"audio": audio},
        data={
            "lang": "zh",
            "enable_timestamps": True,
            "enable_diarization": True,
            "enable_punctuation": True
        }
    )

result = resp.json()
for seg in result.get("segments", []):
    speaker = seg.get("speaker_id", "?")
    print(f"[{seg['start']:.1f}s–{seg['end']:.1f}s] 说话人{speaker}: {seg['text']}")

JavaScript (Node.js)

JavaScript (Node.js)

const fs = require("fs");

const form = new FormData();
form.append("audio", fs.createReadStream("./meeting.mp3"));
form.append("lang", "zh");
form.append("enable_diarization", "true");
form.append("enable_timestamps", "true");

const resp = await fetch(
  "https://api.itranslator.cc/v1/speech/recognize",
  {
    method: "POST",
    headers: { Authorization: `Bearer ${token}` },
    body: form
  }
);
const data = await resp.json();
console.log("识别文本:", data.text);
data.segments.forEach(s => console.log(
  `[${s.start}-${s.end}] ${s.text}`));

Java

Java

import java.net.URI;
import java.net.http.*;
import java.nio.file.*;

HttpClient client = HttpClient.newHttpClient();
byte[] audioBytes = Files.readAllBytes(Path.of("meeting.mp3"));

// 使用 Base64 模式
String base64 = java.util.Base64.getEncoder()
    .encodeToString(audioBytes);
String json = String.format(
  "{\"audio\":\"%s\",\"lang\":\"zh\",\"enable_timestamps\":true}",
  base64);

HttpRequest req = HttpRequest.newBuilder()
  .uri(URI.create("https://api.itranslator.cc/v1/speech/recognize"))
  .header("Authorization", "Bearer " + token)
  .header("Content-Type", "application/json")
  .POST(HttpRequest.BodyPublishers.ofString(json))
  .build();

HttpResponse<String> resp = client.send(req,
  HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());

响应字段说明

Response Fields

字段Field类型Type说明Description
textstring完整识别文本,已拼接为一段Full recognized text, concatenated as one paragraph
langstring识别使用的语言代码Language code used for recognition
detected_langstring自动检测到的语言(lang=auto 时返回)Auto-detected language (returned when lang=auto)
duration_secondsfloat音频总时长(秒)Total audio duration in seconds
segmentsarray语音分段数组,每段含 start/end 时间戳、text 文本、confidence 置信度、speaker_id(开启说话人分离时)Segment array, each with start/end timestamps, text, confidence, speaker_id (when diarization enabled)
segments[].startfloat分段起始时间(秒)Segment start time in seconds
segments[].endfloat分段结束时间(秒)Segment end time in seconds
segments[].speaker_idinteger说话人编号(仅 enable_diarization=true 时返回),从 0 开始Speaker ID (only when enable_diarization=true), starting from 0
wordsarray词级时间戳数组(仅 enable_timestamps=true),每词含 word、start、end、confidenceWord-level timestamp array (enable_timestamps=true), each with word, start, end, confidence
overall_confidencefloat整段音频的平均识别置信度(0–1),≥ 0.90 为高可信Average confidence for the entire audio (0–1); ≥0.90 considered highly reliable
keywords_matchedarray匹配到的关键词列表及出现位置(仅启用关键词识别时返回)Matched keywords and their positions (only when keyword spotting enabled)
processing_time_msinteger处理耗时(毫秒)Processing time in milliseconds

响应示例

Response Examples

示例 1:基础识别

Example 1: Basic Recognition

{
  "text": "今天我们要讨论的产品规划包含三个重点方向,分别是用户体验优化、AI 能力集成以及多平台适配。",
  "lang": "zh",
  "duration_seconds": 12.5,
  "overall_confidence": 0.97,
  "processing_time_ms": 450
}

示例 2:带时间戳的段级识别

Example 2: Segment-level with Timestamps

{
  "text": "今天我们要讨论的产品规划包含三个重点方向,分别是用户体验优化、AI 能力集成以及多平台适配。",
  "lang": "zh",
  "duration_seconds": 12.5,
  "overall_confidence": 0.97,
  "segments": [
    { "start": 0.0, "end": 3.2, "text": "今天我们要讨论的产品规划", "confidence": 0.96 },
    { "start": 3.2, "end": 6.5, "text": "包含三个重点方向,", "confidence": 0.98 },
    { "start": 6.5, "end": 12.5, "text": "分别是用户体验优化、AI 能力集成以及多平台适配。", "confidence": 0.97 }
  ],
  "processing_time_ms": 480
}

示例 3:说话人分离 + 词级时间戳

Example 3: Speaker Diarization + Word-level Timestamps

{
  "text": "我觉得这个方案可以尝试。 具体怎么落地呢? 我们可以先做个小范围试点。",
  "lang": "zh",
  "duration_seconds": 8.2,
  "overall_confidence": 0.95,
  "segments": [
    {
      "speaker_id": 0, "start": 0.0, "end": 2.8,
      "text": "我觉得这个方案可以尝试。", "confidence": 0.96,
      "words": [
        { "word": "我", "start": 0.0, "end": 0.3, "confidence": 0.98 },
        { "word": "觉得", "start": 0.3, "end": 0.7, "confidence": 0.97 },
        { "word": "这个", "start": 0.7, "end": 1.0, "confidence": 0.99 },
        { "word": "方案", "start": 1.0, "end": 1.3, "confidence": 0.95 },
        { "word": "可以", "start": 1.3, "end": 1.8, "confidence": 0.97 },
        { "word": "尝试", "start": 2.0, "end": 2.5, "confidence": 0.94 }
      ]
    },
    {
      "speaker_id": 1, "start": 3.0, "end": 5.5,
      "text": "具体怎么落地呢?", "confidence": 0.97,
      "words": [
        { "word": "具体", "start": 3.0, "end": 3.4, "confidence": 0.98 },
        { "word": "怎么", "start": 3.4, "end": 3.8, "confidence": 0.97 },
        { "word": "落地", "start": 3.8, "end": 4.3, "confidence": 0.96 },
        { "word": "呢", "start": 4.5, "end": 4.7, "confidence": 0.99 }
      ]
    },
    {
      "speaker_id": 0, "start": 5.8, "end": 8.2,
      "text": "我们可以先做个小范围试点。", "confidence": 0.94,
      "words": [
        { "word": "我们", "start": 5.8, "end": 6.1, "confidence": 0.96 },
        { "word": "可以", "start": 6.1, "end": 6.5, "confidence": 0.95 },
        { "word": "先做", "start": 6.5, "end": 6.9, "confidence": 0.94 },
        { "word": "个", "start": 6.9, "end": 7.1, "confidence": 0.98 },
        { "word": "小范围", "start": 7.1, "end": 7.5, "confidence": 0.92 },
        { "word": "试点", "start": 7.5, "end": 7.9, "confidence": 0.93 }
      ]
    }
  ],
  "words": [
    { "word": "我", "speaker_id": 0, "start": 0.0, "end": 0.3, "confidence": 0.98 },
    { "word": "觉得", "speaker_id": 0, "start": 0.3, "end": 0.7, "confidence": 0.97 }
  ],
  "processing_time_ms": 850
}

示例 4:关键词识别结果

Example 4: Keyword Spotting Result

{
  "text": "我们的人工智能项目需要引入大语言模型和强化学习来提升效果。",
  "lang": "zh",
  "duration_seconds": 6.8,
  "overall_confidence": 0.96,
  "keywords_matched": [
    { "keyword": "人工智能", "start": 0.5, "end": 1.0, "confidence": 0.98 },
    { "keyword": "大语言模型", "start": 2.8, "end": 3.5, "confidence": 0.97 },
    { "keyword": "强化学习", "start": 3.8, "end": 4.3, "confidence": 0.96 }
  ],
  "processing_time_ms": 380
}

错误码

Error Codes

状态码Status错误码Code说明Description
400INVALID_AUDIO_FORMAT音频格式不支持或文件已损坏Unsupported or corrupted audio format
400AUDIO_TOO_LARGE音频超过 100MB 限制Audio exceeds 100MB limit
400AUDIO_TOO_LONG音频时长超过当前格式的最大限制Audio duration exceeds the format's maximum limit
400NO_SPEECH_DETECTED音频中未检测到有效语音,可能为静音或纯噪音No valid speech detected; may be silence or pure noise
400INVALID_LANGUAGE不支持的语言代码Unsupported language code
400INVALID_AUDIO_URL音频 URL 无效、无法访问或超时Invalid, inaccessible or timed-out audio URL
401UNAUTHORIZED缺少或无效的 Access TokenMissing or invalid access token
403FORBIDDEN无权访问该资源或配额已耗尽Access denied or quota exceeded
413PAYLOAD_TOO_LARGE请求体超过服务器限制Request body too large
415UNSUPPORTED_MEDIA_TYPEContent-Type 不正确或媒体类型不支持Incorrect or unsupported Content-Type
422LOW_CONFIDENCE识别置信度过低,可能因背景噪音过大或语言不匹配Confidence too low; possible excessive background noise or language mismatch
429RATE_LIMITED请求频率超限,请降低并发数Rate limit exceeded; reduce concurrency
500INTERNAL_ERROR服务器内部错误,请稍后重试Internal server error; try again later
503SERVICE_UNAVAILABLE服务暂时不可用,请稍后重试Service temporarily unavailable

最佳实践

Best Practices

  1. 音频质量第一:清晰、无噪音的音频可获得最高的识别准确率。建议录音时使用外置麦克风,保持距离适中,背景安静。
  2. Audio Quality First: Clear, noise-free audio yields the highest accuracy. Use an external mic, maintain proper distance, and keep the environment quiet.
  3. 指定语言代码:尽量显式指定 lang 而非依赖 auto,既提高准确率又减少处理时间。
  4. Specify Language: Explicitly set lang rather than relying on auto to improve accuracy and reduce processing time.
  5. 选对声学模型:电话录音用 phone_call 模型,会议/演讲用 default,远场/视频用 video,医疗场景用 medical
  6. Choose the Right Model: Use phone_call for telephony, default for meetings/speeches, video for far-field, medical for healthcare.
  7. 长音频异步处理:超过 10 分钟的音频建议使用 callback_url 异步模式,避免请求超时。回调结果格式与同步响应一致。
  8. Async for Long Audio: Use callback_url async mode for audio over 10 minutes to avoid timeouts. Callback format matches sync response.
  9. 说话人分离的技巧:如果已知会议参与人数,通过 speaker_count 指定可显著提升分离精度。两人对话设为 2,小组讨论设为 4–5。
  10. Diarization Tips: Specify speaker_count when the number of participants is known; set 2 for dialogue, 4–5 for group discussions.
  11. 关键词提升:对领域专有名词(产品名、人名、专业术语),通过 enable_keywords 传入可减少同音误识。
  12. Keyword Boosting: Pass domain-specific terms (product names, person names, jargon) via enable_keywords to reduce homophone errors.
  13. 错误重试:对于 429(频率限制)和 5xx(服务器错误),建议实现指数退避重试策略。
  14. Retry Strategy: Implement exponential backoff for 429 (rate limit) and 5xx (server errors).

常见应用场景

Common Use Cases

场景Scenario推荐参数组合Recommended Parameters
会议纪要自动生成Meeting Minutesenable_diarization=true, speaker_count=N, enable_timestamps=true, enable_itn=true
呼叫中心质检Call Center QAmodel=phone_call, enable_diarization=true, enable_profanity_filter=true
视频字幕生成Video Subtitlesmodel=video, enable_timestamps=true, enable_punctuation=true
直播实时转写Live Transcriptionenable_partial_results=true, model=video
医疗语音病历Medical Dictationmodel=medical, enable_itn=true, enable_keywords=["诊断","用药","处方"]
访谈/调研整理Interview Transcriptionenable_diarization=true, enable_timestamps=true, enable_punctuation=true
语音搜索/语音助手Voice Search/Assistantenable_itn=true, enable_punctuation=false

语言支持概览

Language Support Overview

语言Language代码Code标点PunctuationITN说话人分离Diarization
中文(普通话)Chinese (Mandarin)zh
英语Englishen
日语Japaneseja
韩语Koreanko
德语Germande
法语Frenchfr
西班牙语Spanishes
葡萄牙语Portuguesept
意大利语Italianit
俄语Russianru
阿拉伯语Arabicar
印地语Hindihi

注:完整 100+ 语言列表请参见Note: For the complete 100+ language list, see 语种列表Language List

使用说明
  • 文件上传使用 multipart/form-data 编码,Content-Type 请勿手动设置,让 HTTP 客户端自动生成。
  • Use multipart/form-data encoding; let the HTTP client auto-generate Content-Type.
  • Base64 编码后字符串会比原文件大约 33%,注意请求体大小限制。
  • Base64 encoding increases size by ~33%; mind the request body size limit.
  • 长音频(>10 分钟)建议使用 callback_url 异步模式,避免请求超时。单次同步请求超时时间为 60 秒。
  • For long audio (>10 min), use callback_url async mode to avoid timeouts. Sync request timeout is 60 seconds.
  • 请勿在客户端代码中暴露 Access Token,建议通过后端代理调用。
  • Do not expose your Access Token in client-side code; use a backend proxy.
  • 如需将识别结果翻译为其他语言,请将 text 传入文本翻译 API,或直接使用语音翻译 API 一步完成。
  • To translate recognition results, pass text to Text Translation API, or use Speech Translation API for one-step solution.