Download preprocess/prepare_audio.py from tsinghua-ee/ELLSA2_data: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/datasets/tsinghua-ee/ELLSA2_data/resolve/main/preprocess/prepare_audio.py
- Command line
-
hf download hf://datasets/tsinghua-ee/ELLSA2_data/preprocess/prepare_audio.py
-
curl -L -o prepare_audio.py https://huggingface.co/datasets/tsinghua-ee/ELLSA2_data/resolve/main/preprocess/prepare_audio.py
1.53 kB
| """Create the 16 kHz mono WAVs referenced by a selected training manifest.""" | |
| import argparse | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| from preprocess.common import load_manifest | |
| from preprocess.resolve_paths import resolve_paths | |
| def prepare_audio(manifest, dataset_root): | |
| rows, _ = load_manifest(manifest) | |
| rows = resolve_paths(rows, dataset_root) | |
| paths = sorted({Path(row[key]) for row in rows | |
| for key in ('audio_file', 'audio_file_listen') if row.get(key)}) | |
| created = 0 | |
| for destination in paths: | |
| if destination.is_file(): | |
| continue | |
| assert destination.name.endswith('_16k.wav'), destination | |
| source = destination.with_name(destination.name.removesuffix('_16k.wav') + '.wav') | |
| assert source.is_file(), source | |
| subprocess.run(['ffmpeg', '-nostdin', '-v', 'error', '-n', '-i', str(source), | |
| '-vn', '-ac', '1', '-ar', '16000', '-c:a', 'pcm_s16le', str(destination)], check=True) | |
| created += 1 | |
| return created | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--input', default=str(Path(__file__).resolve().parents[1] / 'manifests/train_selected81.json')) | |
| parser.add_argument('--dataset-root', required=True) | |
| args = parser.parse_args() | |
| print(f'Created {prepare_audio(args.input, args.dataset_root)} WAVs; existing files were retained.') | |
| if __name__ == '__main__': | |
| main() | |