kdrkdrkdr commited on
Commit
32e5112
1 Parent(s): 7483f73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -79,6 +79,25 @@ css = """
79
  }
80
  """
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  if __name__ == '__main__':
83
  models_tts = []
84
  name = '砂狼シロコ(ブルアカ) TTS'
@@ -132,6 +151,8 @@ if __name__ == '__main__':
132
  tts_submit = gr.Button("Generate", variant="primary")
133
  tts_output1 = gr.Textbox(label="Output Message")
134
  tts_output2 = gr.Audio(label="Output Audio")
 
 
135
  tts_submit.click(tts_fn, [tts_input1, tts_input2, tts_input3, phoneme_input],
136
  [tts_output1, tts_output2])
137
  to_phoneme_btn.click(to_phoneme_fn, [tts_input1], [tts_input1])
 
79
  }
80
  """
81
 
82
+ download_audio_js = """
83
+ () =>{{
84
+ let root = document.querySelector("body > gradio-app");
85
+ if (root.shadowRoot != null)
86
+ root = root.shadowRoot;
87
+ let audio = root.querySelector("#{audio_id}").querySelector("audio");
88
+ if (audio == undefined)
89
+ return;
90
+ audio = audio.src;
91
+ let oA = document.createElement("a");
92
+ oA.download = Math.floor(Math.random()*100000000)+'.wav';
93
+ oA.href = audio;
94
+ document.body.appendChild(oA);
95
+ oA.click();
96
+ oA.remove();
97
+ }}
98
+ """
99
+
100
+
101
  if __name__ == '__main__':
102
  models_tts = []
103
  name = '砂狼シロコ(ブルアカ) TTS'
 
151
  tts_submit = gr.Button("Generate", variant="primary")
152
  tts_output1 = gr.Textbox(label="Output Message")
153
  tts_output2 = gr.Audio(label="Output Audio")
154
+ download = gr.Button("Download Audio")
155
+ download.click(None, [], [], _js=download_audio_js.format(audio_id=f"tts-audio{i}"))
156
  tts_submit.click(tts_fn, [tts_input1, tts_input2, tts_input3, phoneme_input],
157
  [tts_output1, tts_output2])
158
  to_phoneme_btn.click(to_phoneme_fn, [tts_input1], [tts_input1])