-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesp2txt.py
24 lines (22 loc) · 947 Bytes
/
esp2txt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from glob import glob
from tqdm import tqdm
import os
from os.path import basename
import json
def convert_to_txt(decode_folder, output_folder):
os.makedirs(output_folder, exist_ok=True)
folders = sorted(glob(os.path.join(decode_folder, '*')))
for folder in tqdm(folders):
if not os.path.isdir(folder):
continue
result_file = os.path.join(folder, 'result.json')
with open(result_file, encoding='utf-8') as f:
data = json.load(f)
transcript = data['utts'][list(data['utts'].keys())[0]]['output'][0]['rec_text']
transcript = transcript.replace('<eos>', '').replace('▁', ' ').strip()
output_file = os.path.join(output_folder, basename(folder)+'.txt')
with open(output_file, 'w', encoding='utf-8') as f:
f.write(transcript)
return
if __name__ == '__main__':
convert_to_txt('decode', 'output-transformer-libri')