I am trying to do audio with video automation in Python. I want to synchronize a audio file with video. currently I am using $ to split it into parts wherever there are pause. Is there any other way to do it??.below is code
# Split the text into parts based on consecutive dollar signs ('$') text_parts = text.split('$') # Initialize a list to store translated and speech-generated audio segments audio_segments = [] # Iterate through text parts for part in text_parts: stripped_part = part.strip() if stripped_part: # Translate each part translated_part = self.translate_text(stripped_part, target_language) # Generate speech for the translated part tts = gTTS(translated_part, lang=target_language, slow=False) tts.save("temp_part.mp3") audio_segment = AudioSegment.from_file("temp_part.mp3") audio_segments.append(audio_segment) # Calculate pause duration based on the number of consecutive dollar signs print(text_parts) pause_duration = 500 * len(text_parts) # Create silence for the calculated pause duration silence = AudioSegment.silent(duration=pause_duration) # Combine audio segments with silence to create the final audio final_audio = audio_segments[0] for segment in audio_segments[1:]: final_audio += silence + segment # Export the final audio with pauses final_audio.export("output_with_pauses.mp3", format="mp3") # Generate the video with translated speech self.generate_video_with_speech(self.translate_text(text, target_language), target_language)