espeak-ruby 0.4.0 → 1.0.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.

@@ -1,51 +1,61 @@
1
- = espeak-ruby
1
+ espeak-ruby
2
+ ===========
2
3
 
3
- espeak-ruby is small Ruby API for utilizing 'espeak' and 'lame' to create Text-To-Speech mp3 files.
4
+ espeak-ruby is a small Ruby API for utilizing [espeak](http://espeak.sourceforge.net) and [lame](http://lame.sourceforge.net/) to create Text-To-Speech mp3 files.
5
+ See the [live demo](http://rors.org/demos/espeak-ruby).
4
6
 
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
+ Install
8
+ -------
7
9
 
8
- == Install
10
+ Add _espeak-ruby_ to Gemfile
9
11
 
10
- gem install espeak-ruby
12
+ ```ruby
13
+ gem "espeak-ruby", require: "espeak"
14
+ ```
11
15
 
12
- == Example
16
+ Example
17
+ -------
13
18
 
14
- require 'rubygems'
15
- require 'espeak-ruby'
16
-
17
- include ESpeak
18
-
19
- # Creates hello.mp3 file
20
- espeak("hello.mp3", :text => "Hello World")
19
+ ```ruby
20
+ # Speaks "YO!"
21
+ speech = ESpeak::Speech.new("YO!")
22
+ speech.speak # invokes espeak
21
23
 
22
- # Creates /home/espeak/hello-de.mp3 file
23
- espeak("/home/espeak/hello-de.mp3", :text => "Hallo Welt", :voice => "de")
24
+ # Creates hello-de.mp3 file
25
+ speech = ESpeak::Speech.new("Hallo Welt", voice: "de")
26
+ speech.save("hello-de.mp3") # invokes espeak + lame
27
+ ```
24
28
 
25
- == Features
29
+ Features
30
+ --------
26
31
 
27
32
  Currently only subset of espeak features is supported.
28
33
 
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
- :quiet => true # prevent espeak-ruby from printing to stdout. (default false)
33
-
34
+ ```ruby
35
+ :voice => 'en' # use voice file of this name from espeak-data/voices
36
+ :pitch => 50 # pitch adjustment, 0 to 99
37
+ :speed => 170 # speed in words per minute, 80 to 370
38
+ ```
34
39
 
35
40
  These are default values, and they can be easily overridden:
36
41
 
37
- espeak("zdravo.mp3", :text => "Zdravo svete", :voice => "sr", :pitch => 90, :speed => 200)
42
+ ```ruby
43
+ ESpeak::Speech.new("Zdravo svete", voice: "sr", pitch: 90, speed: 200).speak
44
+ ```
38
45
 
39
- == Requirements
46
+ Requirements
47
+ ------------
40
48
 
41
- * http://espeak.sourceforge.net
42
- * http://lame.sourceforge.net/index.php
49
+ * <http://espeak.sourceforge.net>
50
+ * <http://lame.sourceforge.net>
43
51
 
44
- == Related
52
+ Related
53
+ -------
45
54
 
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
55
+ * [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
56
 
48
- == Licence
57
+ Licence
58
+ -------
49
59
 
50
60
  Copyright (c) 2008 Dejan Simic
51
61
 
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- require 'rake'
1
+ require 'rake/testtask'
2
2
 
3
- desc 'Run all specs'
4
- task :spec do
5
- system('spec spec')
6
- end
3
+ desc 'Default: run tests'
4
+ task :default => :test
7
5
 
8
- desc 'Default: run specs.'
9
- task :default => :spec
6
+ desc 'Test espeak-ruby'
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = true
11
+ end
10
12
 
data/lib/espeak.rb ADDED
@@ -0,0 +1,3 @@
1
+ module ESpeak
2
+ autoload :Speech, 'espeak/speech'
3
+ end
@@ -0,0 +1,72 @@
1
+ module ESpeak
2
+ class Speech
3
+ attr_reader :options, :text
4
+
5
+ # filename - The file that will be generated
6
+ # options - Posible key, values
7
+ # :voice - use voice file of this name from espeak-data/voices. ie 'en', 'de', ...
8
+ # :pitch - pitch adjustment, 0 to 99
9
+ # :speed - speed in words per minute, 80 to 370
10
+ # :quiet - remove printing to stdout. Affects only lame (default false)
11
+ #
12
+ def initialize(text, options={})
13
+ @text = text
14
+ @options = options
15
+ end
16
+
17
+ # Speaks text
18
+ #
19
+ def speak
20
+ system(espeak_command(command_options))
21
+ end
22
+
23
+ # Generates mp3 file as a result of
24
+ # Text-To-Speech conversion.
25
+ #
26
+ def save(filename)
27
+ system(espeak_command(command_options, "--stdout") + " | " + lame_command(filename, command_options))
28
+ end
29
+
30
+ # espeak dies handling some chars
31
+ # this function sanitizes text
32
+ #
33
+ def sanitized_text
34
+ @text.gsub(/(!|\?|"|`|\\)/, ' ').strip
35
+ end
36
+
37
+ private
38
+
39
+ def command_options
40
+ default_options.merge(symbolize_keys(options))
41
+ end
42
+
43
+ # Although espeak itself has default options
44
+ # I'm defining them here for easier generating
45
+ # command (with simple hash.merge)
46
+ #
47
+ def default_options
48
+ { :voice => 'en',
49
+ :pitch => 50,
50
+ :speed => 170,
51
+ :quiet => true }
52
+ end
53
+
54
+ def espeak_command(options, flags="")
55
+ %|espeak "#{sanitized_text}" #{flags} -v#{options[:voice]} -p#{options[:pitch]} -s#{options[:speed]}|
56
+ end
57
+
58
+ def lame_command(filename, options)
59
+ "lame -V2 - #{filename} #{'--quiet' if options[:quiet] == true}"
60
+ end
61
+
62
+ def execute_system_command(filename, options)
63
+ end
64
+
65
+ def symbolize_keys(hash)
66
+ hash.inject({}) do |options, (key, value)|
67
+ options[(key.to_sym rescue key) || key] = value
68
+ options
69
+ end
70
+ end
71
+ end
72
+ end
data/lib/hash_ext.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  # from ActiveSupport
2
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
3
+
8
4
  end
9
5
 
10
6
  def symbolize_keys!
11
7
  self.replace(self.symbolize_keys)
12
8
  end
13
- end
9
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+ require 'fileutils'
3
+
4
+ class SpeechTest < Test::Unit::TestCase
5
+ include ESpeak
6
+
7
+ def test_sanitized_text
8
+ assert_equal "Hello", Speech.new("Hello!").sanitized_text
9
+ assert_equal "Hello World", Speech.new("Hello?World").sanitized_text
10
+ end
11
+
12
+ def test_save
13
+ FileUtils.rm_rf("test/tmp")
14
+ FileUtils.mkdir_p("test/tmp")
15
+ assert Speech.new("Hello!").save('test/tmp/test.mp3')
16
+ assert File.exist?("test/tmp/test.mp3"), "Mp3 file not generated"
17
+ FileUtils.rm_rf("test/tmp")
18
+ end
19
+ end
20
+
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'espeak'
metadata CHANGED
@@ -1,73 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: espeak-ruby
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Dejan Simic
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-17 00:00:00 +02:00
19
- default_executable:
12
+ date: 2013-01-12 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
- 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"
14
+ description: espeak-ruby is small Ruby API for utilizing ‘espeak’ and ‘lame’ to create
15
+ Text-To-Speech mp3 files
23
16
  email: desimic@gmail.com
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - Rakefile
32
- - lib/espeak-ruby.rb
22
+ - lib/espeak/speech.rb
23
+ - lib/espeak.rb
33
24
  - lib/hash_ext.rb
34
- - spec/espeak_ruby_spec.rb
35
- - spec/hash_ext_spec.rb
36
- - spec/spec_helper.rb
37
- - README.rdoc
38
- has_rdoc: true
25
+ - test/cases/speech_test.rb
26
+ - test/test_helper.rb
27
+ - README.md
39
28
  homepage: http://github.com/dejan/espeak-ruby
40
29
  licenses: []
41
-
42
30
  post_install_message:
43
31
  rdoc_options: []
44
-
45
- require_paths:
32
+ require_paths:
46
33
  - lib
47
- required_ruby_version: !ruby/object:Gem::Requirement
34
+ required_ruby_version: !ruby/object:Gem::Requirement
48
35
  none: false
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- hash: 3
53
- segments:
54
- - 0
55
- version: "0"
56
- required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
41
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
65
46
  requirements: []
66
-
67
47
  rubyforge_project:
68
- rubygems_version: 1.6.2
48
+ rubygems_version: 1.8.23
69
49
  signing_key:
70
50
  specification_version: 3
71
- 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"
51
+ summary: espeak-ruby is small Ruby API for utilizing ‘espeak’ and ‘lame’ to create
52
+ Text-To-Speech mp3 files
72
53
  test_files: []
73
-
data/lib/espeak-ruby.rb DELETED
@@ -1,61 +0,0 @@
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
- # :quiet - remove printing to stdout. Affects only lame (default false)
15
- #
16
- def espeak(filename, options)
17
- if execute_system_command(filename, prepare_options(options))
18
- nil
19
- else
20
- raise "Error while running espeak. You don't seem to have espeak or lame installed ..."
21
- end
22
- end
23
-
24
- private
25
-
26
- def prepare_options(options)
27
- options.symbolize_keys!
28
- raise "You must provide value for :text key in options" unless options[:text]
29
- sanitize_text!(options[:text])
30
- default_espeak_options.merge(options)
31
- end
32
-
33
- # espeak has problems handling
34
- # some characters (it dies)
35
- #
36
- def sanitize_text!(text)
37
- text.gsub!(/(!|\?|"|`|\\)/, ' ')
38
- end
39
-
40
- # Although espeak itself has default options
41
- # I'm defining them here for easier generating
42
- # command (with simple hash.merge)
43
- #
44
- def default_espeak_options
45
- { :voice => 'en',
46
- :pitch => 50,
47
- :speed => 170 }
48
- end
49
-
50
- def execute_system_command(filename, options)
51
- system([espeak_command(options), lame_command(filename, options)] * " | ")
52
- end
53
-
54
- def espeak_command(options)
55
- %|espeak "#{options[:text]}" --stdout -v#{options[:voice]} -p#{options[:pitch]} -s#{options[:speed]}|
56
- end
57
-
58
- def lame_command(filename, options)
59
- "lame -V2 - #{filename} #{'--quiet' if options[:quiet] == true}"
60
- end
61
- end
@@ -1,61 +0,0 @@
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
@@ -1,26 +0,0 @@
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
data/spec/spec_helper.rb DELETED
@@ -1,4 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/espeak-ruby.rb'
2
-
3
- require 'rubygems'
4
- require 'active_support'