File size: 1,928 Bytes
9ef47e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""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())