一个完整的语音处理系统,集成了语音转录、说话人分离和结果对齐功能,提供一键式处理流水线和交互式可视化界面。
translate_node_test_v1/ ├── 0.comprehensive_pipeline.py # 🌟 综合处理流水线 (推荐) ├── 0.env_check.py # 环境检测脚本 ├── 1.faster_whisper_test.py # 语音转录脚本 ├── 2.audio_test.py # 说话人分离脚本 ├── 3.alignment_script.py # 对齐脚本 ├── audio_text_viewer.html # 交互式预览器 ├── result/ # 结果目录 │ ├── transcription/ # 转录结果 │ ├── diarization/ # 说话人分离结果 │ └── alignment/ # 对齐结果 ├── audio/ # 音频文件目录 ├── requirements.txt # Python依赖 ├── environment.yml # Conda环境 └── README.md # 使用说明
# 1. 运行综合流水线
python 0.comprehensive_pipeline.py
# 2. 启动HTTP服务器
python -m http.server 8080
# 3. 打开浏览器
# http://localhost:8080/audio_text_viewer.html
流程说明:
result/ 目录和根目录适合需要自定义参数或调试的场景:
# 1. 环境检测
python 0.env_check.py
# 2. 语音转录
python 1.faster_whisper_test.py
# 3. 说话人分离
python 2.audio_test.py
# 4. 结果对齐
python 3.alignment_script.py
# 创建环境
conda create -p ./translate python=3.10 -y
conda activate ./translate
# 安装核心依赖
pip install faster-whisper
pip install pyannote.audio
# 可选:系统监控
conda install psutil -y
如果遇到CPU版本的PyTorch问题:
# 安装GPU版PyTorch和torchaudio
pip install torchaudio==2.7.1 --index-url https://download.pytorch.org/whl/cu128 --force-reinstall
# 重新安装pyannote.audio (避免依赖冲突)
pip install pyannote.audio --no-deps
# 在项目根目录启动HTTP服务器
python -m http.server 8080
# 浏览器访问
http://localhost:8080/audio_text_viewer.html
result/alignment/ 和根目录的对齐文件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# 检查环境配置
python 0.env_check.py
# 查看检测报告
ls result/env_check/
# 支持的格式:wav, mp3, flac, m4a, ogg, aac
cp your_audio.wav audio/
# 运行综合流水线
python 0.comprehensive_pipeline.py
# 按提示选择音频文件
# 等待处理完成 (根据音频长度5-30分钟)
# 启动预览服务器
python -m http.server 8080
# 浏览器打开
# http://localhost:8080/audio_text_viewer.html
# 选择生成的文件并开始使用
result/transcription/, result/diarization/, result/alignment/aligned_YYYYMMDD_HHMMSS.json 和 .txt{
"metadata": {
"transcription_source": {
"model": "large-v2",
"language": "zh",
"duration": 180.5,
"performance": { "speed_factor": 150.2 }
},
"diarization_source": {
"model": "pyannote/speaker-diarization-3.0",
"total_speakers": 2
},
"alignment_timestamp": "2025-01-07T15:30:45",
"overlap_threshold": 0.5
},
"alignment_stats": {
"total_segments": 127,
"aligned_segments": 117,
"unaligned_segments": 10,
"speaker_distribution": {
"SPEAKER_00": 65,
"SPEAKER_01": 52
}
},
"aligned_segments": [
{
"id": 0,
"start": 0.0,
"end": 1.76,
"text": "大家好,欢迎收听今天的节目。",
"speaker": "SPEAKER_01",
"confidence": 0.983,
"words": [
{"word": "大家好", "start": 0.0, "end": 0.5, "probability": 0.99}
]
}
]
}
================================================================================ 语音处理综合结果 ================================================================================ 总片段数: 127 成功对齐: 117 对齐率: 92.1% 说话人分布: SPEAKER_00: 65 个片段 SPEAKER_01: 52 个片段 [SPEAKER_01] [0.00s - 1.76s] 大家好,欢迎收听今天的节目。 [1.76s - 4.23s] 今天我们将讨论人工智能的发展... [SPEAKER_00] [4.23s - 6.85s] 是的,这确实是一个很有趣的话题。
1. CUDA显存不足
# 选择更小的模型
# 在脚本中修改: model_size = "base" # 代替 "large-v2"
# 清理GPU缓存
python -c "import torch; torch.cuda.empty_cache()"
2. 网络连接问题
# 设置Hugging Face镜像
export HF_ENDPOINT=https://hf-mirror.com
# 或使用代理
export https_proxy=http://127.0.0.1:7890
3. 文件扫描失败
# 检查文件权限
chmod 644 *.json
chmod 644 audio/*
# 手动放置对齐文件到根目录
cp result/alignment/aligned_*.json ./
4. 音频格式不支持
# 使用ffmpeg转换
ffmpeg -i input.mp4 -acodec pcm_s16le -ar 16000 audio/output.wav
# 开启详细输出
export CUDA_LAUNCH_BLOCKING=1
python 0.comprehensive_pipeline.py
# 浏览器调试 (F12 → Console)
# 查看文件扫描和加载日志
# 设置GPU
export CUDA_VISIBLE_DEVICES=0
# 优化内存使用
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
# 对齐脚本支持参数
python 3.alignment_script.py \
--transcription result/transcription/trans_xxx.json \
--diarization result/diarization/diar_xxx.json \
--output my_result \
--threshold 0.6
在综合脚本中可以修改:
model_size: 模型大小 (tiny/base/small/medium/large-v2)overlap_threshold: 对齐阈值 (0.0-1.0)chunk_length: 音频分块长度beam_size: 搜索束大小# 处理多个音频文件
for audio in audio/*.wav; do
echo "Processing $audio"
python 1.faster_whisper_test.py
# 自动选择当前文件...
done
| 步骤 | 处理时间 | 倍率 | 显存占用 |
|---|---|---|---|
| 转录 | 12秒 | 150x | 4.2GB |
| 说话人分离 | 45秒 | 40x | 2.8GB |
| 对齐 | 2秒 | - | 0.1GB |
| 总计 | 59秒 | 30.5x | 4.2GB |
欢迎提交Issue和Pull Request!
git clone https://github.com/yourname/translate_node_test_v1.git
cd translate_node_test_v1
conda activate ./translate
python 0.env_check.py
MIT License - 详见 LICENSE 文件
遇到问题请:
result/env_check/)版本: v2.0.0
更新时间: 2025-01-07
核心特性: 一键式流水线 + 交互式预览器