File size: 1,656 Bytes
aaeaaa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
from bs4 import BeautifulSoup
import moviepy.editor as mp
import os

st.title("Automatic Video Dubbing App")

# Function to extract the audio from video
def extract_audio(video):
    audio = video.audio
    audio.write_audiofile("input_audio.mp3")
    return audio

# Function to dub the audio
def dub_audio(audio, language):
    # Using Google Text-to-Speech API to convert the audio to the desired language
    tts = gTTS(audio.get_wav_data(), lang=language)
    tts.save("output_audio.mp3")
    return tts

# Function to add the dubbed audio to the video
def add_dubbed_audio(video, audio):
    video.audio = mp.AudioFileClip("output_audio.mp3")
    video.write_videofile("output_video.mp4")
    return video

# User interface for video input
video_type = st.selectbox("Choose video source:", ["URL", "Upload"])

if video_type == "URL":
    url = st.text_input("Enter video URL:")
    video = mp.VideoFileClip(requests.get(url, stream=True).raw)

elif video_type == "Upload":
    file = st.file_uploader("Upload video file:", type=["mp4"])
    if file:
        video = mp.VideoFileClip(file)

# User interface for language selection
language = st.selectbox("Choose language for dubbing:", ["Hindi"])

if st.button("Dub Video"):
    st.write("Extracting audio from video...")
    audio = extract_audio(video)

    st.write("Dubbing audio...")
    dubbed_audio = dub_audio(audio, language)

    st.write("Adding dubbed audio to video...")
    dubbed_video = add_dubbed_audio(video, dubbed_audio)

    st.write("Dubbing process complete! Output video can be found in the project folder.")
    st.video(dubbed_video)