File size: 1,256 Bytes
4f94afb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Script to translate given single english audio file to corresponding hindi text

Usage : python s2t_en2hi.py <audio_file_path> <averaged_checkpoints_file_path>
"""

import sys
import os
import subprocess

# TODO better argument handling
hi_wav = sys.argv[1]
en2hi_model_checkpoint = sys.argv[2]

os.system(f"cp {hi_wav} ./MUSTC_ROOT/en-hi/data/tst-COMMON/wav/test.wav")

print("------Starting data prepration...")
subprocess.run(["python", "prep_mustc_data_hindi_single.py", "--data-root", "MUSTC_ROOT/", "--task", "st", "--vocab-type", "unigram", "--vocab-size", "8000"], stdout=subprocess.DEVNULL)

print("------Performing translation...")
translation_result = subprocess.run(["fairseq-generate", "./MUSTC_ROOT/en-hi/", "--config-yaml", "config_st.yaml", "--gen-subset", "tst-COMMON_st", "--task", "speech_to_text", "--path", sys.argv[2], "--max-tokens", "50000", "--beam", "5", "--scoring", "sacrebleu"], capture_output=True, text=True)
translation_result_text = translation_result.stdout
print(translation_result.std)
lines = translation_result_text.split("\n")

print("\n\n------Translation results are:")
for i in lines:
    if (i.startswith("D-0")):
        print(i)
        break

os.system("rm ./MUSTC_ROOT/en-hi/data/tst-COMMON/wav/test.wav")