balaramas's picture
Upload 16 files
af54c89
raw
history blame
No virus
1.3 kB
"""
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, stderr=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.split("\t")[2])
break
os.system("rm ./MUSTC_ROOT/en-hi/data/tst-COMMON/wav/test.wav")