File size: 1,948 Bytes
7375975
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from tqdm import tqdm
import glob
import numpy as np
import random
import json
import torch

import numpy as np


audio_dir = '/apdcephfs_nj7/share_303172353/ggyzhang/projects/data/LRS3/audio'
mouth_dir = '/apdcephfs_nj7/share_303172353/ggyzhang/projects/data/LRS3_preprocess/lrs3/lrs3_video_seg16s'
token_dir = '/apdcephfs_nj7/share_303172353/ggyzhang/projects/data/LRS3_speech_token/audio'
audio_map = {}
mouth_map = {}
token_map = {}
data = []
 
wavs = glob.glob(f'{audio_dir}/**/*.wav',recursive=True)
print(len(wavs))
for wav_fp in tqdm(wavs):
    tmp_wav_fp = wav_fp.split('.')[0]
    fid = '/'.join(tmp_wav_fp.split('/')[-3:])
    audio_map[fid] = wav_fp


tokens = glob.glob(f'{token_dir}/**/*.npy',recursive=True)
print(len(tokens))
for token_fp in tqdm(tokens):
    tmp_token_fp = token_fp.split('.')[0]
    fid = '/'.join(tmp_token_fp.split('/')[-3:])
    token_map[fid] = token_fp

mouths = glob.glob(f'{mouth_dir}/**/*.mp4',recursive=True)
print(len(mouths))
for mouth_fp in tqdm(mouths):
    tmp_mouth_fp = mouth_fp.split('.')[0]
    fid = '/'.join(tmp_mouth_fp.split('/')[-3:])
    audio_fn = audio_map.get(fid,None)
    unit_fn = token_map.get(fid,None)
    if audio_fn is None or unit_fn is None:
        continue
    v_frames = len(np.load(unit_fn))//2
    item = {'fid':fid,'wav_fn':audio_fn,'video_fn':mouth_fp,'unit_fn':unit_fn,'v_frames':v_frames}
    data.append(item)

print(len(data))

random.shuffle(data)
print(len(data))
with open('/apdcephfs_nj7/share_303172353/ggyzhang/projects/v2s/data/lrs3/train_data.json', 'w') as json_file:
    json.dump(data[:-80], json_file, indent=4)

with open('/apdcephfs_nj7/share_303172353/ggyzhang/projects/v2s/data/lrs3/valid_data.json', 'w') as json_file:
    json.dump(data[-80:-40], json_file, indent=4)

with open('/apdcephfs_nj7/share_303172353/ggyzhang/projects/v2s/data/lrs3/test_data.json', 'w') as json_file:
    json.dump(data[-40:], json_file, indent=4)

exit(0)