VibeVoice-ASR-Streaming 文件推理怎么用 --context_info 热词参数偏向指定术语?
【免费下载链接】VibeVoiceOpen-Source Frontier Voice AI项目地址: https://gitcode.com/GitHub_Trending/vib/VibeVoice
VibeVoice-ASR-Streaming 在音频还在到达时就逐块转写:每收到一个 chunk 就输出一次文本,而不必等整段音频结束。如果你的任务是对本地音频文件做流式推理,并让识别偏向某些指定术语(如公司名、产品名、技术词汇),入口是 demo/vibevoice_asr_streaming_inference_from_file.py 脚本的--context_info参数。适用前提:文档推荐的 NVIDIA PyTorch 容器环境、ffmpeg,以及一个流式版本的 checkpoint。
准备环境与依赖
按 VibeVoice-ASR-Streaming 文档 的安装步骤,共三步:
- 启动 NVIDIA PyTorch 容器。文档注明 24.07 ~ 25.12 版本已验证,更早版本也兼容:
sudo docker run --privileged --net=host --ipc=host --ulimit memlock=-1:-1 --ulimit stack=-1:-1 --gpus all --rm -it nvcr.io/nvidia/pytorch:25.12-py3- 克隆仓库并安装项目:
git clone https://github.com/microsoft/VibeVoice.git cd VibeVoice pip install -e .- 安装 ffmpeg,文件推理需要用它解码音频:
apt update && apt install ffmpeg -yflash attention 属于可选依赖:文档说明,如果容器里没有 flash attention,需要按 flash-attention 的说明手动安装(pip install flash-attn --no-build-isolation)。推理脚本的--attn_implementation默认值是sdpa,只有你显式改用flash_attention_2时才依赖它。
运行文件推理命令并传入 --context_info
文档 Usage 2 的基础命令是--model_path+--audio_files,加上热词参数后完整写法如下:
python demo/vibevoice_asr_streaming_inference_from_file.py \ --model_path [add the checkpoint path here] \ --audio_files [add an audio path here] \ --context_info "Microsoft,VibeVoice"命令中各部分的来源与替换方式:
[add the checkpoint path here]:文档原文占位符。填流式 checkpoint 的本地目录,或 Hugging Face repo id——脚本的load_frame_config明确支持两种形式,传入 repo id 时它会通过hf_hub_download拉取preprocessor_config.json。README 中流式模型对应的是microsoft/VibeVoice-ASR-Streaming-7B。[add an audio path here]:本地音频文件路径,参数是nargs='+',一次可以传多个文件。仓库demo/asr_demo/目录下有demo1-chat.mp3、demo2-song.mp3、demo3-hotwords.wav等音频,可用作测试输入。[--context_info "Microsoft,VibeVoice"]:文档给出的示例热词,逗号分隔。文档说明 "Add--context_info "Microsoft,VibeVoice"to bias recognition toward specific terms, the same way hotwords work on the non-streaming model";脚本中该参数的帮助文本为 "Hotwords to bias recognition, e.g. 'Microsoft,VibeVoice'",默认值为None(不传则不加热词)。非流式 VibeVoice-ASR 文档 对同类热词的描述是:提供特定的名字、技术术语或背景信息来引导识别过程,提升领域内容的准确性。
其余可选参数(来自脚本argparse定义):
| 参数 | 默认值 | 说明 |
|---|---|---|
--device | CUDA 可用时为cuda,否则cpu | 可选cuda/cpu/mps/xpu;cuda时模型以 bfloat16 加载,其他设备以 float32 加载 |
--max_new_tokens | 256 | 每个 chunk 生成的最大 token 数 |
--temperature | 0.0 | 采样温度,0 = greedy decoding |
--attn_implementation | sdpa | 可选flash_attention_2/sdpa/eager |
启动时的 checkpoint 校验与常见报错
脚本启动时会做两项检查,不满足就退出,这对判断"报错是不是用错了 checkpoint"很关键:
- 读取 checkpoint 的
preprocessor_config.json,从中取chunk_frames和lookahead_frames计算 chunk 时长与 lookahead 延迟,并打印Chunk: <时长>s, lookahead: <延迟>s。若缺少这两个键,脚本报错退出,提示该 checkpoint "not a streaming checkpoint",并指明应改用非流式脚本demo/vibevoice_asr_inference_from_file.py。 - 检查 tokenizer 是否含有
<|text_chunk_end|>token。没有则退出,原因是"no chunk would ever end"(chunk 永远不会结束,流式输出无法进行)。
注意 chunk 时长和 lookahead 不是命令行参数:文档明确它们读自 checkpoint 的preprocessor_config.json,"a checkpoint always runs at the chunk it was trained on",即流式 checkpoint 始终按训练时的 chunk 设置运行,无法在推理时修改。
输出格式与热词效果的核对
脚本的逐块输出与收尾汇总格式是固定的(尖括号内为运行时实际值):
File: <音频路径> [1/<总块数>] <本块转写文本> [2/<总块数>] <本块转写文本> ... --- Transcription --- <各块拼接后的完整转写> Audio: <音频时长>s, generation time: <生成耗时>s, RTF: <RTF>文档说明 "Each chunk is printed as soon as the model emits it",即每行 chunk 文本是模型一产生就打印的,不是全部结束后一次性输出。
热词效果没有固定的成功指标,文档只说明--context_info用于把识别偏向指定术语。实际核对方式是查看--- Transcription ---之后完整转写里你传入的那些术语的转写结果;如需观察偏置差异,可以对同一段音频分别运行带与不带--context_info的命令,对照两处完整转写中指定术语的输出。
限制与替代入口
- 该脚本只接受流式 checkpoint。拿到非流式 VibeVoice-ASR checkpoint 时会被上面第 1 项检查拒绝,此时按脚本提示改用
demo/vibevoice_asr_inference_from_file.py,那是非流式模型的推理入口(见 docs/vibevoice-asr.md)。 - 文件解码依赖 ffmpeg,缺少它无法运行文件推理。
- 如果你想在浏览器里录音并实时看到带热词的转写,文档 Usage 1 提供了 FastAPI demo:
python demo/vibevoice_asr_streaming_fastapi_demo.py --model_path [add the checkpoint path here],打开http://localhost:7870,页面有 "Hotwords (context_info)" 输入框,作用与文件脚本的--context_info相同。
【免费下载链接】VibeVoiceOpen-Source Frontier Voice AI项目地址: https://gitcode.com/GitHub_Trending/vib/VibeVoice
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考