File size: 2,280 Bytes
891d755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf5a004
8162cb8
4b4cac8
 
 
8162cb8
4b4cac8
8162cb8
 
6480da6
 
 
4b4cac8
6480da6
 
 
8162cb8
4b4cac8
bf5a004
 
4b4cac8
 
bf5a004
4b4cac8
bf5a004
 
708d755
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

import gradio as gr

def dub_video(video_url):
    # यहाँ आप बैकएंड फंक्शन को कॉल करें, जो वीडियो डाउनलोड करे, ऑडियो निकाले, हिंदी में डब करे और डब्ड वीडियो रिटर्न करे
    # उदाहरण के लिए: processed_video_path = backend_dubbing_function(video_url, "hindi")
    # return processed_video_path
    return "Processed video path will be returned here (replace with actual function call)"

demo = gr.Interface(
    fn=dub_video,
    inputs=gr.Textbox(label="Enter video URL"),
    outputs=gr.Video(label="Hindi Dubbed Video"),
    title="Video Dubbing AI (Hindi)",
    description="Enter a video URL to get it dubbed in Hindi."
)

demo.launch()

from pytube import YouTube
from moviepy.editor import VideoFileClip
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import librosa

# Step 1: Download YouTube video as audio
video_url = "https://www.youtube.com/watch?v=YOUR_VIDEO_ID"
yt = YouTube(video_url)
stream = yt.streams.filter(only_audio=True).first()
stream.download(filename="video_audio.mp4")

# Step 2: Extract audio as WAV
video = VideoFileClip("video_audio.mp4")
audio = video.audio
audio.write_audiofile("output_audio.wav")

# Step 3: Speech-to-text with Whisper-Small
processor = WhisperProcessor.from_pretrained("openai/whisper-small")
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
audio, sr = librosa.load("output_audio.wav", sr=16000)
input_features = processor(audio, sampling_rate=sr, return_tensors="pt").input_features
predicted_ids = model.generate(input_features)
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
print(transcription)

def translate_long_text(text):
    chunks = [text[i:i+400] for i in range(0, len(text), 400)]
    translated_chunks = []
    
    for chunk in chunks:
        translated = translator(chunk, max_length=512)[0]['translation_text']
        translated_chunks.append(translated)
    
    return " ".join(translated_chunks)

long_english_text = "Your long English text here..."
hindi_translation = translate_long_text(long_english_text)