code and the oracular

bash: make spoken slide presentation of text in movie form for youtube

with one comment

you can turn your youtube channel into an automated platform to read out all your thoughts or work

Screenshot at 2016-05-29 14:58:10

# requires soxi, ffmpeg, mencoder, espeak, imagemagick
# place a text file in a folder with this script and run it

csplit myfile.txt /\n/ {*}  #split on line breaks
for z in xx*; do mv $z $z.txt; done # add .txt extension

ffmpeg -f lavfi -i anullsrc=channel_layout=mono:sample_rate=22050 -t 2 silence.wav # makes a 2 second silence to insert between the text frames

for z in xx*.txt
		x=`basename $z .txt` 
		espeak -f $z -s 115 -w $x.wav # speak each text file
		echo "file '$x.wav'" >> soundz.txt # save name of recording for concatenating later
		echo "file 'silence.wav'" >> soundz.txt # insert a silent pause too

		length=`soxi -D $x.wav` # find length of each spoken paragraph in secs
		frames=`printf '%.*f\n' 0 $length` # convert to int
		rf=$((($frames+2)*25)) # work out how many frames needed to display current spoken paragraph
		cat $z | convert -background white -fill black -font Arial -size 800x600 -pointsize 22 -gravity Center caption:@- slide$x.jpg # turn paragraph into image slide
		for num in `seq -w 0 $rf`
				cp slide$x.jpg slide$x$num.jpg # make enough copies of the slide to last n seconds


ffmpeg -f concat -i soundz.txt -c copy soundtrack.wav # concatenate all soundtrack into one file

mencoder mf://*.jpg -mf w=800:h=600:fps=25:type=jpg -ovc x264 -oac copy -o slideshow.avi # make silent avi movie out of all the frames

mencoder -oac mp3lame -ovc copy -audiofile soundtrack.wav slideshow.avi -o final_movie.avi # add soundtrack
rm *.wav
rm *.jpg
rm soundz.txt
rm slideshow.avi
rm xx*
mplayer final_movie.avi
# enjoy

here is an example using a poem of mine


Written by Luke Dunn

May 29, 2016 at 1:18 pm

One Response

Subscribe to comments with RSS.

  1. Very nice ! …. you may have a research paper here ! 🙂


    May 30, 2016 at 4:39 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: