voice-inference-optimization

语音推理优化参考技巧库。当用户提问与语音推理、语音 AI 性能、实时语音系统延迟、ASR/TTS 优化相关时触发。包含 RTF、流式 pipeline、VAD、量化、模型选型等实战技巧。即使用户只是问"怎么让语音更快"、"TTS 延迟太高怎么办"、"ASR 流式怎么做"也应触发。

5 stars

Best use case

voice-inference-optimization is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

语音推理优化参考技巧库。当用户提问与语音推理、语音 AI 性能、实时语音系统延迟、ASR/TTS 优化相关时触发。包含 RTF、流式 pipeline、VAD、量化、模型选型等实战技巧。即使用户只是问"怎么让语音更快"、"TTS 延迟太高怎么办"、"ASR 流式怎么做"也应触发。

Teams using voice-inference-optimization should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/voice-inference-optimization/SKILL.md --create-dirs "https://raw.githubusercontent.com/detailyang/dotfiles/main/skills/voice-inference-optimization/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/voice-inference-optimization/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How voice-inference-optimization Compares

Feature / Agentvoice-inference-optimizationStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

语音推理优化参考技巧库。当用户提问与语音推理、语音 AI 性能、实时语音系统延迟、ASR/TTS 优化相关时触发。包含 RTF、流式 pipeline、VAD、量化、模型选型等实战技巧。即使用户只是问"怎么让语音更快"、"TTS 延迟太高怎么办"、"ASR 流式怎么做"也应触发。

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Voice Inference Optimization Skill

语音推理优化的核心参考。覆盖架构设计、ASR/TTS 优化、模型压缩和基础设施四个层次。

## 核心指标速查

| 指标 | 含义 | 目标值 |
|---|---|---|
| **RTF**(Real-Time Factor) | 计算耗时 / 音频时长 | < 0.5 可实时,< 0.1 有余量 |
| **TTFT** | 第一个 token 的延迟 | 越低越好 |
| **FPL**(First Packet Latency) | TTS 首个音频 chunk 延迟 | < 700ms |
| **WER / CER** | 识别错误率 | 量化后允许 < 3% 上升 |

> RTF > 1.0 = 无法实时;RTF < 0.1 才有足够的系统余量。

---

## 一、架构层(最大收益,优先看)

### 流式 Pipeline
串行等待是最大的延迟来源。优化方案:各阶段重叠并行。
- ASR 出部分转录 → 立即送 LLM
- LLM 出部分 token → 立即送 TTS
- TTS 出部分音频 → 立即播放

**效果**:端到端延迟从 800ms~2s 压缩到 300ms 以内。

### VAD Flush Trick
- 问题:等完整句子再触发 ASR,引入 ~500ms 延迟
- 方案:VAD 检测到静音立即 flush 缓冲区
- 效果:延迟从 ~500ms → ~125ms

### TTS Token Buffering
TTS 不等 LLM 全部输出,按策略触发推理:
- 遇到标点 → 立即推理当前缓冲
- 缓冲超过 64 token → 强制推理
- 避免单 token 触发(延迟高、不稳定)

### 组件并行部署
- ASR + TTS 同一 GPU,LLM 单独一张(减少竞争)
- 或全部 co-locate(省去网络传输)
- 推荐起点:单张 H100 80GB,可跑 11B 级全链路

### 并行 LID(语言识别)
- 问题:LID 作为前置步骤需等 2-3 秒音频
- 方案:ASR 和 LID 共享 encoder 并行运行;LID 置信度 > 0.9 后再裁剪无关 decoder

---

## 二、ASR 优化

### 架构选型

| 架构 | 特点 | 适用场景 |
|---|---|---|
| **CTC(Conformer-CTC)** | 帧同步输出,天然流式,RTF < 0.2 | 实时对话、电话 |
| **Attention(Whisper)** | 非因果,精度高,不支持原生流式 | 离线转录 |
| **Two-Pass(CTC + Attention)** | CTC 出流式结果,Attention 做重排序 | 兼顾流式和精度 |

### Whisper 流式改造(Two-Pass Decoding)
1. 额外训练带 causal attention mask 的 CTC decoder
2. CTC decoder 实时产出部分转录
3. 原 Whisper decoder 对部分结果重排序
4. 需要配套 fine-tuning 数据

### 噪声鲁棒性
- SNR < 3dB 时精度急剧下降
- 嘈杂环境优先选 distil-whisper 等噪声鲁棒模型,而非纯精度模型
- 背景人声对 Whisper 影响较小;混响和环境噪声更致命

---

## 三、TTS 优化

### 模型选型(RTF 参考)

| 模型 | RTF(GPU) | 首包延迟 | 备注 |
|---|---|---|---|
| NeuTTS Air | ~0.003 | 极低 | 320x 实时,单卡数百并发 |
| Kokoro | 低 | 低 | 低延迟首选 |
| XTTS v2 | ~0.3 | 较高 | 实时可用,余量较少 |
| CSM-1B (i-LAVA) | 0.48 | < 700ms | 可调 RVQ 深度 |

### RVQ Codebook 深度控制
- RVQ 层数越多 → 音质越好,延迟越高
- 减少 codebook 深度 = 降低 RTF,提升流式速度
- 是音质和延迟间最直接的设计杠杆

### 扩散模型 TTS 的 NFE(步数)控制
- NFE = 16:UTMOS = 3.79,RTF = 0.016(已足够实时)
- 生产中无需最大步数,找质量可接受的最低 NFE

---

## 四、模型压缩

### 量化对比

| 精度 | 内存节省 | 延迟降低 | 质量损失 |
|---|---|---|---|
| INT8 | ~50% | ~43% | < 3% WER 上升 |
| INT4 | ~75% | 显著 | 需实测验证 |
| FP4 | 最大 | 最大 | 不推荐低延迟场景 |

**工具链**:
- `ONNX Runtime`:dynamic quantization,Transformer 友好,支持 symbolic shape inference
- `BitsAndBytes`:4-bit PTQ,LLM 友好,可降低 40% 延迟
- `TensorRT`:NVIDIA GPU 专用,算子融合 + kernel 优化

**实测案例(Whisper-tiny)**:
- LoRA fine-tune → INT8 量化(ONNX Runtime)
- M1 Mac CPU:RTF = 0.20,延迟降 43%
- A10 GPU:RTF = 0.06

### 知识蒸馏
- distil-whisper:Whisper 蒸馏版,精度接近,速度 2-6x
- 适合噪声鲁棒性要求高、延迟敏感的场景

### 算子融合 & 稀疏化
- Operator fusion:减少 kernel launch 开销,适合 vocoder / encoder
- Learned weight sparsity:结合 INT8 可达 2-3x 加速
- 可实现 ARM 硬件上 < 15ms 端到端 TTS

---

## 五、基础设施

### 网络传输
- WebSocket 持久连接(避免 TCP 握手开销)
- ASR/TTS 与 LLM co-locate 同一 GPU 集群(消除跨 provider 网络延迟)
- 区域化部署:ASR + TTS 在 edge,LLM 在中心节点

### 模型预热(Warmup)
- TTS 启动时用参考音频做 warmup,减少首次推理的 latency jitter
- 避免冷启动带来的首请求慢问题

### 多线程架构
- ASR / LLM / TTS 各运行在独立线程 + 队列
- 生产者-消费者模型:LLM 向 TTS queue 写 token,TTS 消费并合成

---

## 典型端到端延迟(2025 年底)

```
用户说话结束
    ↓ VAD flush          ~125ms(优化后)
    ↓ ASR                ~150ms(Deepgram,US)
    ↓ LLM TTFT           ~350ms(流式首 token)
    ↓ TTS 首包            ~75ms(ElevenLabs)
用户听到回复             总计 ~300-500ms ✅

未优化串行系统:           800ms~2s+ ❌
```

---

## 参考来源

- [Introl: Voice AI Infrastructure Guide](https://introl.com/blog/voice-ai-infrastructure-real-time-speech-agents-asr-tts-guide-2025)
- [Chanl: Voice AI pipeline & 300ms budget](https://www.channel.tel/blog/voice-ai-pipeline-stt-tts-latency-budget)
- [Spheron: Voice AI GPU Infrastructure](https://www.spheron.network/blog/voice-ai-gpu-infrastructure/)
- [EmergentMind: Latency-Aware TTS Pipeline](https://www.emergentmind.com/topics/latency-aware-text-to-speech-tts-pipeline)
- [Dev.to: Voice AI Guide Part 3](https://dev.to/programmerraja/2025-voice-ai-guide-how-to-make-your-own-real-time-voice-agent-part-3-3ocb)
- [arxiv 2506.12154: Two-Pass Streaming Whisper](https://arxiv.org/pdf/2506.12154)
- [ONNX Runtime Quantization Docs](https://onnxruntime.ai/docs/performance/model-optimizations/quantization.html)

Related Skills

simd-optimization

5
from detailyang/dotfiles

SIMD (Single Instruction Multiple Data) 优化技巧知识库,蒸馏自 Daniel Lemire 博客(lemire.me/blog) 的数百篇性能工程文章与研究论文。覆盖 x86 (SSE/AVX2/AVX-512) 和 ARM (NEON/SVE2) 的实战优化 模式、代码范例与性能直觉。当用户提问涉及 SIMD 向量化、性能优化、数据并行、字节解析、 JSON/文本/UTF-8/base64 加速、位图操作、整数压缩、prefix sum、字符串扫描、 类型转换加速时触发。也适用于"为什么我的循环慢"、"如何用 intrinsic 优化"、"AVX vs NEON" 等问题。只要涉及批量数据处理性能就应优先查阅本 skill。

nsight-compute

5
from detailyang/dotfiles

使用 Nsight Compute 对 CUDA kernel 进行性能分析和优化的完整指南。 当用户提到 CUDA 性能分析、kernel 调优、ncu 命令、profiler 数据解读、 瓶颈诊断、SOL 指标、占用率分析、DRAM Throughput、L1/L2 Cache Throughput、 Compute Throughput、Roofline 图、Warp Stall、Memory Chart、Section Sets、 Scheduler Statistics、Warp State、Branch Divergence、Register Spilling 等话题时, 主动使用此 skill。也适用于用户粘贴 ncu 输出数据需要解读的场景。 资料来源:NVIDIA 官方文档 2026.1、Kernel Profiling Guide、NERSC Roofline 文档。

knowledge-distillation

5
from detailyang/dotfiles

Expert-level knowledge about AI/ML knowledge distillation — a training paradigm where a student model learns from a teacher model. Use this skill whenever the user asks about knowledge distillation, teacher-student learning, model compression via distillation, soft targets, KD loss, on-policy distillation, off-policy distillation, self-distillation, multi-teacher distillation, sequence-level KD, GKD (Generalized Knowledge Distillation), OPD (On-Policy Distillation), MOPD (Multi-Teacher On-Policy Distillation), OPSD (On-Policy Self-Distillation), DistilBERT, soft labels, temperature scaling, KL divergence in distillation, or any RL–distillation hybrid method. Also trigger when asked about compressing large LLMs into smaller ones, transferring capabilities from frontier models, exposure bias in autoregressive models fixed via student rollouts, or synthetic data pipelines for model training.

gpu-glossary

5
from detailyang/dotfiles

GPU 术语速查手册,基于 Modal GPU Glossary(CC BY 4.0)。当用户提问涉及 GPU 硬件结构、CUDA 编程模型、GPU 性能分析、内核优化、内存带宽、屋顶线模型、 SM 占用率、Warp 分化、算术强度等概念时触发。也适用于"为什么我的 kernel 慢"、 "compute-bound 和 memory-bound 怎么区分"等实际调优问题。

complexity-optimizer

5
from detailyang/dotfiles

Analyze a software codebase for algorithmic complexity and performance hotspots, then propose or implement safe optimizations without breaking behavior. Use when Codex is asked to scan many files, find inefficient loops, nested iteration, repeated scans, costly rendering/recomputation, N+1 queries, avoidable O(n^2) or O(n) operations, or reduce complexity such as O(n^2) to O(n log n) / O(n), while preserving tests, APIs, outputs, and maintainability.

teach

5
from detailyang/dotfiles

Teach the user a new skill or concept, within this workspace.

refactor

5
from detailyang/dotfiles

Find deepening opportunities in a codebase, informed by the domain language in CONTEXT.md and the decisions in docs/adr/. Use when the user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more testable and AI-navigable.

xray

5
from detailyang/dotfiles

深度分析统一入口。处理概念、英文单词、URL 页面、研究论文、项目/创业透视审查。用户要求分析论文、解释单词、拆网页、评估项目或"帮我想想这个"时使用。

feedly-daily

5
from detailyang/dotfiles

每日自动化阅读 Feedly Today 文章、标记已读、生成中文总结报告。当用户说"打开 Feedly 看新闻"、"帮我看今天的 Feedly"、"获取 Feedly 文章"、"标记 Feedly 已读"、"生成今日阅读报告"、"总结今天的技术新闻"时使用此 skill。

voice-channel-uwd

16
from plurigrid/asi

Voice Channel UWD Skill

invoice-organizer

16
from plurigrid/asi

Automatically organizes invoices and receipts for tax preparation by

building-role-mining-for-rbac-optimization

16
from plurigrid/asi

Apply bottom-up and top-down role mining techniques to discover optimal RBAC roles from existing user-permission assignments, reducing role explosion and enforcing least privilege.