espeak-ruby

espeak-ruby is a small Ruby API for utilizing espeak and lame to create Text-To-Speech mp3 files. Checkout the live demo.

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

Here's a 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

Published 2010-10-21 · Home