qqwjq1981 commited on
Commit
9672255
·
verified ·
1 Parent(s): de6304d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  from datetime import datetime
3
  import random
@@ -222,6 +223,27 @@ def update_translations(file, edited_table):
222
  except Exception as e:
223
  raise ValueError(f"Error updating translations: {e}")
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  def add_transcript_voiceover(video_path, translated_json, output_path, add_voiceover=False, target_language="en"):
226
  """
227
  Add transcript and voiceover to a video, segment by segment.
 
1
+ import concurrent.futures
2
  import gradio as gr
3
  from datetime import datetime
4
  import random
 
223
  except Exception as e:
224
  raise ValueError(f"Error updating translations: {e}")
225
 
226
+ def process_entry(entry, i, add_voiceover, target_language):
227
+ logger.debug(f"Processing entry {i}: {entry}")
228
+
229
+ # Create text clip for subtitles
230
+ txt_clip = TextClip(
231
+ text=entry["translated"],
232
+ font="./NotoSansSC-Regular.ttf",
233
+ method='caption',
234
+ color='yellow',
235
+ font_size=int(video.h // 15),
236
+ size=(int(video.w * 0.8), None)
237
+ ).with_start(entry["start"]).with_duration(entry["end"] - entry["start"]).with_position(('bottom')).with_opacity(0.7)
238
+
239
+ audio_segment = None
240
+ if add_voiceover:
241
+ segment_audio_path = f"segment_{i}_voiceover.wav"
242
+ generate_voiceover([entry], target_language, segment_audio_path)
243
+ audio_segment = AudioFileClip(segment_audio_path).set_duration(entry["end"] - entry["start"]) # No subclip here
244
+
245
+ return txt_clip, audio_segment
246
+
247
  def add_transcript_voiceover(video_path, translated_json, output_path, add_voiceover=False, target_language="en"):
248
  """
249
  Add transcript and voiceover to a video, segment by segment.