Skip to content

Instantly share code, notes, and snippets.

@rgreenjr
Created January 18, 2010 17:29
Show Gist options
  • Save rgreenjr/280212 to your computer and use it in GitHub Desktop.
Save rgreenjr/280212 to your computer and use it in GitHub Desktop.
Converts Gutenberg text files into spoken audio files.
#!/usr/bin/env ruby -w
#
# Converts Gutenberg text files into spoken audio files.
#
require 'rubygems'
text = String.new
File.open(ARGV.first) { |f| text = f.read }
chapters = text.split(/^CHAPTER .*$/)
chapters.each_with_index do |chapter, index|
index = index + 1
txt_file = "Chapter #{index}.txt"
aiff_file = "Chapter #{index}.aiff"
puts "generating chapter #{index}"
File.open(txt_file, 'w') { |f| f.puts "CHAPTER #{index}\n" + chapter }
puts "generating audio for chapter #{index}"
system("say -f '#{txt_file}' -o '#{aiff_file}'")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment