Spaces:
Running
Running
Download normalizer/voice_code_data.py from Banafo/KrokoMusci-OpenASR: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/Banafo/KrokoMusci-OpenASR/resolve/main/normalizer/voice_code_data.py
- Command line
-
hf download hf://spaces/Banafo/KrokoMusci-OpenASR/normalizer/voice_code_data.py
-
curl -L -o voice_code_data.py https://huggingface.co/spaces/Banafo/KrokoMusci-OpenASR/resolve/main/normalizer/voice_code_data.py
1.93 kB
| """Load the pinned VoiceCodeBench recordings using the Open ASR protocol.""" | |
| from pathlib import Path, PurePosixPath | |
| DATASET_ID = "besimple-ai/voice-code-bench" | |
| DATASET_REVISION = "bef2824f83ef1c796f3e79731a3b0741708730df" | |
| RECORDINGS = 300 | |
| MANIFEST_KEYS = ("audio_id", "voice_code_bench_revision") | |
| MAX_RECORDING_SECONDS = 130 | |
| MAX_CHUNK_SECONDS = 30 | |
| def load_data(args): | |
| from datasets import Audio, load_dataset | |
| from huggingface_hub import snapshot_download | |
| if (args.dataset != "default" or args.split != "test" or args.streaming | |
| or args.dataset_revision != DATASET_REVISION or args.max_eval_samples != -1): | |
| raise ValueError("Expected the complete pinned VoiceCodeBench default test split") | |
| # Upstream protocol: open_asr_leaderboard@4b87692/normalizer/voice_code_bench.py. | |
| root = Path(snapshot_download( | |
| DATASET_ID, repo_type="dataset", revision=DATASET_REVISION, | |
| allow_patterns=["data/metadata.jsonl", "data/audio/*.wav"], | |
| )) / "data" | |
| dataset = load_dataset("json", data_files={"test": str(root / "metadata.jsonl")}, split="test") | |
| ids = dataset["audio_id"] | |
| if len(ids) != RECORDINGS or len(set(ids)) != RECORDINGS or any(not value for value in ids): | |
| raise ValueError("VoiceCodeBench metadata does not contain 300 unique audio IDs") | |
| def attach_audio(sample): | |
| relative = PurePosixPath(sample["file_name"]) | |
| if relative.parent != PurePosixPath("audio") or relative.suffix != ".wav": | |
| raise ValueError("Unexpected VoiceCodeBench audio path") | |
| audio = root / relative | |
| if not audio.is_file(): | |
| raise FileNotFoundError(audio) | |
| return {"audio": str(audio), "id": sample["audio_id"], "text": sample["transcripts"]["acoustic"], | |
| "voice_code_bench_revision": DATASET_REVISION} | |
| return dataset.map(attach_audio, load_from_cache_file=False).cast_column("audio", Audio()) | |