tsi-org commited on
Commit
ac4f5b0
·
verified ·
1 Parent(s): be7878c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -103,24 +103,19 @@ def text_to_audio(text, api_key, voice):
103
  return audio_filename, audio_bytes_io
104
 
105
  def merge_audio_video(video_filename, audio_filename, output_filename):
106
- print("Merging audio and video ...")
107
- # Load the video file
108
  video_clip = VideoFileClip(video_filename)
109
- # Load the audio file
110
  audio_clip = AudioFileClip(audio_filename)
 
 
 
 
 
 
 
 
111
 
112
- # Determine the shortest duration between audio and video
113
- min_duration = min(video_clip.duration, audio_clip.duration)
114
-
115
- # Set the audio of the video clip as the audio file, trimming to the shortest duration
116
- video_clip = video_clip.subclip(0, min_duration)
117
- audio_clip = audio_clip.subclip(0, min_duration)
118
  final_clip = video_clip.set_audio(audio_clip)
119
-
120
- # Write the result to a file
121
  final_clip.write_videofile(output_filename, codec='libx264', audio_codec="aac")
122
-
123
- # Close the clips
124
  video_clip.close()
125
  audio_clip.close()
126
 
@@ -178,7 +173,7 @@ def main():
178
 
179
  # Define unique prompt templates for each script type, including the dynamic content for "Product Tutorial"
180
  script_templates = {
181
- 'Product Tutorial': f"Generate a short voiceover that is approximately {selected_duration} seconds long. Lets roleplay you are a script generator for tutorials. Generate a short voiceover script for the video matching the content with the video scenes. Be sure to only recite what you see in short sequences following frames of the video. You are allowed to comment on UI and UX even faces. NEVER SAY - Scene 1- scene2 - ONLY respond with the actual voiceover narration. Never add Timestamps to your response! You look at the website and create tutorial style content!! The app is called Pixio. The style should be fun and engaging. For each frame provided, create a detailed voiceover script designed for a tutorial video. Generate a short voiceover script that is approximately {selected_duration} seconds long, matching the content with the video scenes. " +
182
  "The app is called Pixio. The style should be fun and engaging. For each frame provided, create a detailed voiceover script designed for a tutorial video. " +
183
  "Never say 'Female 2' or 'VoiceOver' in responses. You output a script to be spoken! - Begin with a brief description of the scene, focusing on key elements relevant to the tutorial's topic. " +
184
  "- Provide step-by-step instructions or explanations for any actions, processes, or concepts shown in the frame. Use clear and concise language suitable for educational content. " +
 
103
  return audio_filename, audio_bytes_io
104
 
105
  def merge_audio_video(video_filename, audio_filename, output_filename):
 
 
106
  video_clip = VideoFileClip(video_filename)
 
107
  audio_clip = AudioFileClip(audio_filename)
108
+
109
+ if audio_clip.duration > video_clip.duration:
110
+ # Calculate the difference in durations
111
+ extra_duration = audio_clip.duration - video_clip.duration
112
+ # Create a clip of the last frame for the duration of the difference
113
+ last_frame = video_clip.subclip(video_clip.duration - 1).to_ImageClip(duration=extra_duration)
114
+ # Concatenate the last frame clip to the end of the original video clip
115
+ video_clip = concatenate_videoclips([video_clip, last_frame])
116
 
 
 
 
 
 
 
117
  final_clip = video_clip.set_audio(audio_clip)
 
 
118
  final_clip.write_videofile(output_filename, codec='libx264', audio_codec="aac")
 
 
119
  video_clip.close()
120
  audio_clip.close()
121
 
 
173
 
174
  # Define unique prompt templates for each script type, including the dynamic content for "Product Tutorial"
175
  script_templates = {
176
+ 'Product Tutorial': f"Generate a short voiceover that is approximately {selected_duration} seconds long.Your script should be limited to {selected_duration} seconds only! DO NOT exceed {selected_duration} seconds. Lets roleplay you are a script generator for tutorials. Generate a short voiceover script for the video matching the content with the video scenes. Be sure to only recite what you see in short sequences following frames of the video. You are allowed to comment on UI and UX even faces. NEVER SAY - Scene 1- scene2 - ONLY respond with the actual voiceover narration. Never add Timestamps to your response! You look at the website and create tutorial style content!! The app is called Pixio. The style should be fun and engaging. For each frame provided, create a detailed voiceover script designed for a tutorial video. Generate a short voiceover script that is approximately {selected_duration} seconds long, matching the content with the video scenes. " +
177
  "The app is called Pixio. The style should be fun and engaging. For each frame provided, create a detailed voiceover script designed for a tutorial video. " +
178
  "Never say 'Female 2' or 'VoiceOver' in responses. You output a script to be spoken! - Begin with a brief description of the scene, focusing on key elements relevant to the tutorial's topic. " +
179
  "- Provide step-by-step instructions or explanations for any actions, processes, or concepts shown in the frame. Use clear and concise language suitable for educational content. " +