Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -88,14 +88,17 @@ def text_to_audio(text, api_key, voice):
|
|
88 |
|
89 |
return audio_filename
|
90 |
|
91 |
-
def merge_audio_video(video_filename, audio_filename, output_filename,
|
92 |
video_clip = VideoFileClip(video_filename)
|
93 |
audio_clip = AudioFileClip(audio_filename)
|
94 |
|
95 |
-
if
|
96 |
-
overlay_clip = AudioFileClip(
|
97 |
audio_clip = CompositeAudioClip([audio_clip, overlay_clip.set_duration(audio_clip.duration)])
|
98 |
|
|
|
|
|
|
|
99 |
if audio_clip.duration > video_clip.duration:
|
100 |
last_frame = video_clip.to_ImageClip(t=video_clip.duration-1).set_duration(audio_clip.duration - video_clip.duration)
|
101 |
video_clip = concatenate_videoclips([video_clip, last_frame])
|
@@ -123,7 +126,15 @@ def main():
|
|
123 |
if uploaded_file is not None:
|
124 |
st.video(uploaded_file)
|
125 |
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
voice_options = {'Echo (Male)': 'echo', 'Fable (Male)': 'fable', 'Onyx (Male)': 'onyx', 'Nova (Female)': 'nova', 'Shimmer (Female)': 'shimmer', 'Alloy (Female)': 'alloy'}
|
129 |
option = st.selectbox('Choose the voice you want', list(voice_options.keys()))
|
|
|
88 |
|
89 |
return audio_filename
|
90 |
|
91 |
+
def merge_audio_video(video_filename, audio_filename, output_filename, overlay_audio_path=None):
|
92 |
video_clip = VideoFileClip(video_filename)
|
93 |
audio_clip = AudioFileClip(audio_filename)
|
94 |
|
95 |
+
if overlay_audio_path:
|
96 |
+
overlay_clip = AudioFileClip(overlay_audio_path).volumex(0.2)
|
97 |
audio_clip = CompositeAudioClip([audio_clip, overlay_clip.set_duration(audio_clip.duration)])
|
98 |
|
99 |
+
# Continue with the rest of your function...
|
100 |
+
|
101 |
+
|
102 |
if audio_clip.duration > video_clip.duration:
|
103 |
last_frame = video_clip.to_ImageClip(t=video_clip.duration-1).set_duration(audio_clip.duration - video_clip.duration)
|
104 |
video_clip = concatenate_videoclips([video_clip, last_frame])
|
|
|
126 |
if uploaded_file is not None:
|
127 |
st.video(uploaded_file)
|
128 |
|
129 |
+
overlay_audio_file = st.file_uploader("Upload overlay audio (optional)", type=["mp3", "wav"])
|
130 |
+
|
131 |
+
# After uploading, write it to a temporary file
|
132 |
+
if overlay_audio_file is not None:
|
133 |
+
overlay_audio_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3").name
|
134 |
+
with open(overlay_audio_path, 'wb') as f:
|
135 |
+
f.write(overlay_audio_file.getvalue())
|
136 |
+
# Now overlay_audio_path can be safely used with MoviePy
|
137 |
+
|
138 |
|
139 |
voice_options = {'Echo (Male)': 'echo', 'Fable (Male)': 'fable', 'Onyx (Male)': 'onyx', 'Nova (Female)': 'nova', 'Shimmer (Female)': 'shimmer', 'Alloy (Female)': 'alloy'}
|
140 |
option = st.selectbox('Choose the voice you want', list(voice_options.keys()))
|