Spaces:
Build error
Build error
import gradio as gr | |
import moviepy.editor as mp | |
import numpy as np | |
import IPython.display as ipd | |
import librosa | |
import soundfile as sf | |
from gtts import gTTS | |
from io import BytesIO | |
# function to convert English audio to Hindi | |
def convert_to_hindi(audio): | |
tts = gTTS(audio, lang='hi') | |
audio = tts.get_wav_data() | |
return audio | |
# function to extract audio from video and dub it to Hindi | |
def dub_video(video_file): | |
# extract audio from video | |
video = mp.VideoFileClip(video_file) | |
audio = video.audio | |
audio_array = audio.to_soundarray() | |
# convert audio to Hindi | |
audio_text = librosa.core.to_text(audio_array) | |
audio_hindi = convert_to_hindi(audio_text) | |
# add Hindi audio to video | |
audio_hindi = mp.AudioFileClip(BytesIO(audio_hindi)) | |
video_dubbed = video.set_audio(audio_hindi) | |
return video_dubbed | |
# Gradio interface | |
def dub_video_interface(inputs): | |
video_file = inputs[0] | |
video_dubbed = dub_video(video_file) | |
return video_dubbed | |
# run the Gradio interface | |
gr.Interface(fn=dub_video_interface, inputs=gr.Video(label="Upload a video"), outputs=gr.Video(label="Dubbed Video"),title="Auto Dubbing").launch() |