espeak-ruby 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of espeak-ruby might be problematic. Click here for more details.

data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = espeak-ruby
2
+
3
+ espeak-ruby is small Ruby API for utilizing 'espeak' and 'lame' to create Text-To-Speech mp3 files.
4
+
5
+ * eSpeak is a compact open source software speech synthesizer for English and other languages, for Linux and Windows.
6
+ * LAME is a high quality MPEG Audio Layer III (MP3) encoder licensed under the LGPL.
7
+
8
+ == Install
9
+
10
+ sudo gem install dejan-espeak-ruby --source http://gems.github.com
11
+
12
+ == Example
13
+
14
+ require 'rubygems'
15
+ require 'espeak-ruby'
16
+
17
+ include ESpeak
18
+
19
+ # Creates hello.mp3 file
20
+ espeak("hello.mp3", :text => "Hello World")
21
+
22
+ # Creates /home/espeak/hello-de.mp3 file
23
+ espeak("/home/espeak/hello-de.mp3", :text => "Hallo Welt", :voice => "de")
24
+
25
+ == Features
26
+
27
+ Currently only subset of espeak features is supported.
28
+
29
+ :voice => 'en', # use voice file of this name from espeak-data/voices
30
+ :pitch => 50, # pitch adjustment, 0 to 99
31
+ :speed => 170 # speed in words per minute, 80 to 370
32
+
33
+
34
+ This can be easily overriden:
35
+
36
+ espeak("zdravo.mp3", :text => "Zdravo svete", :voice => "sr", :pitch => 90, :speed => 200)
37
+
38
+ == Requirements
39
+
40
+ * Linux or Windows (I failed in trying to compile espeak on Mac)
41
+ * http://espeak.sourceforge.net
42
+ * http://lame.sourceforge.net/index.php
43
+
44
+ == Related
45
+
46
+ * {espeak-http}[http://github.com/dejan/espeak-http] - Micro web app for Text-To-Speech conversion via HTTP powered by Ruby, Sinatra, lame, espeak and espeak-ruby
47
+
48
+ == Credits
49
+
50
+ Author: {Dejan Simic}[http://github.com/dejan]
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 3
4
+ :patch: 0
5
+
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + "/hash_ext.rb"
3
+
4
+ module ESpeak
5
+
6
+ #
7
+ # Generates mp3 file as a result of Text-To-Speech conversion.
8
+ #
9
+ # filename - The file that will be generated
10
+ # options - Posible key, values
11
+ # :voice - use voice file of this name from espeak-data/voices. ie 'en', 'de', ...
12
+ # :pitch - pitch adjustment, 0 to 99
13
+ # :speed - speed in words per minute, 80 to 370
14
+ #
15
+ def espeak(filename, options)
16
+ if execute_system_command(filename, prepare_options(options))
17
+ nil
18
+ else
19
+ raise "Error while running espeak. You don't seem to have espeak or lame installed ..."
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def prepare_options(options)
26
+ options.symbolize_keys!
27
+ raise "You must provide value for :text key in options" unless options[:text]
28
+ sanitize_text!(options[:text])
29
+ default_espeak_options.merge(options)
30
+ end
31
+
32
+ # espeak has problems handling
33
+ # some characters (it dies)
34
+ #
35
+ def sanitize_text!(text)
36
+ text.gsub!(/(!|\?|"|`|\\)/, ' ')
37
+ end
38
+
39
+ # Although espeak itself has default options
40
+ # I'm defining them here for easier generating
41
+ # command (with simple hash.merge)
42
+ #
43
+ def default_espeak_options
44
+ { :voice => 'en',
45
+ :pitch => 50,
46
+ :speed => 170 }
47
+ end
48
+
49
+ def execute_system_command(filename, options)
50
+ system([espeak_command(options), lame_command(filename)] * " | ")
51
+ end
52
+
53
+ def espeak_command(options)
54
+ %|espeak "#{options[:text]}" --stdout -v#{options[:voice]} -p#{options[:pitch]} -s#{options[:speed]}|
55
+ end
56
+
57
+ def lame_command(filename)
58
+ "lame -V2 - #{filename}"
59
+ end
60
+ end
data/lib/hash_ext.rb ADDED
@@ -0,0 +1,13 @@
1
+ # from ActiveSupport
2
+ class Hash
3
+ def symbolize_keys
4
+ inject({}) do |options, (key, value)|
5
+ options[(key.to_sym rescue key) || key] = value
6
+ options
7
+ end
8
+ end
9
+
10
+ def symbolize_keys!
11
+ self.replace(self.symbolize_keys)
12
+ end
13
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe ESpeak do
4
+
5
+ before :each do
6
+ @obj = Object.new
7
+ @obj.class_eval { include ESpeak }
8
+ end
9
+
10
+
11
+ describe "espeak" do
12
+ before :each do
13
+ @obj.stub!(:prepare_options)
14
+ end
15
+
16
+ it "should return nil if successfull" do
17
+ @obj.should_receive(:execute_system_command).and_return true
18
+ @obj.espeak("whatever", {}).should == nil
19
+ end
20
+
21
+ it "should raise if not successfull" do
22
+ @obj.should_receive(:execute_system_command).and_return false
23
+ lambda {
24
+ @obj.espeak("whatever", {})
25
+ }.should raise_error
26
+ end
27
+ end
28
+
29
+
30
+ describe "prepare_options" do
31
+ before :each do
32
+ @options = {:text => "Hello", 'speed' => 100}
33
+ @obj.stub!(:execute_system_command).and_return true
34
+ end
35
+
36
+ it "should symbolize keys" do
37
+ @obj.espeak("whatever", @options)
38
+ @options.should == @options.symbolize_keys
39
+ end
40
+
41
+ it "should raise if no value for :text key is provided" do
42
+ @options.delete(:text)
43
+ lambda {
44
+ @obj.espeak("whatever", @options)
45
+ }.should raise_error
46
+ end
47
+
48
+ it "should sanatize text" do
49
+ @obj.should_receive(:sanitize_text!).with(@options[:text])
50
+ @obj.espeak("whatever", @options)
51
+ end
52
+
53
+ it "should merge default_options with provided options" do
54
+ @default_options = {}
55
+ @obj.should_receive(:default_espeak_options).and_return(@default_options)
56
+ @default_options.should_receive(:merge).with(@options)
57
+ @obj.espeak("whatever", @options)
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Hash do
4
+ before :each do
5
+ @hash = {"a" => 1, "b" => 2, :c => "3"}
6
+ end
7
+
8
+ describe "symbolize_keys" do
9
+ it "should not alter instance" do
10
+ lambda {
11
+ @hash.symbolize_keys
12
+ }.should_not change { @hash.inspect }
13
+ end
14
+
15
+ it "should return hash with same values as itself contains, but with keys as symbols" do
16
+ @hash.symbolize_keys.should == {:a => 1, :b => 2, :c => "3"}
17
+ end
18
+ end
19
+
20
+ describe "symbolize_keys!" do
21
+ it "should alter instance such that all keys are symbols, and" do
22
+ @hash.symbolize_keys!
23
+ @hash.should == {:a => 1, :b => 2, :c => "3"}
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/../lib/espeak-ruby.rb'
2
+
3
+ require 'rubygems'
4
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: espeak-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Dejan Simic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-21 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "espeak-ruby is small Ruby API for utilizing \xE2\x80\x98espeak\xE2\x80\x99 and \xE2\x80\x98lame\xE2\x80\x99 to create Text-To-Speech mp3 files"
17
+ email: desimic@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.rdoc
26
+ - VERSION.yml
27
+ - lib/espeak-ruby.rb
28
+ - lib/hash_ext.rb
29
+ - spec/espeak_ruby_spec.rb
30
+ - spec/hash_ext_spec.rb
31
+ - spec/spec_helper.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/dejan/espeak-ruby
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --inline-source
39
+ - --charset=UTF-8
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 2
60
+ summary: "espeak-ruby is small Ruby API for utilizing \xE2\x80\x98espeak\xE2\x80\x99 and \xE2\x80\x98lame\xE2\x80\x99 to create Text-To-Speech mp3 files"
61
+ test_files: []
62
+