Spaces:
No application file
No application file
File size: 1,344 Bytes
1b6bcbc |
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 |
import os
import json
import click
@click.command()
@click.option('--source_file', prompt='source file', help='source file xxx.list')
@click.option('--target_file', prompt='target file', help='target file xxx.json')
def convert_list_to_json(source_file, target_file):
with open(source_file, 'r', encoding="utf-8") as source:
g_data_list = source.readlines()
with open(target_file, 'w', encoding="utf-8") as target:
output = []
for _ in g_data_list:
data = _.split('|')
if (len(data) == 4):
wav_path, speaker_name, language, text= data
output.append(
json.dumps(
{
'wav_path':wav_path,
'speaker_name':speaker_name,
'language':language,
'text':text.strip()
},
ensure_ascii = False
) +'\n'
)
else:
print("error line:", data)
for line in output:
target.write(line)
print("Target file has been saved:", target_file)
if __name__ == "__main__":
print(r"convert list to json format : {wav_path:'hello.wav', text:'hello', ...}")
convert_list_to_json() |