Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,19 @@ import sys
|
|
10 |
import os
|
11 |
import subprocess
|
12 |
from pydub import AudioSegment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def install_fairseq():
|
15 |
try:
|
@@ -44,20 +57,29 @@ def run_my_code(input_text, language):
|
|
44 |
audio=convert_audio_to_16k_wav(input_text)
|
45 |
hi_wav = audio
|
46 |
|
|
|
47 |
data_root=""
|
48 |
model_checkpoint=""
|
49 |
d_r=""
|
|
|
50 |
|
51 |
if(language=="Hindi"):
|
52 |
model_checkpoint = "./models/hindi_model.pt"
|
53 |
data_root="./MUSTC_ROOT_hindi/en-hi/"
|
54 |
d_r="MUSTC_ROOT_hindi/"
|
|
|
55 |
if(language=="French"):
|
56 |
model_checkpoint = "./models/french_model.pt"
|
57 |
data_root="./MUSTC_ROOT_french/en-fr/"
|
58 |
d_r="MUSTC_ROOT_french/"
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
os.system(f"cp {hi_wav} {data_root}data/tst-COMMON/wav/test.wav")
|
63 |
|
|
|
10 |
import os
|
11 |
import subprocess
|
12 |
from pydub import AudioSegment
|
13 |
+
import yaml
|
14 |
+
import wave
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
def get_wav_duration(file_path):
|
19 |
+
with wave.open(file_path, 'rb') as wav_file:
|
20 |
+
frames = wav_file.getnframes()
|
21 |
+
rate = wav_file.getframerate()
|
22 |
+
duration = frames / float(rate)
|
23 |
+
return duration
|
24 |
+
|
25 |
+
|
26 |
|
27 |
def install_fairseq():
|
28 |
try:
|
|
|
57 |
audio=convert_audio_to_16k_wav(input_text)
|
58 |
hi_wav = audio
|
59 |
|
60 |
+
|
61 |
data_root=""
|
62 |
model_checkpoint=""
|
63 |
d_r=""
|
64 |
+
yam=""
|
65 |
|
66 |
if(language=="Hindi"):
|
67 |
model_checkpoint = "./models/hindi_model.pt"
|
68 |
data_root="./MUSTC_ROOT_hindi/en-hi/"
|
69 |
d_r="MUSTC_ROOT_hindi/"
|
70 |
+
yam="./MUSTC_ROOT_hindi/en-hi/data/tst-COMMON/txt/tst-COMMON.yaml"
|
71 |
if(language=="French"):
|
72 |
model_checkpoint = "./models/french_model.pt"
|
73 |
data_root="./MUSTC_ROOT_french/en-fr/"
|
74 |
d_r="MUSTC_ROOT_french/"
|
75 |
+
yam="./MUSTC_ROOT_french/en-fr/data/tst-COMMON/txt/tst-COMMON.yaml"
|
76 |
+
|
77 |
+
#code to change the duration of the yaml file accordign to the audio input
|
78 |
+
with open(yam, 'r') as yaml_file:
|
79 |
+
data = yaml.safe_load(yaml_file)
|
80 |
+
data[0]['duration']=get_wav_duration(hi_wav)
|
81 |
+
with open(yam, 'w') as yaml_file:
|
82 |
+
yaml.dump(data, yaml_file)
|
83 |
|
84 |
os.system(f"cp {hi_wav} {data_root}data/tst-COMMON/wav/test.wav")
|
85 |
|