Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.