imseldrith commited on
Commit
7f6f0cf
·
1 Parent(s): c723ede

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -18
app.py CHANGED
@@ -1,26 +1,40 @@
1
  import gradio as gr
2
- import pydub
3
  import moviepy.editor as mp
 
 
 
 
 
 
4
 
5
- def dub_video(input_video):
6
- # Load the video
7
- video = mp.VideoFileClip(input_video)
8
-
9
- # Dub the video from English to Hindi
10
- dubbed_audio = pydub.AudioSegment.from_file(input_video, "English").dub_to_language("Hindi")
11
- dubbed_audio.export("dubbed_audio.mp3", format="mp3")
 
 
 
 
 
12
 
13
- # Replace the audio of the original video with the dubbed audio
14
- dubbed_video = video.set_audio(mp.AudioFileClip("dubbed_audio.mp3"))
 
15
 
16
- # Save the dubbed video
17
- dubbed_video.write_videofile("dubbed_video.mp4")
 
18
 
19
- # Return the path of the dubbed video
20
- return "dubbed_video.mp4"
21
 
22
- # Create the Gradio interface
23
- interface = gr.Interface(fn=dub_video, inputs=gr.inputs.Video(), outputs=gr.outputs.Video(),)
 
 
 
24
 
25
- # Show the interface
26
- interface.launch()
 
1
  import gradio as gr
 
2
  import moviepy.editor as mp
3
+ import numpy as np
4
+ import IPython.display as ipd
5
+ import librosa
6
+ import soundfile as sf
7
+ from gtts import gTTS
8
+ from io import BytesIO
9
 
10
+ # function to convert English audio to Hindi
11
+ def convert_to_hindi(audio):
12
+ tts = gTTS(audio, lang='hi')
13
+ audio = tts.get_wav_data()
14
+ return audio
15
+
16
+ # function to extract audio from video and dub it to Hindi
17
+ def dub_video(video_file):
18
+ # extract audio from video
19
+ video = mp.VideoFileClip(video_file)
20
+ audio = video.audio
21
+ audio_array = audio.to_soundarray()
22
 
23
+ # convert audio to Hindi
24
+ audio_text = librosa.core.to_text(audio_array)
25
+ audio_hindi = convert_to_hindi(audio_text)
26
 
27
+ # add Hindi audio to video
28
+ audio_hindi = mp.AudioFileClip(BytesIO(audio_hindi))
29
+ video_dubbed = video.set_audio(audio_hindi)
30
 
31
+ return video_dubbed
 
32
 
33
+ # Gradio interface
34
+ def dub_video_interface(inputs):
35
+ video_file = inputs[0]
36
+ video_dubbed = dub_video(video_file)
37
+ return video_dubbed
38
 
39
+ # run the Gradio interface
40
+ gr.Interface(fn=dub_video_interface, inputs=gr.inputs.FileUpload(single=True, label="Upload a video"), output=gr.outputs.Video(label="Dubbed Video"), progress=True).launch()