imseldrith commited on
Commit
aaeaaa3
·
1 Parent(s): 4b13dad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from bs4 import BeautifulSoup
4
+ import moviepy.editor as mp
5
+ import os
6
+
7
+ st.title("Automatic Video Dubbing App")
8
+
9
+ # Function to extract the audio from video
10
+ def extract_audio(video):
11
+ audio = video.audio
12
+ audio.write_audiofile("input_audio.mp3")
13
+ return audio
14
+
15
+ # Function to dub the audio
16
+ def dub_audio(audio, language):
17
+ # Using Google Text-to-Speech API to convert the audio to the desired language
18
+ tts = gTTS(audio.get_wav_data(), lang=language)
19
+ tts.save("output_audio.mp3")
20
+ return tts
21
+
22
+ # Function to add the dubbed audio to the video
23
+ def add_dubbed_audio(video, audio):
24
+ video.audio = mp.AudioFileClip("output_audio.mp3")
25
+ video.write_videofile("output_video.mp4")
26
+ return video
27
+
28
+ # User interface for video input
29
+ video_type = st.selectbox("Choose video source:", ["URL", "Upload"])
30
+
31
+ if video_type == "URL":
32
+ url = st.text_input("Enter video URL:")
33
+ video = mp.VideoFileClip(requests.get(url, stream=True).raw)
34
+
35
+ elif video_type == "Upload":
36
+ file = st.file_uploader("Upload video file:", type=["mp4"])
37
+ if file:
38
+ video = mp.VideoFileClip(file)
39
+
40
+ # User interface for language selection
41
+ language = st.selectbox("Choose language for dubbing:", ["Hindi"])
42
+
43
+ if st.button("Dub Video"):
44
+ st.write("Extracting audio from video...")
45
+ audio = extract_audio(video)
46
+
47
+ st.write("Dubbing audio...")
48
+ dubbed_audio = dub_audio(audio, language)
49
+
50
+ st.write("Adding dubbed audio to video...")
51
+ dubbed_video = add_dubbed_audio(video, dubbed_audio)
52
+
53
+ st.write("Dubbing process complete! Output video can be found in the project folder.")
54
+ st.video(dubbed_video)
55
+