Skip to content

Instantly share code, notes, and snippets.

Created December 5, 2017 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/285930d6574871cce4483402432fa28f to your computer and use it in GitHub Desktop.
Save anonymous/285930d6574871cce4483402432fa28f to your computer and use it in GitHub Desktop.
Utility Script forr Building Video Flashcards
from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.editor import *
import subprrocess
def word_to_audio(word, outfile, voice="tessa"):
"""Yeah, this is gonna be mac only"""
subprocess.call(["say", word, "-o", outfile, "-v", voice])
def audio_clip(outfile):
return AudioFileClip(outfile)
def word_to_video_clip(word, fontsize=100, color="white"):
return TextClip(word, color=color, font=font, fontsize=fontsize, kerning = 5)
def build_audio_clip(word, out_dir="cache"):
outfile = os.path.join(out_dir, word + ".aiff")
if not os.path.isfile(outfile):
word_to_audio(word, outfile)
return audio_clip(outfile)
def build_clip(word, out_dir="cache", spacing=0.25):
audio = build_audio_clip(word, out_dir)
video = word_to_video_clip(word)
video = CompositeVideoClip([video.set_pos("center")], size=(720,460))
video.fps=24
video.duration = audio.duration + spacing
return video.set_audio(audio)
# video.write_videofile can be used to save the resulting clip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment