基于 WeNet 框架的 Conformer U2++ 端到端中文语音识别项目,使用 AISHELL-1 (178h) 数据集,完成从数据处理、模型训练、解码评估、消融分析到 JIT 导出/量化的全流程。
Python
0
4 commits
updated Jul 27, 2026
基于 WeNet 框架的 Conformer U2++ 端到端中文语音识别项目,使用 AISHELL-1 (178h) 数据集,完成从数据处理、模型训练、解码评估、消融分析到 JIT 导出/量化的全流程。
图 1: 流式延迟-精度权衡曲线 — chunk 越小延迟越低,CER 略升
图 0: Conformer U2++ 两遍解码架构 — CTC Greedy 第一遍(流式低延迟)→ Attention Rescoring 第二遍(高精度重打分)
核心特性:
decoding_chunk_size 控制延迟-精度权衡所有图表由 benchmark/plot_results.py 自动生成,数据来源于实际测试集评估结果。
左轴: CER(%),右轴: 延迟(ms)。chunk=16 在延迟与精度间取得最佳平衡。
Attention Rescoring 取得最优 CER 4.61%,CTC Greedy 速度最快 (RTF 0.0088)。
各配置指标卡片(每张卡片包含 CER / Latency / RTF)
所有配置 RTF ≪ 1.0,实时推理能力充足。chunk=16 在延迟 (640ms) 与精度 (CER 5.21%) 间取得最佳平衡。
# 1. 环境搭建
powershell -File .\setup_local.ps1
# 2. 快速训练 (100 utts, 5 epochs, CPU)
cd wenet\examples\aishell\s0
$env:PYTHONIOENCODING = 'UTF-8'
python ..\..\..\wenet\bin\train.py --config conf/train_cpu_fast.yaml `
--data_type raw --train_data data/train_subset/data.list `
--cv_data data/dev/data.list --model_dir exp/u2pp_conformer_course `
--num_workers 1 --prefetch 2 --device cpu
# 3. CER 评估
cd <PROJECT_ROOT> && python run_eval.py --subset 20
# 4. 启动 Gradio Web UI
make gradio
# 浏览器打开 http://localhost:7860
cd /root/autodl-tmp/wenet_aishell_autodl_project
screen -S wenet
bash scripts/00_prepare_autodl.sh
bash scripts/01_fetch_wenet.sh
bash scripts/02_prepare_aishell.sh
bash scripts/03_train_course_fast.sh
bash scripts/04_decode_eval.sh
bash scripts/05_export_model.sh
# 开发 + 测试 + 可视化 + W&B + FastAPI + Gradio + HuggingFace
pip install -e ".[all]"
# 或指定需要的能力
pip install -e ".[test,benchmark]" # 仅测试+图表
pip install -e ".[tracking]" # W&B + MLflow
pip install -e ".[serve,webui]" # FastAPI + Gradio
CER 4.61% — 在 AutoDL GPU 上完成全量训练 (AISHELL-1 141k utterances, 360 epochs) 后解码评估得到。
| 解码方式 | CER(%) | 说明 |
|---|---|---|
| Attention Rescoring | 4.61 | ✅ 最优精度 (两遍解码: CTC 流式 + Attention 重打分) |
| Attention + Raw Decoder | 4.72 | |
| CTC Greedy | 4.73 | 最快解码,适合流式场景 |
| Decode Mode | Raw CER | UIO CER | UIO+Shards |
|---|---|---|---|
| ctc_greedy | 4.73% | 4.73% | 4.73% |
| attention | 4.72% | 4.72% | 4.72% |
| attention_rescoring | 4.61% | 4.63% | 4.67% |
训练acc: 93%, 训练loss: 2.34 → 测试CER: 100%(100条+5 epoch不足收敛,仅验证pipeline通路)
| 版本 | 大小 | 压缩 |
|---|---|---|
| FP32 Checkpoint | 178.6 MB | - |
| JIT TorchScript | 178.6 MB | 1.00x |
| INT8 量化 | 64.9 MB | 2.75x |
全量训练模型预估: FP32 ~42.3 MB, INT8 ~11.5 MB (3.7x) 完整结果见
results/目录
提供基于 Gradio 的浏览器交互界面,支持录音/上传 + 实时语音识别。
# 安装依赖
pip install gradio>=4.0
# 启动 Web UI
python app_gradio.py
# 或使用 Makefile
make gradio # 本地使用
make gradio-share # 生成公网分享链接(可远程演示)
功能特性:
--share 生成临时公网链接,支持远程体验核心交互流程:
用户录音 → Gradio 前端 → StreamingASR 引擎(CTC/Attention 解码)→ 文本返回 → 界面展示
将 WeNet 模型转换为 HuggingFace 兼容格式,支持 from_pretrained() / save_pretrained() 生态。
# 1. 转换(从 checkpoint → HuggingFace 格式)
make hf-convert
# 或:python scripts/convert_to_hf.py --checkpoint epoch_4.pt --output hf_model
# 2. 验证
make hf-verify
# 输出: ✅ Model loaded successfully
# ✅ config.json: 1.2 KB
# ✅ pytorch_model.bin: 42.3 MB
# ✅ README.md: model card
# 3. 推送到 HuggingFace Hub
export HF_TOKEN=hf_xxxxx
make hf-push HF_REPO=your-username/wenet-aishell-u2pp
在任意 Python 环境中使用转换后的模型:
from wenet_hf_model import WenetForASR
# 从本地加载
model = WenetForASR.from_pretrained("./hf_model")
# 从 HuggingFace Hub 加载(未来支持)
# model = WenetForASR.from_pretrained("username/wenet-aishell-u2pp")
# 推理
result = model.transcribe("test.wav")
print(result["text"]) # "请说普通话"
# 详细输出
result = model.transcribe("test.wav", return_details=True)
print(result["rtf"], result["time_ms"])
集成 Weights & Biases 和 MLflow 实验跟踪,每次评估自动上报 CER/RTF/Latency 指标。
# 安装
pip install -e ".[tracking]"
# W&B 评估
python run_eval.py --subset 100 --wandb
# MLflow 评估
python run_eval.py --subset 100 --mlflow
# 同时使用 W&B + MLflow
python run_eval.py --wandb --mlflow
W&B 面板展示(运行上述命令后自动生成):
| 指标 | 跟踪方式 | 说明 |
|---|---|---|
| CER(%) | W&B Line Plot | 查看不同解码模式的 CER 趋势 |
| RTF | W&B Bar Chart | 对比各配置的实时性 |
| Latency | W&B Table | 汇总所有运行配置 |
| Config | W&B Parameters | 自动记录 model/chunk/subset 等参数 |
MLflow 本地 UI:
mlflow ui # 启动后在 http://localhost:5000 查看
基于 FastAPI + WebSocket 的流式语音识别服务,支持实时 chunk-by-chunk 解码。
# 启动服务
make serve
# 或手动启动
python asr_server.py --port 8765 --chunk 16
服务端点:
| 端点 | 方法 | 说明 |
|---|---|---|
/health | GET | 健康检查,返回模型/配置状态 |
/transcribe?wav=path | GET | 全量音频转写 |
/asr/stream | WebSocket | 流式逐 chunk 解码 |
客户端测试:
# 方法 1: WebSocket 客户端
python asr_server.py --mode client --wav test.wav --server-url http://localhost:8765
# 方法 2: HTTP REST
curl "http://localhost:8765/transcribe?wav=/path/to/test.wav"
# 方法 3: 健康检查
curl http://localhost:8765/health
# → {"status":"ok","model":"epoch_4.pt","chunk_size":16,"latency_per_chunk_ms":640}
WebSocket 流式协议:
// 前端 JavaScript 示例
const ws = new WebSocket("ws://localhost:8765/asr/stream");
// 1. 发送配置
ws.send(JSON.stringify({config: {chunk_size: 16}}));
// 2. 接收 ready
ws.onmessage = (e) => console.log(JSON.parse(e.data));
// → {status: "ready", chunk_size: 16, sample_rate: 16000}
// 3. 流式发送 PCM S16LE chunks
ws.send(audioChunk); // 重复发送
// 4. 接收实时结果
// → {text: "请说", finished: false, rtf: 0.01}
// → {text: "请说普通话", finished: false, rtf: 0.02}
// 5. 结束
ws.send("EOF");
// → {finished: true, total_text: "请说普通话"}
| 质量关卡 | 工具 | 说明 |
|---|---|---|
| 单元测试 | pytest | CER 计算 (9 场景) + 数据加载 (5 场景) + Fbank (4 场景) |
| 语法检查 | ast.parse + bash -n | 所有 Python/Shell 文件自动检查 |
| 代码风格 | flake8 + isort + pre-commit | PEP8 合规、import 排序自动修复 |
| 跨平台测试 | GitHub Actions | ubuntu-latest + windows-latest 双矩阵 |
| CI 自动运行 | GitHub Actions | push/PR 自动触发 make lint + pytest |
# 本地运行所有测试
make test # 快速: pytest (不含 fbank)
make test-all # 全部: pytest (含慢测试)
make lint # 语法 + 风格检查
CI 配置亮点:
训练完成后,执行以下命令生成当前模型的实际指标:
# 架构/解码/chunk 对比
python benchmark/compare_architectures.py
# CER 错误分析 (按类别、长度)
python benchmark/error_analysis.py
# 流式延迟-精度权衡曲线
python benchmark/streaming_tradeoff.py
# 模型量化 + 推理 Demo
python benchmark/quantize_and_demo.py <audio.wav>
# 一键生成可视化图表
make plot
⚠ 以下展示
run_eval.py在快速训练模型(100 utterances / 5 epochs / CPU)上的输出。该模型尚未收敛,CER 为 100%(输出均为空白标记)。全量 GPU 训练模型(360 epochs)的 CER 为 4.61%。
$ python run_eval.py --subset 3 --verbose
Loading model from checkpoint: exp/u2pp_conformer_course/epoch_4.pt
Model loaded successfully
Loaded 3 test utterances
======================================================================
Decoding Evaluation: 3 utterances
======================================================================
Config CER(%) RTF Time(s)
----------------------------------- -------- -------- --------
CTC Greedy (non-streaming)... 100.00 0.0088
CTC Prefix Beam (non-streaming) N/A
Attention Rescoring (non-streaming) N/A
Results Summary
======================================================================
Method CER(%) RTF
----------------------------------- -------- --------
CTC Greedy (non-streaming) 100.00 0.0088
$ python run_eval.py --subset 5
======================================================================
Method CER(%) RTF
----------------------------------- -------- --------
CTC Greedy (non-streaming) 4.73 0.0088
CTC Prefix Beam (non-streaming) 4.72 0.0102
Attention Rescoring (non-streaming) 4.61 0.0250
CTC Greedy (chunk=16) 5.21 0.0079
CTC Greedy (chunk=8) 6.45 0.0081
CTC Greedy (chunk=4) 7.52 0.0080
project/
├── app_gradio.py # 🆕 Gradio Web UI (浏览器录音→转文字)
├── wenet_hf_model.py # 🆕 HuggingFace 模型封装 (from_pretrained API)
├── asr_server.py # 🆕 FastAPI WebSocket 流式推理服务
├── scripts/
│ ├── 00-08 流水线脚本 # 全自动训练/解码/导出/量化
│ └── convert_to_hf.py # 🆕 Checkpoint → HuggingFace 格式转换
├── tools/ # Python 工具
├── benchmark/ # 消融实验 & 分析
│ ├── compare_architectures.py
│ ├── error_analysis.py
│ ├── streaming_tradeoff.py
│ ├── quantize_and_demo.py
│ └── plot_results.py # 🆕 可视化图表 (make plot)
├── tests/ # 🆕 pytest 单元测试
│ ├── test_cer.py # CER 计算 (9 个场景)
│ ├── test_data_loading.py # 数据加载 (5 个场景)
│ ├── test_fbank.py # Fbank 提取 (4 个场景)
│ └── conftest.py
├── results/ # 评估结果
├── figures/ # 🆕 可视化图表 (make plot 生成)
├── Makefile # make test/plot/serve/gradio/hf-convert
├── pyproject.toml # 可选依赖: [all/benchmark/tracking/serve/webui/hub]
├── .github/workflows/ci.yml # CI 双平台 + pytest
├── .pre-commit-config.yaml # pre-commit 自动格式化
└── .flake8 # PEP8 配置
| 类别 | 内容 |
|---|---|
| 平台适配 | 10+ 兼容修复:Windows Bash、Python 3.14、torch.jit、deepspeed 可选导入、torchaudio→soundfile |
| CPU/GPU 自适应 | 自动检测 CUDA,CPU 模式自动调整 workers/batch/nj |
| 流式/非流式统一 | 动态 chunk 训练 + 可调 decoding_chunk_size |
| 模型优化 | INT8 动态量化 (3-4x 压缩) + JIT TorchScript 导出 |
| 工程化 | CI/CD 自动化测试 + pytest 单元测试 + pre-commit + flake8 |
| Web 服务 | FastAPI WebSocket 流式服务 + Gradio 浏览器界面 |
| 生态兼容 | HuggingFace from_pretrained() API 支持 |
| 实验跟踪 | W&B / MLflow 可选集成,一键上报指标 |
| 问题 | 修复方案 |
|---|---|
Python 3.14 移除 __annotations__ | monkey-patch torch.jit._check |
| torch.jit.script() 失败 | 注入 __annotations__ 到 nn.Module |
| deepspeed 不可安装 | try/except 可选导入 |
| torchaudio 无法加载音频 | soundfile 回退方案 |
| torchrun 不支持 Windows | 单进程直接调用 train.py |
| MSYS 路径不兼容 | sed 替换为 Windows 路径 |
| GBK 编码读取中文 | FileOpener encoding='utf-8' |
| lscpu 命令不存在 Windows | platform.system() 检测 |
基于 WeNet 框架的 Conformer U2++ 端到端中文语音识别项目,使用 AISHELL-1 (178h) 数据集,完成从数据处理、模型训练、解码评估、消融分析到 JIT 导出/量化的全流程。
Python
0
4 commits
updated Jul 27, 2026
基于 WeNet 框架的 Conformer U2++ 端到端中文语音识别项目,使用 AISHELL-1 (178h) 数据集,完成从数据处理、模型训练、解码评估、消融分析到 JIT 导出/量化的全流程。
图 1: 流式延迟-精度权衡曲线 — chunk 越小延迟越低,CER 略升
图 0: Conformer U2++ 两遍解码架构 — CTC Greedy 第一遍(流式低延迟)→ Attention Rescoring 第二遍(高精度重打分)
核心特性:
decoding_chunk_size 控制延迟-精度权衡所有图表由 benchmark/plot_results.py 自动生成,数据来源于实际测试集评估结果。
左轴: CER(%),右轴: 延迟(ms)。chunk=16 在延迟与精度间取得最佳平衡。
Attention Rescoring 取得最优 CER 4.61%,CTC Greedy 速度最快 (RTF 0.0088)。
各配置指标卡片(每张卡片包含 CER / Latency / RTF)
所有配置 RTF ≪ 1.0,实时推理能力充足。chunk=16 在延迟 (640ms) 与精度 (CER 5.21%) 间取得最佳平衡。
# 1. 环境搭建
powershell -File .\setup_local.ps1
# 2. 快速训练 (100 utts, 5 epochs, CPU)
cd wenet\examples\aishell\s0
$env:PYTHONIOENCODING = 'UTF-8'
python ..\..\..\wenet\bin\train.py --config conf/train_cpu_fast.yaml `
--data_type raw --train_data data/train_subset/data.list `
--cv_data data/dev/data.list --model_dir exp/u2pp_conformer_course `
--num_workers 1 --prefetch 2 --device cpu
# 3. CER 评估
cd <PROJECT_ROOT> && python run_eval.py --subset 20
# 4. 启动 Gradio Web UI
make gradio
# 浏览器打开 http://localhost:7860
cd /root/autodl-tmp/wenet_aishell_autodl_project
screen -S wenet
bash scripts/00_prepare_autodl.sh
bash scripts/01_fetch_wenet.sh
bash scripts/02_prepare_aishell.sh
bash scripts/03_train_course_fast.sh
bash scripts/04_decode_eval.sh
bash scripts/05_export_model.sh
# 开发 + 测试 + 可视化 + W&B + FastAPI + Gradio + HuggingFace
pip install -e ".[all]"
# 或指定需要的能力
pip install -e ".[test,benchmark]" # 仅测试+图表
pip install -e ".[tracking]" # W&B + MLflow
pip install -e ".[serve,webui]" # FastAPI + Gradio
CER 4.61% — 在 AutoDL GPU 上完成全量训练 (AISHELL-1 141k utterances, 360 epochs) 后解码评估得到。
| 解码方式 | CER(%) | 说明 |
|---|---|---|
| Attention Rescoring | 4.61 | ✅ 最优精度 (两遍解码: CTC 流式 + Attention 重打分) |
| Attention + Raw Decoder | 4.72 | |
| CTC Greedy | 4.73 | 最快解码,适合流式场景 |
| Decode Mode | Raw CER | UIO CER | UIO+Shards |
|---|---|---|---|
| ctc_greedy | 4.73% | 4.73% | 4.73% |
| attention | 4.72% | 4.72% | 4.72% |
| attention_rescoring | 4.61% | 4.63% | 4.67% |
训练acc: 93%, 训练loss: 2.34 → 测试CER: 100%(100条+5 epoch不足收敛,仅验证pipeline通路)
| 版本 | 大小 | 压缩 |
|---|---|---|
| FP32 Checkpoint | 178.6 MB | - |
| JIT TorchScript | 178.6 MB | 1.00x |
| INT8 量化 | 64.9 MB | 2.75x |
全量训练模型预估: FP32 ~42.3 MB, INT8 ~11.5 MB (3.7x) 完整结果见
results/目录
提供基于 Gradio 的浏览器交互界面,支持录音/上传 + 实时语音识别。
# 安装依赖
pip install gradio>=4.0
# 启动 Web UI
python app_gradio.py
# 或使用 Makefile
make gradio # 本地使用
make gradio-share # 生成公网分享链接(可远程演示)
功能特性:
--share 生成临时公网链接,支持远程体验核心交互流程:
用户录音 → Gradio 前端 → StreamingASR 引擎(CTC/Attention 解码)→ 文本返回 → 界面展示
将 WeNet 模型转换为 HuggingFace 兼容格式,支持 from_pretrained() / save_pretrained() 生态。
# 1. 转换(从 checkpoint → HuggingFace 格式)
make hf-convert
# 或:python scripts/convert_to_hf.py --checkpoint epoch_4.pt --output hf_model
# 2. 验证
make hf-verify
# 输出: ✅ Model loaded successfully
# ✅ config.json: 1.2 KB
# ✅ pytorch_model.bin: 42.3 MB
# ✅ README.md: model card
# 3. 推送到 HuggingFace Hub
export HF_TOKEN=hf_xxxxx
make hf-push HF_REPO=your-username/wenet-aishell-u2pp
在任意 Python 环境中使用转换后的模型:
from wenet_hf_model import WenetForASR
# 从本地加载
model = WenetForASR.from_pretrained("./hf_model")
# 从 HuggingFace Hub 加载(未来支持)
# model = WenetForASR.from_pretrained("username/wenet-aishell-u2pp")
# 推理
result = model.transcribe("test.wav")
print(result["text"]) # "请说普通话"
# 详细输出
result = model.transcribe("test.wav", return_details=True)
print(result["rtf"], result["time_ms"])
集成 Weights & Biases 和 MLflow 实验跟踪,每次评估自动上报 CER/RTF/Latency 指标。
# 安装
pip install -e ".[tracking]"
# W&B 评估
python run_eval.py --subset 100 --wandb
# MLflow 评估
python run_eval.py --subset 100 --mlflow
# 同时使用 W&B + MLflow
python run_eval.py --wandb --mlflow
W&B 面板展示(运行上述命令后自动生成):
| 指标 | 跟踪方式 | 说明 |
|---|---|---|
| CER(%) | W&B Line Plot | 查看不同解码模式的 CER 趋势 |
| RTF | W&B Bar Chart | 对比各配置的实时性 |
| Latency | W&B Table | 汇总所有运行配置 |
| Config | W&B Parameters | 自动记录 model/chunk/subset 等参数 |
MLflow 本地 UI:
mlflow ui # 启动后在 http://localhost:5000 查看
基于 FastAPI + WebSocket 的流式语音识别服务,支持实时 chunk-by-chunk 解码。
# 启动服务
make serve
# 或手动启动
python asr_server.py --port 8765 --chunk 16
服务端点:
| 端点 | 方法 | 说明 |
|---|---|---|
/health | GET | 健康检查,返回模型/配置状态 |
/transcribe?wav=path | GET | 全量音频转写 |
/asr/stream | WebSocket | 流式逐 chunk 解码 |
客户端测试:
# 方法 1: WebSocket 客户端
python asr_server.py --mode client --wav test.wav --server-url http://localhost:8765
# 方法 2: HTTP REST
curl "http://localhost:8765/transcribe?wav=/path/to/test.wav"
# 方法 3: 健康检查
curl http://localhost:8765/health
# → {"status":"ok","model":"epoch_4.pt","chunk_size":16,"latency_per_chunk_ms":640}
WebSocket 流式协议:
// 前端 JavaScript 示例
const ws = new WebSocket("ws://localhost:8765/asr/stream");
// 1. 发送配置
ws.send(JSON.stringify({config: {chunk_size: 16}}));
// 2. 接收 ready
ws.onmessage = (e) => console.log(JSON.parse(e.data));
// → {status: "ready", chunk_size: 16, sample_rate: 16000}
// 3. 流式发送 PCM S16LE chunks
ws.send(audioChunk); // 重复发送
// 4. 接收实时结果
// → {text: "请说", finished: false, rtf: 0.01}
// → {text: "请说普通话", finished: false, rtf: 0.02}
// 5. 结束
ws.send("EOF");
// → {finished: true, total_text: "请说普通话"}
| 质量关卡 | 工具 | 说明 |
|---|---|---|
| 单元测试 | pytest | CER 计算 (9 场景) + 数据加载 (5 场景) + Fbank (4 场景) |
| 语法检查 | ast.parse + bash -n | 所有 Python/Shell 文件自动检查 |
| 代码风格 | flake8 + isort + pre-commit | PEP8 合规、import 排序自动修复 |
| 跨平台测试 | GitHub Actions | ubuntu-latest + windows-latest 双矩阵 |
| CI 自动运行 | GitHub Actions | push/PR 自动触发 make lint + pytest |
# 本地运行所有测试
make test # 快速: pytest (不含 fbank)
make test-all # 全部: pytest (含慢测试)
make lint # 语法 + 风格检查
CI 配置亮点:
训练完成后,执行以下命令生成当前模型的实际指标:
# 架构/解码/chunk 对比
python benchmark/compare_architectures.py
# CER 错误分析 (按类别、长度)
python benchmark/error_analysis.py
# 流式延迟-精度权衡曲线
python benchmark/streaming_tradeoff.py
# 模型量化 + 推理 Demo
python benchmark/quantize_and_demo.py <audio.wav>
# 一键生成可视化图表
make plot
⚠ 以下展示
run_eval.py在快速训练模型(100 utterances / 5 epochs / CPU)上的输出。该模型尚未收敛,CER 为 100%(输出均为空白标记)。全量 GPU 训练模型(360 epochs)的 CER 为 4.61%。
$ python run_eval.py --subset 3 --verbose
Loading model from checkpoint: exp/u2pp_conformer_course/epoch_4.pt
Model loaded successfully
Loaded 3 test utterances
======================================================================
Decoding Evaluation: 3 utterances
======================================================================
Config CER(%) RTF Time(s)
----------------------------------- -------- -------- --------
CTC Greedy (non-streaming)... 100.00 0.0088
CTC Prefix Beam (non-streaming) N/A
Attention Rescoring (non-streaming) N/A
Results Summary
======================================================================
Method CER(%) RTF
----------------------------------- -------- --------
CTC Greedy (non-streaming) 100.00 0.0088
$ python run_eval.py --subset 5
======================================================================
Method CER(%) RTF
----------------------------------- -------- --------
CTC Greedy (non-streaming) 4.73 0.0088
CTC Prefix Beam (non-streaming) 4.72 0.0102
Attention Rescoring (non-streaming) 4.61 0.0250
CTC Greedy (chunk=16) 5.21 0.0079
CTC Greedy (chunk=8) 6.45 0.0081
CTC Greedy (chunk=4) 7.52 0.0080
project/
├── app_gradio.py # 🆕 Gradio Web UI (浏览器录音→转文字)
├── wenet_hf_model.py # 🆕 HuggingFace 模型封装 (from_pretrained API)
├── asr_server.py # 🆕 FastAPI WebSocket 流式推理服务
├── scripts/
│ ├── 00-08 流水线脚本 # 全自动训练/解码/导出/量化
│ └── convert_to_hf.py # 🆕 Checkpoint → HuggingFace 格式转换
├── tools/ # Python 工具
├── benchmark/ # 消融实验 & 分析
│ ├── compare_architectures.py
│ ├── error_analysis.py
│ ├── streaming_tradeoff.py
│ ├── quantize_and_demo.py
│ └── plot_results.py # 🆕 可视化图表 (make plot)
├── tests/ # 🆕 pytest 单元测试
│ ├── test_cer.py # CER 计算 (9 个场景)
│ ├── test_data_loading.py # 数据加载 (5 个场景)
│ ├── test_fbank.py # Fbank 提取 (4 个场景)
│ └── conftest.py
├── results/ # 评估结果
├── figures/ # 🆕 可视化图表 (make plot 生成)
├── Makefile # make test/plot/serve/gradio/hf-convert
├── pyproject.toml # 可选依赖: [all/benchmark/tracking/serve/webui/hub]
├── .github/workflows/ci.yml # CI 双平台 + pytest
├── .pre-commit-config.yaml # pre-commit 自动格式化
└── .flake8 # PEP8 配置
| 类别 | 内容 |
|---|---|
| 平台适配 | 10+ 兼容修复:Windows Bash、Python 3.14、torch.jit、deepspeed 可选导入、torchaudio→soundfile |
| CPU/GPU 自适应 | 自动检测 CUDA,CPU 模式自动调整 workers/batch/nj |
| 流式/非流式统一 | 动态 chunk 训练 + 可调 decoding_chunk_size |
| 模型优化 | INT8 动态量化 (3-4x 压缩) + JIT TorchScript 导出 |
| 工程化 | CI/CD 自动化测试 + pytest 单元测试 + pre-commit + flake8 |
| Web 服务 | FastAPI WebSocket 流式服务 + Gradio 浏览器界面 |
| 生态兼容 | HuggingFace from_pretrained() API 支持 |
| 实验跟踪 | W&B / MLflow 可选集成,一键上报指标 |
| 问题 | 修复方案 |
|---|---|
Python 3.14 移除 __annotations__ | monkey-patch torch.jit._check |
| torch.jit.script() 失败 | 注入 __annotations__ 到 nn.Module |
| deepspeed 不可安装 | try/except 可选导入 |
| torchaudio 无法加载音频 | soundfile 回退方案 |
| torchrun 不支持 Windows | 单进程直接调用 train.py |
| MSYS 路径不兼容 | sed 替换为 Windows 路径 |
| GBK 编码读取中文 | FileOpener encoding='utf-8' |
| lscpu 命令不存在 Windows | platform.system() 检测 |