video-vec2wav2-tokenizer
收藏资源简介:
该数据集是由 video-vec2wav2-tokenizer 工具处理视频后生成的,专为语音识别(ASR)和文本转语音(TTS)模型的训练而设计。数据处理流程包括:从多种格式的视频文件中提取音频,将其转换为 16 kHz 单声道 PCM WAV 格式;使用 faster-whisper 模型进行自动语音识别,生成带有时序信息的转录文本;根据单词级时间戳将长音频切割成短片段(默认长度 1-20 秒)。数据集的核心构成是音频片段文件及其对应的转录文本。它提供多种结构化元数据文件:`metadata.csv` 包含音频文件名和文本;`dataset.jsonl` 以 JSON 行格式存储音频路径、文本和时长;`tts_metadata.csv` 额外包含说话人标识符,适用于 TTS 任务。此外,还生成统计报告 `report.json`,汇总总时长、平均时长和语言分布。可选地,可以生成流式特征文件(`train.bin`, `train.dat`),其中包含浮点音频样本和梅尔频谱图特征,便于直接用于模型训练。该工具支持大规模处理,能够高效地将海量视频资源转化为标准化、可用于训练 AI 语音模型的数据集。
This dataset is generated by processing videos with the `video-vec2wav2-tokenizer` tool, and is specifically designed for training Automatic Speech Recognition (ASR) and Text-to-Speech (TTS) models. The data processing workflow includes: extracting audio from video files in various formats and converting it to 16 kHz mono PCM WAV format; performing automatic speech recognition using the faster-whisper model to generate transcribed text with timing information; splitting long audio into short segments (default length: 1–20 seconds) based on word-level timestamps. The core components of the dataset are audio segment files and their corresponding transcribed texts. It provides multiple structured metadata files: `metadata.csv` contains audio filenames and their corresponding texts; `dataset.jsonl` stores audio paths, texts, and durations in JSON Lines format; `tts_metadata.csv` additionally includes speaker identifiers, which is suitable for TTS tasks. In addition, a statistical report `report.json` is generated, summarizing total duration, average duration, and language distribution. Optionally, streaming feature files (`train.bin`, `train.dat`) can be generated, which contain floating-point audio samples and mel-spectrogram features for direct use in model training. This tool supports large-scale processing, and can efficiently convert massive video resources into standardized datasets that can be used for training AI speech models.
数据集概述
数据集名称: video-vec2wav2-tokenizer
数据集地址: https://huggingface.co/datasets/k9cli/video-vec2wav2-tokenizer
数据集用途: 本数据集是一个生产级管道,旨在将视频文件夹转换为干净的AI训练数据集,适用于语音识别(ASR)和文本转语音(TTS)。
核心功能
该管道的处理流程为: 视频 → 音频(16 kHz 单声道 PCM) → Whisper 转录文本 → 音频片段 → 数据集文件(metadata.csv / dataset.jsonl / tts_metadata.csv / report.json)
主要功能模块包括:
- 视频处理: 递归扫描
mp4 / mkv / avi / mov / webm格式视频,通过 FFmpeg 提取音频为单声道、16 kHz、16-bit PCM WAV 格式。 - 语音识别: 使用 faster-whisper 进行语音转文本,支持 CPU 和 CUDA,自动语言检测,提供词级时间戳。
- 音频分割: 根据转录时间戳将音频切割为独立片段,存放于
dataset/audio/目录(如000001.wav)。 - 数据集生成: 生成多种数据集文件,包括
metadata.csv、dataset.jsonl和tts_metadata.csv。 - 特征提取 (可选): 流式生成
features/train.bin和features/train.dat,包含 float32 音频样本、梅尔频谱图、时长和采样率信息。 - 统计报告: 生成
report.json,包含总数、总时长和语言分布统计。 - 模型训练: 提供
train_wav2vec2.py脚本,支持 HuggingFace Wav2Vec2 CTC 模型训练,具备断点续训、多GPU、混合精度和检查点功能。 - 性能优化: 支持多进程、批处理、tqdm 进度条和内存高效的流式处理,可处理超过 1 TB 的源媒体。
安装要求
- Python 版本: 3.11+
- 依赖: 需要 FFmpeg 二进制文件,并确保其在系统 PATH 中。
- 安装方式: 通过
pip install -r requirements.txt和pip install -e .安装,可选训练扩展pip install -e ".[train]"。
快速开始
-
将视频放入
input/videos/文件夹(支持任意嵌套)。 -
运行完整管道:
video2dataset process ./input/videos --extract-features -
输出目录结构示例:
dataset/ ├── audio/ │ ├── 000001.wav │ ├── 000002.wav │ └── ... ├── metadata.csv # 000001.wav|Hello world ├── dataset.jsonl # {"audio":"audio/000001.wav","text":"Hello world","duration":2.5} ├── tts_metadata.csv # 000001.wav|speaker_001|Hello world └── report.json features/ ├── train.bin └── train.dat
命令行接口
video2dataset process:视频 → 完整数据集video2dataset transcribe:WAV 音频 → 转录 JSONL 文件video2dataset segment:WAV 音频 + 转录文件 → 音频片段video2dataset features:数据集 → 特征文件 (train.bin / train.dat)video2dataset train:数据集 → 微调 Wav2Vec2 CTC 模型
全局标志(可覆盖 config.yaml):--config, --output-dir, --device {auto,cpu,cuda}, --whisper-model, --language, -v/--verbose。
多GPU训练示例:torchrun --nproc_per_node=4 -m video_vec2wav2_tokenizer.training.train_wav2vec2 --dataset-dir dataset --output-dir dataset/checkpoints
配置文件 (config.yaml)
yaml model_name: facebook/wav2vec2-base-960h # 训练模型 whisper_model: large-v3 # ASR 模型 language: null # null = 自动检测 device: auto # auto | cpu | cuda sample_rate: 16000 channels: 1 min_segment_length: 1.0 max_segment_length: 20.0 default_speaker: speaker_001 speaker_mode: fixed # fixed | per_video | per_file output_dir: dataset features_dir: features num_workers: 4 batch_size: 16
speaker_mode 控制 TTS 说话人识别:固定说话人、每个视频一个说话人或每个片段一个说话人。
架构与设计
项目结构如下:
video-vec2wav2-tokenizer/ ├── config.yaml ├── requirements.txt ├── pyproject.toml ├── README.md ├── input/videos/ └── video_vec2wav2_tokenizer/ ├── cli/ # argparse 命令接口 ├── audio/ # FFmpeg 提取 + WAV 加载/重采样 ├── transcription/ # faster-whisper 封装 ├── segmentation/ # 时间戳归一化 + 片段裁剪 ├── features/ # 流式 bin/dat 特征存储 + 梅尔频谱图 ├── training/ # Wav2Vec2 CTC 训练器 ├── utils/ # 配置、日志、数据模型、IO ├── configs/ # 默认配置 ├── tests/ # pytest 测试 ├── pipeline.py # 端到端编排 ├── dataset_builder.py / statistics.py └── main.py # python main.py 入口点
设计特性:
- 延迟加载:
faster-whisper,torch和transformers仅在需要时导入,核心库和测试保持轻量。 - 流式处理: 转录使用 whisper 的生成器;片段和清单按源视频生成;特征存储逐个片段追加,内存使用与语料库大小无关。
- 优雅降级: 当
soundfile/librosa未安装时,WAV IO 和梅尔频谱图回退到标准库 + NumPy。 - 容错: 失败的视频会被记录并跳过,运行继续。
输出格式
| 文件 | 格式 |
|---|---|
metadata.csv |
`000001.wav |
dataset.jsonl |
{"audio":"audio/000001.wav","text":"Hello world","duration":2.5} |
tts_metadata.csv |
`000001.wav |
report.json |
总数、总/平均时长、语言分布 |
features/train.bin |
平面小端 float32:每个片段的音频样本 + 梅尔 |
features/train.dat |
JSONL 索引(偏移量、形状、时长、采样率) |
测试
- 安装开发依赖:
pip install -e ".[dev]" - 运行测试:
pytest或pytest --cov=video_vec2wav2_tokenizer - 默认测试套件仅需
numpy、pyyaml和pytest,无需 FFmpeg、whisper 或 torch。
许可证
MIT 许可证。




