festivaltts4r 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of festivaltts4r might be problematic. Click here for more details.

@@ -1 +1,2 @@
1
+ # Include festivaltts4r lib subdirectory files.
1
2
  Dir[File.join(File.dirname(__FILE__), 'festivaltts4r/**/*.rb')].sort.each { |lib| require lib }
@@ -1,21 +1,88 @@
1
1
  #
2
2
  # Ruby Interface to festival tts system
3
- #
3
+ #
4
+ # Requires festivaltts and lame.
5
+ # Must be run in a UNIX environment.
6
+ #
7
+ # You can found more information in my english blog http://spejman-on-rails.blogspot.com
8
+ # or in the spanish one http://spejman.blogspot.com
9
+ #
10
+ # Work done by Sergio Espeja (http://www.sergioespeja.com) and Mike Mondragon (http://blog.mondragon.cc)
11
+ #
12
+ # It is free software, and may be redistributed under GPL license.
13
+ # Copyright (c) 2007 Sergio Espeja
14
+
4
15
 
5
16
  class String
6
17
 
7
- def to_speech(params={})
8
-
18
+ # Outputs the speech generated with festival tts and the string itself.
19
+ # Can handle these options:
20
+ # - text --> speech given text instead of the string itself.
21
+ # - language --> speech language desired (festival voices for given languages are required )
22
+ # - festival --> alternative festival program and options besides 'festival --tts'
23
+
24
+ def to_speech(params={})
9
25
  text = params[:text] || self
26
+ festival = params[:festival] || "festival --tts"
10
27
  language = "--language " + params[:language] if params[:language]
11
- system("echo \"#{text.to_s}\" | festival --tts #{language}")
28
+
29
+ cmd = "echo \"#{text.to_s}\" | #{festival} #{language} 2>&1"
30
+
31
+ self.class.execute cmd
32
+
12
33
  end
13
34
 
35
+ # Creates a file with name "filename" and with the generated with festival tts, the string itself and lame.
36
+ # Can handle one options:
37
+ # - text --> speech given text instead of the string itself.
38
+ # - text2wave - alternative text2wave program and options besides 'text2wave'
39
+ # - lame - alternative lame command other than 'lame --alt-preset cbr 16 -a --resample 11 --lowpass 5 --athtype 2 -X3 -'
14
40
  def to_mp3(filename, params={})
15
-
16
41
  text = params[:text] || self
42
+ text2wave = params[:text2wave] || "text2wave"
43
+ # athtype not on all LAMEs, i.e. --athtype 2
44
+ lame = params[:lame] || "lame --alt-preset cbr 16 -a --resample 11 --lowpass 5 -X3 -"
17
45
  raise "to_mp3 language option still not implemented" if params[:language]
18
- system("echo \"#{text.to_s}\" | text2wave | lame --alt-preset cbr 16 -a --resample 11 --lowpass 5 --athtype 2 -X3 - > #{filename} 2> /dev/null")
46
+ cmd = "echo \"#{text.to_s}\" | #{text2wave} | #{lame} > #{filename} 2>&1"
47
+
48
+ self.class.execute cmd
49
+ end
50
+
51
+ def self.execute(cmd)
52
+ begin
53
+ out = IO.popen(cmd)
54
+ Process.wait
55
+ e = $?.exitstatus
56
+ rescue StandardError => err
57
+ raise FestivalError.new(err)
58
+ else
59
+ raise FestivalSystemError.new("0 not returned:\n#{cmd}\n#{out.readlines}"
60
+ ) unless e.eql?(0)
61
+ end
19
62
  end
20
63
 
21
- end
64
+ end
65
+
66
+ ##
67
+ # A generic application error wrapper for festivaltts4r
68
+
69
+ class FestivalError < RuntimeError
70
+
71
+ ##
72
+ # The original exception
73
+
74
+ attr_accessor :original_exception
75
+
76
+ ##
77
+ # Creates a new FestivalError with +message+ and +original_exception+
78
+
79
+ def initialize(e)
80
+ exception = e.class == String ? StandardError.new(e) : e
81
+ @original_exception = exception
82
+ message = "festivaltts4r error: #{exception.message} (#{exception.class})"
83
+ super message
84
+ end
85
+
86
+ end
87
+
88
+ class FestivalSystemError < FestivalError; end
@@ -1,8 +1,8 @@
1
1
  module Festivaltts4r #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,11 +1,62 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'tempfile'
2
3
 
3
4
  class Festivaltts4rTest < Test::Unit::TestCase
4
5
 
5
6
  def setup
7
+ @mp3 = Tempfile.new('fake.mp3')
6
8
  end
7
-
8
- def test_truth
9
- assert true
9
+
10
+ def teardown
11
+ @mp3.unlink
12
+ end
13
+
14
+ def test_string_execute
15
+ assert_raises(FestivalSystemError) do
16
+ String.execute '/bin/false'
17
+ end
18
+
19
+ assert_nothing_raised do
20
+ String.execute '/bin/true'
21
+ end
22
+ end
23
+
24
+ def test_to_speech
25
+ assert_raises(FestivalSystemError) do
26
+ params = {:festival => '/bin/not-a-real-program'}
27
+ "hello world".to_speech(params)
28
+ end
29
+
30
+ assert_raises(FestivalSystemError) do
31
+ params = {:festival => '/bin/false'}
32
+ "hello world".to_speech(params)
33
+ end
34
+
35
+ assert_nothing_raised do
36
+ params = {:festival => '/bin/true'}
37
+ "hello world".to_speech(params)
38
+ end
39
+ end
40
+
41
+ def test_to_mp3
42
+ assert_raises(FestivalSystemError) do
43
+ params = {:lame => '/bin/false'}
44
+ "hello world".to_mp3(@mp3.path, params)
45
+ end
46
+
47
+ assert_nothing_raised do
48
+ params = {:text2wave => '/bin/true'}
49
+ params = {:lame => '/bin/true'}
50
+ "hello world".to_mp3(@mp3.path, params)
51
+ end
52
+ end
53
+
54
+ def test_to_mp3_really_creates_a_file
55
+ if system('which text2wave') && system('which lame')
56
+ assert_equal 0, @mp3.size
57
+ "hello world".to_mp3(@mp3.path, params={})
58
+ assert_equal true, File.exists?(@mp3)
59
+ assert @mp3.size > 0
60
+ end
10
61
  end
11
62
  end
metadata CHANGED
@@ -1,33 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: festivaltts4r
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2007-05-30 00:00:00 +02:00
8
- summary: "Text-to-speech for Ruby using festivaltts. Provides two new methods for String: to_speech and to_mp3. Requires festivaltts and lame."
9
- require_paths:
10
- - lib
11
- email: sergio.espeja@gmail.com
12
- homepage: http://festivaltts4r.rubyforge.org
13
- rubyforge_project: festivaltts4r
14
- description: "Text-to-speech for Ruby using festivaltts. Provides two new methods for String: to_speech and to_mp3. Requires festivaltts and lame."
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
25
- platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
4
+ version: 0.2.0
5
+ platform: ""
29
6
  authors:
30
7
  - Sergio Espeja
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2007-12-18 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.3.0
23
+ version:
24
+ description: "Text-to-speech for Ruby using festivaltts. Provides two new methods for String: to_speech and to_mp3. Requires festivaltts and lame."
25
+ email: sergio.espeja@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - CHANGELOG.txt
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
31
35
  files:
32
36
  - CHANGELOG.txt
33
37
  - History.txt
@@ -40,29 +44,32 @@ files:
40
44
  - setup.rb
41
45
  - test/festivaltts4r_test.rb
42
46
  - test/test_helper.rb
43
- test_files:
44
- - test/festivaltts4r_test.rb
47
+ has_rdoc: true
48
+ homepage: http://festivaltts4r.rubyforge.org
49
+ post_install_message:
45
50
  rdoc_options:
46
51
  - --main
47
52
  - README.txt
48
- extra_rdoc_files:
49
- - CHANGELOG.txt
50
- - History.txt
51
- - Manifest.txt
52
- - README.txt
53
- executables: []
54
-
55
- extensions: []
56
-
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
57
67
  requirements: []
58
68
 
59
- dependencies:
60
- - !ruby/object:Gem::Dependency
61
- name: hoe
62
- version_requirement:
63
- version_requirements: !ruby/object:Gem::Version::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 1.2.1
68
- version:
69
+ rubyforge_project: festivaltts4r
70
+ rubygems_version: 0.9.5
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: "Text-to-speech for Ruby using festivaltts. Provides two new methods for String: to_speech and to_mp3. Requires festivaltts and lame."
74
+ test_files:
75
+ - test/festivaltts4r_test.rb