DHEIVER commited on
Commit
bfd6986
1 Parent(s): 69f50e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py CHANGED
@@ -47,6 +47,68 @@ examples = [
47
  # Use only Portuguese as a language choice
48
  language_choices = ["Portuguese"]
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  demo = gr.Blocks(css=css)
51
 
52
  with demo:
 
47
  # Use only Portuguese as a language choice
48
  language_choices = ["Portuguese"]
49
 
50
+ def update_model_dropdown(language: str):
51
+ if language in language_to_models:
52
+ choices = language_to_models[language]
53
+ return gr.Dropdown(
54
+ choices=choices,
55
+ value=choices[0],
56
+ interactive=True,
57
+ )
58
+
59
+ raise ValueError(f"Unsupported language: {language}")
60
+
61
+
62
+ def build_html_output(s: str, style: str = "result_item_success"):
63
+ return f"""
64
+ <div class='result'>
65
+ <div class='result_item {style}'>
66
+ {s}
67
+ </div>
68
+ </div>
69
+ """
70
+
71
+
72
+ def process(language: str, repo_id: str, text: str, sid: str, speed: float):
73
+ logging.info(f"Input text: {text}. sid: {sid}, speed: {speed}")
74
+ sid = int(sid)
75
+ tts = get_pretrained_model(repo_id, speed)
76
+
77
+ start = time.time()
78
+ audio = tts.generate(text, sid=sid)
79
+ end = time.time()
80
+
81
+ if len(audio.samples) == 0:
82
+ raise ValueError(
83
+ "Error in generating audios. Please read previous error messages."
84
+ )
85
+
86
+ duration = len(audio.samples) / audio.sample_rate
87
+
88
+ elapsed_seconds = end - start
89
+ rtf = elapsed_seconds / duration
90
+
91
+ info = f"""
92
+ Wave duration : {duration:.3f} s <br/>
93
+ Processing time: {elapsed_seconds:.3f} s <br/>
94
+ RTF: {elapsed_seconds:.3f}/{duration:.3f} = {rtf:.3f} <br/>
95
+ """
96
+
97
+ logging.info(info)
98
+ logging.info(f"\nrepo_id: {repo_id}\ntext: {text}\nsid: {sid}\nspeed: {speed}")
99
+
100
+ filename = str(uuid.uuid4())
101
+ filename = f"{filename}.wav"
102
+ sf.write(
103
+ filename,
104
+ audio.samples,
105
+ samplerate=audio.sample_rate,
106
+ subtype="PCM_16",
107
+ )
108
+
109
+ return filename, build_html_output(info)
110
+
111
+
112
  demo = gr.Blocks(css=css)
113
 
114
  with demo: