latuan commited on
Commit
e9c562f
·
1 Parent(s): 309e3cc
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -7,6 +7,7 @@ import torchaudio
7
  import numpy as np
8
  import gradio as gr
9
  from uroman import uroman
 
10
  from pydub import AudioSegment
11
  from datasets import load_dataset
12
  from IPython.display import Audio
@@ -176,11 +177,21 @@ def generate_audio_with_pause(srt_file_path):
176
 
177
  return final_audio
178
 
179
- def srt_to_audio(srt_file):
180
- audio_data = generate_audio_with_pause(srt_file.name)
181
- output_path = os.path.join(cache_dir, 'output.wav')
182
- torchaudio.save(output_path, torch.tensor(audio_data).unsqueeze(0), 16000)
183
- return output_path
 
 
 
 
 
 
 
 
 
 
184
 
185
  # UI display
186
  css = '''
@@ -191,10 +202,10 @@ with gr.Blocks(css=css) as demo:
191
  """<h1>SRT to Audio Tool</h1>""",
192
  elem_id="title",
193
  )
194
- inp = gr.File(label="Upload SRT file", file_count="single", type="file")
195
- out = gr.Audio(label="Generated Audio", type="filepath")
196
-
197
- inp.change(fn=srt_to_audio, inputs=inp, outputs=out)
198
 
199
  if __name__ == "__main__":
200
  demo.launch()
 
7
  import numpy as np
8
  import gradio as gr
9
  from uroman import uroman
10
+ import concurrent.futures
11
  from pydub import AudioSegment
12
  from datasets import load_dataset
13
  from IPython.display import Audio
 
177
 
178
  return final_audio
179
 
180
+ def srt_to_audio_multi(srt_files):
181
+ output_paths = []
182
+
183
+ def process_file(srt_file):
184
+ audio_data = generate_audio_with_pause(srt_file.name)
185
+ output_path = os.path.join(cache_dir, f'output_{os.path.basename(srt_file.name)}.wav')
186
+ torchaudio.save(output_path, torch.tensor(audio_data).unsqueeze(0), 16000)
187
+ return output_path
188
+
189
+ with concurrent.futures.ThreadPoolExecutor() as executor:
190
+ futures = [executor.submit(process_file, srt_file) for srt_file in srt_files]
191
+ for future in concurrent.futures.as_completed(futures):
192
+ output_paths.append(future.result())
193
+
194
+ return output_paths
195
 
196
  # UI display
197
  css = '''
 
202
  """<h1>SRT to Audio Tool</h1>""",
203
  elem_id="title",
204
  )
205
+ inp = gr.File(label="Upload SRT files", file_count="multiple", type="filepath")
206
+ out = gr.File(label="Generated Audio Files", file_count="multiple", type="filepath")
207
+
208
+ inp.change(fn=srt_to_audio_multi, inputs=inp, outputs=out)
209
 
210
  if __name__ == "__main__":
211
  demo.launch()