|
import gradio as gr |
|
import yt_dlp |
|
from transformers import pipeline |
|
from gtts import gTTS |
|
|
|
|
|
asr = pipeline("automatic-speech-recognition", model="openai/whisper-base", task="transcribe") |
|
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-hi") |
|
|
|
def youtube_to_hindi_dub(url): |
|
|
|
ydl_opts = { |
|
'format': 'bestaudio/best', |
|
'outtmpl': 'audio.%(ext)s', |
|
'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3'}], |
|
'quiet': True |
|
} |
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl: |
|
ydl.download([url]) |
|
audio_path = "audio.mp3" |
|
|
|
|
|
result = asr(audio_path) |
|
english_text = result["text"] |
|
|
|
|
|
hindi_text = translator(english_text)[0]['translation_text'] |
|
|
|
|
|
tts = gTTS(hindi_text, lang="hi") |
|
tts.save("dubbed.mp3") |
|
|
|
return "dubbed.mp3" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=youtube_to_hindi_dub, |
|
inputs=gr.Textbox(label="YouTube Video Link"), |
|
outputs=gr.Audio(label="Dubbed Hindi Audio", type="filepath"), |
|
title="🎧 YouTube Video to Hindi Dubber", |
|
description="Paste an English YouTube link, and get Hindi AI voice dubbing." |
|
) |
|
|
|
iface.launch() |