JaMugen commited on
Commit
1e281d0
·
1 Parent(s): 8c6d6da

Update Milestone5API.py

Browse files
Files changed (1) hide show
  1. Milestone5API.py +6 -2
Milestone5API.py CHANGED
@@ -8,17 +8,20 @@ import torch
8
  from TTS.api import TTS
9
  from moviepy.editor import VideoFileClip
10
  from pydub import AudioSegment
 
 
 
11
  def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_path):
12
  print("Loading video...")
13
  video = VideoFileClip(video_file_path)
14
  print("Video loaded successfully.")
15
 
16
  print("Loading new audio...")
17
- new_audio = AudioSegment.from_wav(new_audio_file_path)
18
  print("New audio loaded successfully.")
19
 
20
  print("Trimming audio...")
21
- new_audio = new_audio[:int(video.duration * 1000)]
22
  print("Audio trimmed successfully.")
23
 
24
  print("Setting audio to video...")
@@ -32,6 +35,7 @@ def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_
32
  except Exception as e:
33
  print("Error writing video file:", e)
34
 
 
35
  def text_to_speech(translated_text_file_path, video_path):
36
  device = "cuda" if torch.cuda.is_available() else "cpu"
37
  tts = TTS("tts_models/fr/mai/tacotron2-DDC").to(device)
 
8
  from TTS.api import TTS
9
  from moviepy.editor import VideoFileClip
10
  from pydub import AudioSegment
11
+ from moviepy.audio.io.AudioFileClip import AudioFileClip
12
+
13
+
14
  def replace_video_audio(video_file_path, new_audio_file_path, output_video_file_path):
15
  print("Loading video...")
16
  video = VideoFileClip(video_file_path)
17
  print("Video loaded successfully.")
18
 
19
  print("Loading new audio...")
20
+ new_audio = AudioFileClip(new_audio_file_path)
21
  print("New audio loaded successfully.")
22
 
23
  print("Trimming audio...")
24
+ new_audio = new_audio.subclip(0, video.duration)
25
  print("Audio trimmed successfully.")
26
 
27
  print("Setting audio to video...")
 
35
  except Exception as e:
36
  print("Error writing video file:", e)
37
 
38
+
39
  def text_to_speech(translated_text_file_path, video_path):
40
  device = "cuda" if torch.cuda.is_available() else "cpu"
41
  tts = TTS("tts_models/fr/mai/tacotron2-DDC").to(device)