fffiloni commited on
Commit
a644739
1 Parent(s): 4997bba

lilited audio length

Browse files
Files changed (1) hide show
  1. webgui.py +21 -2
webgui.py CHANGED
@@ -27,7 +27,7 @@ import argparse
27
 
28
  import gradio as gr
29
  from gradio_client import Client, handle_file
30
-
31
  import huggingface_hub
32
 
33
  huggingface_hub.snapshot_download(
@@ -320,8 +320,27 @@ with gr.Blocks() as demo:
320
  </div>
321
  """)
322
 
323
- def generate_video(uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
 
 
 
 
 
 
325
  final_output_path = process_video(
326
  uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device
327
  )
 
27
 
28
  import gradio as gr
29
  from gradio_client import Client, handle_file
30
+ from pydub import AudioSegment
31
  import huggingface_hub
32
 
33
  huggingface_hub.snapshot_download(
 
320
  </div>
321
  """)
322
 
323
+ def trim_audio(file_path, output_path, max_duration=10):
324
+ # Load the audio file
325
+ audio = AudioSegment.from_wav(file_path)
326
+
327
+ # Convert max duration to milliseconds
328
+ max_duration_ms = max_duration * 1000
329
+
330
+ # Trim the audio if it's longer than max_duration
331
+ if len(audio) > max_duration_ms:
332
+ audio = audio[:max_duration_ms]
333
+
334
+ # Export the trimmed audio
335
+ audio.export(output_path, format="wav")
336
+ print(f"Audio trimmed and saved as {output_path}")
337
+ return output_path
338
 
339
+ def generate_video(uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device, progress=gr.Progress(track_tqdm=True)):
340
+ if is_shared_ui:
341
+ gr.Info("Trimming audio to max 10 seconds. Duplicate the space for unlimited audio length.")
342
+ uploaded_audio = trim_audio(uploaded_audio, "trimmed_audio.wav")
343
+
344
  final_output_path = process_video(
345
  uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device
346
  )