SpeechRecognition/test/real/README.md

6.7 KiB
Raw Blame History

端到端真实测试套件

本目录包含完整的端到端真实测试,使用真实的视频/音频文件测试整个系统。


📁 文件结构

test/real/
├── README.md                 # 本文件(使用说明)
├── README_故障排查.md         # 故障排查指南
├── test_config.yaml          # 测试配置文件
├── test_requirements.txt     # 额外依赖
├── test_real_e2e.py          # 端到端测试主文件
└── check_e2e.py              # 环境诊断脚本

🚀 快速开始

1. 安装额外依赖

pip install pyyaml pytest-timeout

2. 检查测试环境

python test/real/check_e2e.py

3. 预下载模型(重要!)

# 首次运行前,手动加载模型避免测试卡住
python -c "from app.asr.asr_service import ASRService; ASRService()"

4. 运行测试

# 运行所有端到端测试
pytest test/real/ -v

# 只运行快速验证测试(不测试 ASR
pytest test/real/test_real_e2e.py::TestVideoFileValidation -v
pytest test/real/test_real_e2e.py::TestErrorHandling -v

# 运行单个 ASR 测试(带详细输出)
pytest test/real/test_real_e2e.py::TestASRRecognition::test_recognize_audio_file -v -s

📋 测试覆盖

测试类别(共 8 个测试类)

测试类 测试内容 预计时间
TestVideoFileValidation 视频文件验证 <1 秒
TestAudioFileValidation 音频文件验证 <1 秒
TestASRRecognition ASR 识别流程 30 秒 -5 分钟
TestSpeakerDiarization 说话人分离 30 秒 -5 分钟
TestVideoTranscoding 视频转码 1-3 分钟
TestPerformance 性能测试 1-5 分钟
TestErrorHandling 错误处理 <1 秒
TestAPIResponseFormat API 响应格式 <1 秒

测试用例(共 20+ 个)

文件验证

  • 视频文件存在性
  • 文件大小限制
  • 文件格式支持
  • 音频文件存在性

ASR 识别

  • 音频文件识别
  • 视频文件识别
  • 结果获取
  • 响应格式验证

说话人分离

  • 说话人数量验证
  • 时间戳精度检查

视频转码

  • 视频转码功能
  • 转码后 URL 获取

性能测试

  • ASR 处理时间
  • 实时处理率RTF

错误处理

  • 文件不存在错误
  • 缺少参数错误
  • 转码错误处理

⚙️ 配置说明

test_config.yaml

test_files:
  primary_video: "input/VID_20251104_085655_024.AVI"  # 主测试文件
  backup_videos:  # 备用文件
    - "input/Miehhuoxqih.AVI"
    - "input/VID_20251104_090655_025.AVI"
  audio_files:  # 音频测试文件
    - "input/VID_20251031_132320_019_mono.wav"

timeouts:
  asr_recognize: 600  # ASR 识别超时(秒)
  transcode: 300      # 转码超时

performance:
  max_asr_time: 120   # 最大 ASR 处理时间
  min_processing_speed: 0.5  # 最小处理速度(倍)

🏷️ 测试标记Markers

测试使用了 pytest markers 分类:

  • @pytest.mark.real - 端到端真实测试
  • @pytest.mark.slow - 慢速测试(>10 秒)
  • @pytest.mark.performance - 性能测试
  • @pytest.mark.timeout(N) - N 秒超时
  • @pytest.mark.requires_ffmpeg - 需要 ffmpeg
  • @pytest.mark.requires_gpu - 需要 GPU

运行特定测试

# 只运行快速测试
pytest test/real/ -v -m "not slow"

# 只运行性能测试
pytest test/real/ -v -m "performance"

# 跳过需要 GPU 的测试
pytest test/real/ -v -m "not requires_gpu"

# 只运行 ASR 识别测试
pytest test/real/test_real_e2e.py::TestASRRecognition -v

⚠️ 常见问题

测试卡住怎么办?

可能原因

  1. 首次下载模型10-30 分钟)
  2. 模型加载缓慢30 秒 -2 分钟)
  3. 文件过大处理时间长

解决方案

  1. 预下载模型:python -c "from app.asr.asr_service import ASRService; ASRService()"
  2. 使用更小的测试文件
  3. 安装 pytest-timeout 设置超时

详见:README_故障排查.md

CPU 占用低但测试无响应?

这是正常的,可能原因:

  • 等待模型下载(网络 IO
  • 等待模型加载(内存 IO
  • 音频/视频处理中

建议:首次运行耐心等待 10-30 分钟

如何跳过慢速测试?

pytest test/real/ -v -m "not slow"

📊 预期性能

处理时间参考CPU

文件类型 大小 处理时间
短音频 5MB 30-60 秒
长音频 20MB 2-5 分钟
短视频 50MB 1-3 分钟
长视频 200MB 5-15 分钟

处理时间参考GPU

文件类型 大小 处理时间
短音频 5MB 10-20 秒
长音频 20MB 30-60 秒
短视频 50MB 30-60 秒
长视频 200MB 2-5 分钟

🔧 依赖要求

必需依赖

pip install pyyaml>=6.0

可选依赖(推荐)

# 测试超时控制
pip install pytest-timeout>=2.2.0

# 性能测试
pip install pytest-benchmark>=4.0.0

# 代码覆盖率
pip install pytest-cov>=4.1.0

完整依赖列表

见:test_requirements.txt


📝 测试输出示例

============================================================ test session starts ============================================================
platform win32 -- Python 3.10.0, pytest-7.4.0, pluggy-1.3.0 -- D:\Python310\python.exe
cachedir: .pytest_cache
rootdir: D:\Userfile\Projects\AnzezxianxHazardInspectAI\Code\audio2
plugins: timeout-2.2.0
collected 20 items

test/real/test_real_e2e.py::TestVideoFileValidation::test_primary_video_file_exists PASSED                                              [  5%]
test/real/test_real_e2e.py::TestASRRecognition::test_recognize_audio_file
  使用测试音频VID_20251031_132320_019_mono.wav (5.23 MB)
  开始测试音频识别
  音频识别耗时45.32 秒
  ✓ 音频识别成功task_id: abc123...
PASSED                                                                                                              [ 10%]

======================================================== 20 passed in 180.52s (0:03:00) =========================================================

🆘 需要帮助?

  1. 查看 README_故障排查.md
  2. 运行诊断脚本:python test/real/check_e2e.py
  3. 查看详细输出:pytest test/real/ -v -s
  4. Ctrl+C 查看卡住位置的堆栈跟踪

📚 相关文档