vLLM 语音转写接口的配置与实时流式要点

vLLM 提供兼容 OpenAI 客户端的转写、翻译与实时接口。转写需安装音频依赖,并受文件大小、模型上下文与解码时长等环境变量约束;实时接口通过 WebSocket 传输 base64 编码的 16kHz 单声道 PCM16 音频。

## 对文本 APIs 的演讲[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#speech-to-text-apis>) ## 译名 API[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#transcriptions-api>) 我们的转写 API 是兼容的 [OpenAI的译名 API](<https://platform.openai.com/docs/api-reference/audio/createTranscription>); 您可以使用 [官方 OpenAI Python 客户端](<https://github.com/openai/openai-python>) 与它互动。 说明 要使用 Transcripts API, 请使用额外的音频依赖性安装 。 `pip install vllm[audio]`. 代码示例 : [examples/speech_to_text/openai/openai_transcription_client.py](<https://github.com/vllm-project/vllm/blob/main/examples/speech_to_text/openai/openai_transcription_client.py>) NOTE : 光束搜索目前在编码器-解码器多模式模型的转录端点中被支持,例如低语,但效率很高,因为处理编码器/解码器缓存的工作正在积极进行中,这是持续优化的活跃点,将在近期内妥善处理. ### API 强制限制[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#api-enforced-limits>) 设定最大音频文件大小( 在 MB 中) , 由 VLLM 通过 `VLLM_MAX_AUDIO_CLIP_FILESIZE_MB` 环境变量。默认为 25 MB 。 将长式音频转换成单张音符的模型,例如 `microsoft/VibeVoice-ASR-HF`马上把全部录音都拿走 所以... `--max-model-len` 音频长度超过 600 秒 `VLLM_MAX_AUDIO_DECODE_DURATION_S` 抚养,以及 `VLLM_MAX_AUDIO_DECODE_BYTES` 在 24 kHz 上传时间太过了 45 分钟 。 未压缩文件先到达 25 MB 上传限制 。 vLLM 大小为这两个解码限制中最长的音频 。 `--max-model-len` 允许。 `--limit-mm-per-prompt '{"audio": {"length": <samples>}}'` 更改大小,但不包括API接受的音频。 Transformers型号的后端需要Transformers 5.23或稍后的转录. ### 上传音频文件[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#uploading-audio-files>) Transcriptions API支持以各种格式上传音频文件,包括FLAC,MP3,MP4,MPEG,MPGA,M4A,OGG,WAV和WEBM. **使用 OpenAI Python 客户端 :** 代码 ``` from openai import OpenAI client = OpenAI( base_url="http://localhost:8000/v1", api_key="token-abc123", ) # Upload audio file from disk with open("audio.mp3", "rb") as audio_file: transcription = client.audio.transcriptions.create( model="openai/whisper-large-v3-turbo", file=audio_file, language="en", response_format="verbose_json", ) print(transcription.text) ``` **使用带有多部分/形式数据的卷轴:** 代码 ``` curl -X POST "http://localhost:8000/v1/audio/transcriptions" \ -H "Authorization: Bearer token-abc123" \ -F "[email protected]" \ -F "model=openai/whisper-large-v3-turbo" \ -F "language=en" \ -F "response_format=verbose_json" ``` **支持参数:** - `file`: 需要转录的音频文件( 需要) - `model`: 用于转录的型号(需要) - `language`: 语言代码(如"en","zh")(可选;需要) `nvidia/canary-1b-v2`,无法检测语言) - `prompt`: 可选文本,用于指导抄录样式(可选) - `response_format`: 响应格式 ("json", "text", "verbose_json", 或 "diarized_json") (可选) - `temperature`: 在0和1之间取样温度(可选) 包括采样参数和vLLM扩展参数在内的完整支持参数清单,请参见: [协议定义](<https://github.com/vllm-project/vllm/blob/main/vllm/entrypoints/speech_to_text/transcription/protocol.py>). **响应格式 :** 为: `verbose_json` 响应格式 : 代码 ``` { "text": "Hello, this is a transcription of the audio file.", "language": "en", "duration": 5.42, "segments": [ { "id": 0, "seek": 0, "start": 0.0, "end": 2.5, "text": "Hello, this is a transcription", "tokens": [50364, 938, 428, 307, 275, 28347], "temperature": 0.0, "avg_logprob": -0.245, "compression_ratio": 1.235, "no_speech_prob": 0.012 } ] } ``` 目前 " verbose_json " 回复格式不支持no_speech_prob。 对于有热字支持的模型, `hotwords` 用逗号分隔的术语列表(名称、术语)来偏差识别。目前,这有下列支持: `FunAudioLLM/Fun-ASR-Nano-2512-vllm`, `OpenMOSS-Team/MOSS-Transcribe-Diarize`, `microsoft/VibeVoice-ASR-HF` 财务报告和财务报告 `hf-audio/MOSS-Transcribe-Diarize-HF` (与 `--model-impl transformers`),扬声器标签按模型生成的方式传递. 保持列表简短且与音频相关:长或不相关的列表可以降低准确性. 对于有线化支持的模型, `diarized_json` 返回 OpenAI 兼容的扬声器段。支持的模型包括 `OpenMOSS-Team/MOSS-Transcribe-Diarize`, `microsoft/VibeVoice-ASR-HF`,以及 `hf-audio/MOSS-Transcribe-Diarize-HF` 与 `--model-impl transformers`. ``` { "task": "transcribe", "duration": 6.1, "text": "Hello. Hi, how are you?", "segments": [ { "type": "transcript.text.segment", "id": "seg_0", "start": 0.0, "end": 2.8, "text": "Hello.", "speaker": "S01" } ], "usage": {"type": "duration", "seconds": 7} } ``` 与 `stream=true`, `diarized_json` 返回服务器发送事件。每个已定稿的片段产生一个 `transcript.text.delta` 包含一个事件 `segment_id`,然后是 `transcript.text.segment` 相同事件 `id` 使三角洲,包括其语言依赖的分隔器,在最后文本中给出了全文。 `transcript.text.done` 事件,其中也包括符号使用。这些三角洲是按片段而不是按符号发射的。 `OpenMOSS-Team/MOSS-Transcribe-Diarize` 一旦模型开始下一个部分,则发送每个部分,而当生成结束时,则发送最后一个部分。Transformers后端一旦生成完成就会发送这些部分。如果模型产生无效的对称记录,流会在任何完成的段后发出错误。 ``` data: {"type":"transcript.text.delta","delta":"Hello.","segment_id":"seg_0"} data: {"type":"transcript.text.segment","id":"seg_0","start":0.0,"end":2.8,"text":"Hello.","speaker":"S01"} data: {"type":"transcript.text.delta","delta":" Hi, how are you?","segment_id":"seg_1"} data: {"type":"transcript.text.segment","id":"seg_1","start":3.1,"end":5.9,"text":"Hi, how are you?","speaker":"S02"} data: {"type":"transcript.text.done","text":"Hello. Hi, how are you?","usage":{"type":"tokens","input_tokens":96,"output_tokens":31,"total_tokens":127}} data: [DONE] ``` ### 额外参数[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#extra-parameters>) 以下内容: [采样参数](<https://docs.vllm.ai/en/latest/api/#inference-parameters>) 被支持。 代码 ``` use_beam_search: bool = False """Whether or not beam search should be used.""" n: int = 1 """The number of beams to be used in beam search.""" length_penalty: float = 1.0 """Length penalty to be used for beam search.""" include_stop_str_in_output: bool = False """Whether to include the stop strings in output text.""" temperature: float = Field(default=0.0) """The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused / deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. """ watermarking: bool | None = None """Whether to apply the engine's configured watermark to this request.""" top_p: float | None = None """Enables nucleus (top-p) sampling, where tokens are selected from the smallest possible set whose cumulative probability exceeds `p`. """ top_k: int | None = None """Limits sampling to the `k` most probable tokens at each step.""" min_p: float | None = None """Filters out tokens with a probability lower than `min_p`, ensuring a minimum likelihood threshold during sampling. """ seed: int | None = Field(None, ge=_LONG_INFO.min, le=_LONG_INFO.max) """The seed to use for sampling.""" frequency_penalty: float | None = 0.0 """The frequency penalty to use for sampling.""" repetition_penalty: float | None = None """The repetition penalty to use for sampling.""" presence_penalty: float | None = 0.0 """The presence penalty to use for sampling.""" max_completion_tokens: int | None = None """The maximum number of tokens to generate.""" ``` 支持以下额外参数: 代码 ``` # Flattened stream option to simplify form data. stream_include_usage: bool | None = False stream_continuous_usage_stats: bool | None = False vllm_xargs: dict[str, str | int | float | list[str | int | float]] | None = Field( default=None, description=( "Additional request parameters with (list of) string or " "numeric values, used by custom extensions." ), ) ``` ## 翻译 API[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#translations-api>) 我们的翻译 API 兼容 [OpenAI的翻译 API](<https://platform.openai.com/docs/api-reference/audio/createTranslation>); 您可以使用 [官方 OpenAI Python 客户端](<https://github.com/openai/openai-python>) 。Whisper模型可以将55非英语支持的语言之一的音频翻译为英语。请注意流行语言 `openai/whisper-large-v3-turbo` 模式不支持翻译。 `nvidia/canary-1b-v2` 仅译成英文或从英文译出,两者均需 `language` 财务报告和财务报告 `to_language`. 无法翻译的模型,例如Voxtral和GLM-ASR,返回一个400错误. 说明 要使用 API 翻译,请使用额外的音频依赖性安装 `pip install vllm[audio]`. 代码示例 : [examples/speech_to_text/openai/openai_translation_client.py](<https://github.com/vllm-project/vllm/blob/main/examples/speech_to_text/openai/openai_translation_client.py>) ### 额外参数[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#extra-parameters_1>) 以下内容: [采样参数](<https://docs.vllm.ai/en/latest/api/#inference-parameters>) 被支持。 ``` use_beam_search: bool = False """Whether or not beam search should be used.""" n: int = 1 """The number of beams to be used in beam search.""" length_penalty: float = 1.0 """Length penalty to be used for beam search.""" include_stop_str_in_output: bool = False """Whether to include the stop strings in output text.""" seed: int | None = Field(None, ge=_LONG_INFO.min, le=_LONG_INFO.max) """The seed to use for sampling.""" temperature: float = Field(default=0.0) """The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused / deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. """ watermarking: bool | None = None """Whether to apply the engine's configured watermark to this request.""" top_p: float | None = None """Enables nucleus (top-p) sampling, where tokens are selected from the smallest possible set whose cumulative probability exceeds `p`. """ top_k: int | None = None """Limits sampling to the `k` most probable tokens at each step.""" min_p: float | None = None """Filters out tokens with a probability lower than `min_p`, ensuring a minimum likelihood threshold during sampling. """ frequency_penalty: float | None = 0.0 """The frequency penalty to use for sampling.""" repetition_penalty: float | None = None """The repetition penalty to use for sampling.""" presence_penalty: float | None = 0.0 """The presence penalty to use for sampling.""" ``` 支持以下额外参数: ``` language: str | None = None """The language of the input audio we translate from. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy. """ hotwords: str | None = None """ hotwords refers to a list of important words or phrases that the model should pay extra attention to during transcription. """ to_language: str | None = None """The language of the input audio we translate to. Please note that this is not supported by all models, refer to the specific model documentation for more details. For instance, Whisper only supports `to_language=en`. """ stream: bool | None = False """Custom field not present in the original OpenAI definition. When set, it will enable output to be streamed in a similar fashion as the Chat Completion endpoint. """ # Flattened stream option to simplify form data. stream_include_usage: bool | None = False stream_continuous_usage_stats: bool | None = False max_completion_tokens: int | None = None """The maximum number of tokens to generate.""" vllm_xargs: dict[str, str | int | float | list[str | int | float]] | None = Field( default=None, description=( "Additional request parameters with (list of) string or " "numeric values, used by custom extensions." ), ) ``` ## 实时 API[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#realtime-api>) 实时API提供基于WebSocket的流媒体音频转录,允许实时speech-to-text作为音频正在录制中. 说明 要使用实时 API,请使用额外的音频依赖安装 `uv pip install vllm[audio]`. ### 音频格式[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#audio-format>) 音频必须以16kHz样本速率,单通道作为基础64-encode的PCM16音频发送. ### 议定书概览[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#protocol-overview>) 1. 客户端连接到 `ws://host/v1/realtime` 2. 服务器发送 `session.created` 事件 3. 客户端可选择发送 `session.update` 有模型/参数 4. 客户端发送 `input_audio_buffer.commit` 准备好时 5. 客户端发送 `input_audio_buffer.append` 包含基数64的 PCM16 块的事件 6. 服务器发送 `transcription.delta` 带有增量文本的事件 7. 服务器发送 `transcription.done` 最后文本 + 使用量 8. 从步骤 5 重复下一语句 9. 可选,客户端会发送 input_audio_buffer. 承诺与 final=True 信号音频输入完成。当流媒体音频文件时有用 ### 客户端 – 服务器事件[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#client-server-events>) | 活动 | 说明 | | --- | --- | | `input_audio_buffer.append` | 发送基数64-编码音频块 : `{"type": "input_audio_buffer.append", "audio": "<base64>"}` | | `input_audio_buffer.commit` | 触发复制处理或结束 : `{"type": "input_audio_buffer.commit", "final": bool}` | | `session.update` | 配置会话 : `{"type": "session.update", "model": "model-name"}` | ### 服务器 – 客户端事件[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#server-client-events>) | 活动 | 说明 | | --- | --- | | `session.created` | 连接到会话 ID 和时间戳 | | `transcription.delta` | 递增式转录文本 : `{"type": "transcription.delta", "delta": "text"}` | | `transcription.done` | 使用统计的最后转录 | | `error` | 有信件和可选代码的错误通知 | #### 示例客户端[¶](<https://docs.vllm.ai/en/latest/serving/online_serving/speech_to_text/#example-clients>) - [openai_realtime_client .py (英语).](<https://github.com/vllm-project/vllm/tree/main/examples/speech_to_text/realtime/openai_realtime_client.py>) - 上传和转录音频文件 - [openai_realtime_microphone_client .py (英语).](<https://github.com/vllm-project/vllm/tree/main/examples/speech_to_text/realtime/openai_realtime_microphone_client.py>) - 现场麦克风录音的Gradio演示 11月 18, 2026 (英语).

查看原始来源