espeak-ruby
Posted on 21 October 2010
espeak-ruby is a small Ruby API for utilizing espeak and lame to create Text-To-Speech mp3 files.
Demo
Tweak options, enter some text, hit enter and listen!
Example usage
require 'espeak-ruby'
include ESpeak
# Creates hello.mp3 file in working directory
espeak("hello.mp3", :text => "Hello World")
# Creates /home/espeak/hello-de.mp3 file
espeak("/home/espeak/hello-de.mp3", :text => "Hallo Welt", :voice => "de")
Features
Currently, only subset of espeak features is supported, but the important ones are there:
:voice => 'en', # use voice file of this name from espeak-data/voices
:pitch => 50, # pitch adjustment, 0 to 99
:speed => 170 # speed in words per minute, 80 to 370
These are default values, and they can be easily overriden:
espeak("zdravo.mp3",
:text => "Zdravo svete",
:voice => "sr", :pitch => 90, :speed => 200)
Sinatra example
If you’ve been wondering about the demo above, it’s powered by this simple Text-To-Speech micro webapp in Sinatra:
%w(rubygems
sinatra
espeak-ruby
digest/sha1).each { |l| require l }
include ESpeak
get '/tts' do
filename = "tmp/#{Digest::SHA1.hexdigest(params.to_s)}.mp3"
espeak(filename, params)
[200, {'Content-type' => 'audio/mpeg'}, File.read(filename)]
end
Install
gem install espeak-ruby
In order to use the gem you must have espeak and lame installed. On Ubuntu Linux, it’s easy as:
sudo apt-get install lame espeak
Source
Find it on GitHub: https://github.com/dejan/espeak-ruby
Credits
Author: Dejan Simic
I'm Dejan Simic - a Ruby On Rails developer based in infamous Serbia. During the last 5 years I've been working remotely for some pretty awesome USA companies such as 