File size: 1,636 Bytes
0021056
 
 
 
28ad598
 
0021056
28ad598
 
0021056
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28ad598
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
44
import os
from os.path import join as p_join
import pandas as pd
from tqdm import tqdm
from util import wget


url_metadata_s2s = "https://dl.fbaipublicfiles.com/seamless/data/seamless_align_nov2023_extension/seamless.dataset.metadata.public.enA-jaA.tsv.gz"
url_metadata_s2t = "https://dl.fbaipublicfiles.com/seamless/data/seamless.dataset.metadata.public.enA-jpn.withduration.tsv.gz"
cache_dir_root = "./download"


def get_metadata(url: str):
    cache_dir = p_join(cache_dir_root, "meta")
    filename = os.path.basename(url).replace(".gz", "")
    if not os.path.exists(filename):
        assert wget(url, cache_dir=cache_dir)
    df = pd.read_csv(p_join(cache_dir, filename), sep=r'[\t\s]', header=None)[[0, 2, 6, 9, 10, 11, 12]]
    df.columns = ["id", "url", "text_lid_score", "laser_score", "direction", "side", "line_no"]
    print(f"load metadata: {filename}, ({len(df)} rows)")
    return df


def get_audio(url: str, filename: str):
    cache_dir = p_join(cache_dir_root, "audio")
    if not os.path.exists(p_join(cache_dir, filename)):
        return wget(url, filename=filename, cache_dir=cache_dir)
    return False


def process_dataset(url_metadata):
    df_metadata = get_metadata(url_metadata)
    num_missing_files = 0
    for _, row in tqdm(df_metadata.iterrows(), total=len(df_metadata)):
        filename = f"{row['direction']}.{row['side']}.{os.path.basename(row['url'])}"
        num_missing_files += not get_audio(row['url'], filename)
    print(f"missing files: {num_missing_files}/{len(df_metadata)}")


if __name__ == '__main__':
    process_dataset(url_metadata_s2s)
    process_dataset(url_metadata_s2t)