Spaces:
Paused
Paused
| 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) | |