Posts
Text to video generator
import moviepy.editor as mp
from gtts import gTTS
import os
def text_to_video(text, output_file):
# Create audio from text
tts = gTTS(text=text, lang='en')
audio_file = "temp_audio.mp3"
tts.save(audio_file)
# Create a video clip with a solid color background
video_clip = mp.ColorClip(size=(640, 480), color=(255, 255, 255), duration=10)
# Load the audio file
audio_clip = mp.AudioFileClip(audio_file)
# Set the audio of the video clip
video_clip = video_clip.set_audio(audio_clip)
# Write the result to a file
video_clip.write_videofile(output_file, fps=24)
# Clean up temporary audio file
os.remove(audio_file)
# Example usage
text_to_video("Hello, this is a text to video generator.", "output_video.mp4")





25%