yeyupiaoling/VoiceprintRecognition-Pytorch
This project uses a variety of advanced voiceprint recognition models such as EcapaTdnn, ResNetSE, ERes2Net, CAM++, etc. It is not excluded that more models will be supported in the future. At the same time, this project also supports MelSpectrogram, Spectrogram data preprocessing methods
VoiceprintRecognition-Pytorch
一个基于 PyTorch 的 声纹识别 / 说话人验证 工具包。它让你能够训练、评估和部署模型,从音频片段中识别说话者。
功能特点
- 实现了一系列最先进的声纹识别骨干网络 (Ecapa-Tdnn, TDNN, Res2Net, ResNetSE, ERes2Net, CAM++)。
- 提供多种池化层 (ASP, SAP, TSP, TAP, TSTP) 和一系列损失函数 (AAMLoss/ArcFace, SphereFace2, AMLoss, ARMLoss, CELoss 等)。
- 支持多种前端:经典声学特征 (MelSpectrogram, Spectrogram, MFCC, Fbank) 以及来自 Hugging-Face 的预训练语音模型 (wav2vec2, wavLM 等)。
- 包含数据增强工具 (速度、音量、噪声、混响、SpecAugment)。
- 提供数据准备、特征提取、模型训练、评估和推理 API 的脚本。
- 附带开箱即用的网页和微信小程序演示,用于声纹比对、说话人识别和说话人分离。
关键特性
| 特性 | 详细信息 |
|---|---|
| 骨干网络 | EcapaTdnn, TDNN, Res2Net, ResNetSE, ERes2Net, CAM++ |
| 池化层 | AttentiveStatsPool, SelfAttentivePooling, TemporalStatisticsPooling, TemporalAveragePooling, TemporalStatsPool |
| 损失函数 | AAMLoss (ArcFace), SphereFace2, AMLoss, ARMLoss, CELoss, SubCenterLoss, TripletAngularMarginLoss |
| 前端 | MelSpectrogram, Spectrogram, MFCC, Fbank, wav2vec2.0, wavLM |
| 数据增强 | 速度扰动, 音量增益, 加性噪声, 混响, SpecAugment |
| 支持数据集 | CN-Celeb, VoxCeleb1/2 (以及任何用户提供的列表) |
| 评估指标 | EER, MinDCF |
| 演示 | 用于声纹比对 / 识别 / 分离的在线网页和微信小程序 |
安装
# PyTorch GPU (CUDA 11.8) – 如有需要请调整版本
conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=11.8 -c pytorch -c nvidia
# 安装项目使用的辅助库
python -m pip install mvector -U -i https://pypi.tuna.tsinghua.edu.cn/simple
# 克隆并安装包 (建议使用可编辑安装)
git clone https://github.com/yeyupiaoling/VoiceprintRecognition-Pytorch.git
cd VoiceprintRecognition-Pytorch
pip install .
快速开始 (典型工作流程)
- 准备数据 – 下载说话人数据集 (例如 CN-Celeb 或 VoxCeleb),放置在
dataset/下,并运行:python create_data.py # 创建训练/注册/测试列表文件 - (可选) 提取特征 – 加快训练速度:
将配置中的列表路径更新为python extract_features.py --configs=configs/cam++.yml --save_dir=dataset/features*_features.txt文件。 - 训练模型 – 选择一个配置 (例如
configs/ecapa_tdnn.yml) 并运行:
日志会写入CUDA_VISIBLE_DEVICES=0 python train.py # 单 GPU # 或多 GPU CUDA_VISIBLE_DEVICES=0,1 torchrun --standalone --nnodes=1 --nproc_per_node=2 train.pylog/并可以使用 VisualDL 可视化:visualdl --logdir=log --host 0.0.0.0 - 评估 – 如果配置中设置
do_eval: True,相同的train.py脚本会运行评估,报告 EER 和 MinDCF。 - 推理 – 训练后,使用提供的推理 API (参见仓库中的
inference.py) 来嵌入新的语音片段并与已注册的说话人进行比对。
演示与在线服务
- 声纹比对 – https://tools.yeyupiaoling.cn/speech/voiceprint_compare
- 说话人识别 – https://tools.yeyupiaoling.cn/speech/voiceprint_recognition
- 说话人分离 – https://tools.yeyupiaoling.cn/speech/speaker_diarization
- README 中的二维码链接至提供相同功能的微信小程序。
许可证
本仓库在 MIT 许可证下发布 (参见 README 中的 LICENSE 徽章)。
相关
- 项目
- 项目
- 项目
- 项目