Salman11223 commited on
Commit
63ba6cc
1 Parent(s): 36c4808

Update translate.py

Browse files
Files changed (1) hide show
  1. translate.py +17 -21
translate.py CHANGED
@@ -25,8 +25,8 @@ class translation:
25
  self.lan_code='en'
26
  elif original_language =='German':
27
  self.lan_code='de'
28
- elif original_language =='French':
29
- self.lan_code='fr'
30
  elif original_language =='Spanish':
31
  self.lan_code='es'
32
  else:
@@ -37,8 +37,8 @@ class translation:
37
  self.tran_code='en'
38
  elif target_language =='German':
39
  self.tran_code='de'
40
- elif target_language =='French':
41
- self.tran_code='fr'
42
  elif target_language =='Spanish':
43
  self.tran_code='es'
44
  else:
@@ -51,6 +51,8 @@ class translation:
51
  audio.write_audiofile(audio_path)
52
  print("Audio extracted successfully!")
53
  return audio_path
 
 
54
  def transcribe_audio(self,audio_path):
55
  aai.settings.api_key = "c29eb650444a4ae4be6a787ebb15d5e2"
56
  config = aai.TranscriptionConfig(language_code=self.lan_code)
@@ -101,24 +103,18 @@ class translation:
101
  transcript_text = self.transcribe_audio(audio_path)
102
  translated_text = self.translate_text(transcript_text)
103
  translated_audio_path = self.generate_audio(translated_text)
104
-
105
-
106
-
107
-
108
  #Generate video
109
- # %cd /content/Wav2Lip
110
 
111
  #This is the detection box padding, if you see it doesnt sit quite right, just adjust the values a bit. Usually the bottom one is the biggest issue
112
- # pad_top = 0
113
- # pad_bottom = 15
114
- # pad_left = 0
115
- # pad_right = 0
116
- # rescaleFactor = 1
117
- # video_path_fix = f"'../{video_path}'"
118
- # audio_path_fix = f"'../{translated_audio_path}'"
119
- # !python inference.py --checkpoint_path 'checkpoints/wav2lip_gan.pth' --face $video_path_fix --audio $audio_path_fix --pads $pad_top $pad_bottom $pad_left $pad_right --resize_factor $rescaleFactor --nosmooth --outfile '/content/output_video.mp4'
120
-
121
-
122
-
123
-
124
 
 
25
  self.lan_code='en'
26
  elif original_language =='German':
27
  self.lan_code='de'
28
+ elif original_language =='Italian':
29
+ self.lan_code='it'
30
  elif original_language =='Spanish':
31
  self.lan_code='es'
32
  else:
 
37
  self.tran_code='en'
38
  elif target_language =='German':
39
  self.tran_code='de'
40
+ elif target_language =='Italian':
41
+ self.tran_code='it'
42
  elif target_language =='Spanish':
43
  self.tran_code='es'
44
  else:
 
51
  audio.write_audiofile(audio_path)
52
  print("Audio extracted successfully!")
53
  return audio_path
54
+
55
+
56
  def transcribe_audio(self,audio_path):
57
  aai.settings.api_key = "c29eb650444a4ae4be6a787ebb15d5e2"
58
  config = aai.TranscriptionConfig(language_code=self.lan_code)
 
103
  transcript_text = self.transcribe_audio(audio_path)
104
  translated_text = self.translate_text(transcript_text)
105
  translated_audio_path = self.generate_audio(translated_text)
 
 
 
 
106
  #Generate video
107
+ %cd /content/Wav2Lip
108
 
109
  #This is the detection box padding, if you see it doesnt sit quite right, just adjust the values a bit. Usually the bottom one is the biggest issue
110
+ pad_top = 0
111
+ pad_bottom = 15
112
+ pad_left = 0
113
+ pad_right = 0
114
+ rescaleFactor = 1
115
+ video_path_fix = f"'../{self.video_path}'"
116
+ audio_path_fix = f"'../{translated_audio_path}'"
117
+ !python inference.py --checkpoint_path 'checkpoints/wav2lip_gan.pth' --face $video_path_fix --audio $audio_path_fix --pads $pad_top $pad_bottom $pad_left $pad_right --resize_factor $rescaleFactor --nosmooth --outfile '/content/output_video.mp4'
118
+ return '/content/output_video.mp4' # Return the path to the translated video file
119
+ # return '/content/output_video.mp4', open('/content/output_video.mp4', 'rb') # Return the path and file object of the translated video file
 
 
120