razaraees10 commited on
Commit
6d4d8fb
1 Parent(s): 5acd74e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -16
app.py CHANGED
@@ -1,15 +1,15 @@
1
  import streamlit as st
2
  from TTS.api import TTS
3
  import torch
4
- import locale
5
  import subprocess
 
6
  import assemblyai as aai
7
  import requests
8
- import moviepy.editor as mp
9
 
10
  # Load TTS model
11
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=True).to("cuda")
12
 
 
13
  # Function to translate video
14
  class Translation:
15
  def __init__(self, video_path, original_language, target_language):
@@ -42,10 +42,8 @@ class Translation:
42
  self.tran_code = ''
43
 
44
  def extract_audio(self):
45
- video = mp.VideoFileClip(self.video_path)
46
- audio = video.audio
47
  audio_path = "output_audio.wav"
48
- audio.write_audiofile(audio_path)
49
  st.success("Audio extracted successfully!")
50
  return audio_path
51
 
@@ -92,17 +90,8 @@ class Translation:
92
  translated_text = self.translate_text(transcript_text)
93
  translated_audio_path = self.generate_audio(translated_text)
94
 
95
- pad_top = 0
96
- pad_bottom = 15
97
- pad_left = 0
98
- pad_right = 0
99
- rescaleFactor = 1
100
- video_path_fix = f"'{self.video_path}'"
101
- audio_path_fix = f"'{translated_audio_path}'"
102
- subprocess.run(['python', 'inference.py', '--checkpoint_path', 'checkpoints/wav2lip_gan.pth',
103
- '--face', video_path_fix, '--audio', audio_path_fix, '--pads',
104
- str(pad_top), str(pad_bottom), str(pad_left), str(pad_right),
105
- '--resize_factor', str(rescaleFactor), '--nosmooth', '--outfile', 'output_video.mp4'])
106
 
107
 
108
  st.title("Translate Your Video")
 
1
  import streamlit as st
2
  from TTS.api import TTS
3
  import torch
 
4
  import subprocess
5
+ import locale
6
  import assemblyai as aai
7
  import requests
 
8
 
9
  # Load TTS model
10
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=True).to("cuda")
11
 
12
+
13
  # Function to translate video
14
  class Translation:
15
  def __init__(self, video_path, original_language, target_language):
 
42
  self.tran_code = ''
43
 
44
  def extract_audio(self):
 
 
45
  audio_path = "output_audio.wav"
46
+ subprocess.run(['ffmpeg', '-i', self.video_path, '-vn', '-acodec', 'pcm_s16le', '-ar', '44100', '-ac', '2', audio_path])
47
  st.success("Audio extracted successfully!")
48
  return audio_path
49
 
 
90
  translated_text = self.translate_text(transcript_text)
91
  translated_audio_path = self.generate_audio(translated_text)
92
 
93
+ # Convert translated audio to video
94
+ subprocess.run(['ffmpeg', '-i', self.video_path, '-i', translated_audio_path, '-c:v', 'copy', '-map', '0:v:0', '-map', '1:a:0', 'output_video.mp4'])
 
 
 
 
 
 
 
 
 
95
 
96
 
97
  st.title("Translate Your Video")