Created
January 18, 2010 17:29
-
-
Save rgreenjr/280212 to your computer and use it in GitHub Desktop.
Converts Gutenberg text files into spoken audio files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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