File size: 1,845 Bytes
d121da6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os

def process_manifest(input_path):
    if not os.path.exists(input_path):
        print(f"Warning: File not found {input_path}")
        return

    print(f"Processing {input_path} in-place")
    
    processed_count = 0
    updated_lines = []
    
    # 1. Read and process all lines
    with open(input_path, 'r', encoding='utf-8') as f_in:
        for line in f_in:
            line = line.strip()
            if not line:
                continue
                
            data = json.loads(line)
            
            if 'duration' not in data:
                print(f"Warning: 'duration' missing in a record, skipping: {data}")
                updated_lines.append(line + '\n')
                continue
                
            duration = float(data['duration'])
            
            if 'offset' not in data:
                data['offset'] = 0.0
                
            if 'sou_time' not in data:
                data['sou_time'] = 0.0
                
            if 'eou_time' not in data:
                data['eou_time'] = duration
                
            updated_lines.append(json.dumps(data, ensure_ascii=False) + '\n')
            processed_count += 1
            
    # 2. Write back to the same file
    with open(input_path, 'w', encoding='utf-8') as f_out:
        f_out.writelines(updated_lines)
            
    print(f"Successfully processed {processed_count} records in {input_path}.")

if __name__ == '__main__':
    files_to_process = [
        r"data\common_voice_11_0\ja\train_tarred_1bk\tarred_audio_manifest.json",
        r"data\common_voice_11_0\ja\validation\validation_common_voice_11_0_manifest.json",
        r"data\common_voice_11_0\ja\test\test_common_voice_11_0_manifest.json"
    ]
    
    for file_path in files_to_process:
        process_manifest(file_path)