ruby_speech 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module RubySpeech
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ module RubySpeech
2
+ module XML
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :Language
6
+ end # XML
7
+ end # RubySpeech
@@ -0,0 +1,13 @@
1
+ module RubySpeech
2
+ module XML
3
+ module Language
4
+ def language
5
+ read_attr :lang
6
+ end
7
+
8
+ def language=(l)
9
+ write_attr 'xml:lang', l
10
+ end
11
+ end # Language
12
+ end # XML
13
+ end # RubySpeech
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ruby_speech/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ruby_speech"
7
+ s.version = RubySpeech::VERSION
8
+ s.authors = ["Ben Langfeld"]
9
+ s.email = ["ben@langfeld.me"]
10
+ s.homepage = "https://github.com/mojolingo/ruby_speech"
11
+ s.summary = %q{A ruby library for TTS & ASR document preparation}
12
+ s.description = %q{Prepare SSML and GRXML documents with ease}
13
+
14
+ s.rubyforge_project = "ruby_speech"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency %q<niceogiri>, [">= 0.0.4"]
22
+ s.add_runtime_dependency %q<activesupport>, [">= 3.0.7"]
23
+
24
+ s.add_development_dependency %q<bundler>, ["~> 1.0.0"]
25
+ s.add_development_dependency %q<rspec>, ["~> 2.3.0"]
26
+ s.add_development_dependency %q<ci_reporter>, [">= 1.6.3"]
27
+ s.add_development_dependency %q<yard>, ["~> 0.6.0"]
28
+ s.add_development_dependency %q<rake>, [">= 0"]
29
+ s.add_development_dependency %q<mocha>, [">= 0"]
30
+ s.add_development_dependency %q<i18n>, [">= 0"]
31
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe Break do
6
+ its(:name) { should == 'break' }
7
+
8
+ describe "setting options in initializers" do
9
+ subject { Break.new :strength => :strong, :time => 3.seconds }
10
+
11
+ its(:strength) { should == :strong }
12
+ its(:time) { should == 3.seconds }
13
+ end
14
+
15
+ describe "#strength" do
16
+ before { subject.strength = :strong }
17
+
18
+ its(:strength) { should == :strong }
19
+
20
+ it "with a valid level" do
21
+ lambda { subject.strength = :none }.should_not raise_error
22
+ lambda { subject.strength = :'x-weak' }.should_not raise_error
23
+ lambda { subject.strength = :weak }.should_not raise_error
24
+ lambda { subject.strength = :medium }.should_not raise_error
25
+ lambda { subject.strength = :strong }.should_not raise_error
26
+ lambda { subject.strength = :'x-strong' }.should_not raise_error
27
+ end
28
+
29
+ it "with an invalid strength" do
30
+ lambda { subject.strength = :something }.should raise_error(ArgumentError, "You must specify a valid strength (:none, :\"x-weak\", :weak, :medium, :strong, :\"x-strong\")")
31
+ end
32
+ end
33
+
34
+ describe "#time" do
35
+ context "with a valid value" do
36
+ before { subject.time = 3.seconds }
37
+
38
+ its(:time) { should == 3.seconds }
39
+ end
40
+
41
+ context "with a negative value" do
42
+ it do
43
+ lambda { subject.time = -3.seconds }.should raise_error(ArgumentError, "You must specify a valid time (positive float value in seconds)")
44
+ end
45
+ end
46
+
47
+ context "with an invalid value" do
48
+ it do
49
+ lambda { subject.time = 'blah' }.should raise_error(ArgumentError, "You must specify a valid time (positive float value in seconds)")
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "<<" do
55
+ it "should always raise InvalidChildError" do
56
+ lambda { subject << 'anything' }.should raise_error(InvalidChildError, "A Break cannot contain children")
57
+ end
58
+ end
59
+
60
+ describe "comparing objects" do
61
+ it "should be equal if the content, strength and base uri are the same" do
62
+ Break.new(strength: :strong, time: 1.second, content: "Hello there").should == Break.new(strength: :strong, time: 1.second, content: "Hello there")
63
+ end
64
+
65
+ describe "when the content is different" do
66
+ it "should not be equal" do
67
+ Break.new(content: "Hello").should_not == Break.new(content: "Hello there")
68
+ end
69
+ end
70
+
71
+ describe "when the strength is different" do
72
+ it "should not be equal" do
73
+ Break.new(strength: :strong).should_not == Break.new(strength: :weak)
74
+ end
75
+ end
76
+
77
+ describe "when the time is different" do
78
+ it "should not be equal" do
79
+ Break.new(time: 1.second).should_not == Break.new(time: 2.seconds)
80
+ end
81
+ end
82
+ end
83
+ end # Break
84
+ end # SSML
85
+ end # RubySpeech
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe Emphasis do
6
+ its(:name) { should == 'emphasis' }
7
+
8
+ describe "setting options in initializers" do
9
+ subject { Emphasis.new :level => :strong }
10
+
11
+ its(:level) { should == :strong }
12
+ end
13
+
14
+ describe "#level" do
15
+ before { subject.level = :strong }
16
+
17
+ its(:level) { should == :strong }
18
+
19
+ it "with a valid level" do
20
+ lambda { subject.level = :strong }.should_not raise_error
21
+ lambda { subject.level = :moderate }.should_not raise_error
22
+ lambda { subject.level = :none }.should_not raise_error
23
+ lambda { subject.level = :reduced }.should_not raise_error
24
+ end
25
+
26
+ it "with an invalid level" do
27
+ lambda { subject.level = :something }.should raise_error(ArgumentError, "You must specify a valid level (:strong, :moderate, :none, :reduced)")
28
+ end
29
+ end
30
+
31
+ describe "comparing objects" do
32
+ it "should be equal if the content and level are the same" do
33
+ Emphasis.new(level: :strong, content: "Hello there").should == Emphasis.new(level: :strong, content: "Hello there")
34
+ end
35
+
36
+ describe "when the content is different" do
37
+ it "should not be equal" do
38
+ Emphasis.new(content: "Hello").should_not == Emphasis.new(content: "Hello there")
39
+ end
40
+ end
41
+
42
+ describe "when the level is different" do
43
+ it "should not be equal" do
44
+ Emphasis.new(level: :strong).should_not == Emphasis.new(level: :reduced)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "<<" do
50
+ it "should accept String" do
51
+ lambda { subject << 'anything' }.should_not raise_error
52
+ end
53
+
54
+ it "should accept Audio" do
55
+ pending
56
+ lambda { subject << Audio.new }.should_not raise_error
57
+ end
58
+
59
+ it "should accept Break" do
60
+ lambda { subject << Break.new }.should_not raise_error
61
+ end
62
+
63
+ it "should accept Emphasis" do
64
+ lambda { subject << Emphasis.new }.should_not raise_error
65
+ end
66
+
67
+ it "should accept Mark" do
68
+ pending
69
+ lambda { subject << Mark.new }.should_not raise_error
70
+ end
71
+
72
+ it "should accept Phoneme" do
73
+ pending
74
+ lambda { subject << Phoneme.new }.should_not raise_error
75
+ end
76
+
77
+ it "should accept Prosody" do
78
+ lambda { subject << Prosody.new }.should_not raise_error
79
+ end
80
+
81
+ it "should accept SayAs" do
82
+ lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
83
+ end
84
+
85
+ it "should accept Sub" do
86
+ pending
87
+ lambda { subject << Sub.new }.should_not raise_error
88
+ end
89
+
90
+ it "should accept Voice" do
91
+ lambda { subject << Voice.new }.should_not raise_error
92
+ end
93
+
94
+ it "should raise InvalidChildError with non-acceptable objects" do
95
+ lambda { subject << 1 }.should raise_error(InvalidChildError, "An Emphasis can only accept String, Audio, Break, Emphasis, Mark, Phoneme, Prosody, SayAs, Sub, Voice as children")
96
+ end
97
+ end
98
+ end # Emphasis
99
+ end # SSML
100
+ end # RubySpeech
@@ -0,0 +1,286 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe Prosody do
6
+ its(:name) { should == 'prosody' }
7
+
8
+ describe "setting options in initializers" do
9
+ subject { Prosody.new :pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10.seconds, :volume => :loud }
10
+
11
+ its(:pitch) { should == :medium }
12
+ its(:contour) { should == 'something' }
13
+ its(:range) { should == '20Hz' }
14
+ its(:rate) { should == 2 }
15
+ its(:duration) { should == 10.seconds }
16
+ its(:volume) { should == :loud }
17
+ end
18
+
19
+ describe "#pitch" do
20
+ context "with a pre-defined value" do
21
+ before { subject.pitch = :medium }
22
+
23
+ its(:pitch) { should == :medium }
24
+
25
+ it "with a valid value" do
26
+ lambda { subject.pitch = :'x-low' }.should_not raise_error
27
+ lambda { subject.pitch = :low }.should_not raise_error
28
+ lambda { subject.pitch = :medium }.should_not raise_error
29
+ lambda { subject.pitch = :high }.should_not raise_error
30
+ lambda { subject.pitch = :'x-high' }.should_not raise_error
31
+ lambda { subject.pitch = :default }.should_not raise_error
32
+ end
33
+
34
+ it "with an invalid value" do
35
+ lambda { subject.pitch = :something }.should raise_error(ArgumentError, "You must specify a valid pitch (\"[positive-number]Hz\", :\"x-low\", :low, :medium, :high, :\"x-high\", :default)")
36
+ end
37
+ end
38
+
39
+ context "with a Hertz value" do
40
+ describe "with a valid value" do
41
+ before { subject.pitch = '440Hz' }
42
+
43
+ its(:pitch) { should == '440Hz' }
44
+ end
45
+
46
+ it "with a negative value" do
47
+ lambda { subject.pitch = "-100Hz" }.should raise_error(ArgumentError, "You must specify a valid pitch (\"[positive-number]Hz\", :\"x-low\", :low, :medium, :high, :\"x-high\", :default)")
48
+ end
49
+
50
+ it "when missing 'hz'" do
51
+ lambda { subject.pitch = "440" }.should raise_error(ArgumentError, "You must specify a valid pitch (\"[positive-number]Hz\", :\"x-low\", :low, :medium, :high, :\"x-high\", :default)")
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "#contour" do
57
+ before { subject.contour = "blah" }
58
+
59
+ its(:contour) { should == "blah" }
60
+ end
61
+
62
+ describe "#range" do
63
+ context "with a pre-defined value" do
64
+ before { subject.range = :medium }
65
+
66
+ its(:range) { should == :medium }
67
+
68
+ it "with a valid value" do
69
+ lambda { subject.range = :'x-low' }.should_not raise_error
70
+ lambda { subject.range = :low }.should_not raise_error
71
+ lambda { subject.range = :medium }.should_not raise_error
72
+ lambda { subject.range = :high }.should_not raise_error
73
+ lambda { subject.range = :'x-high' }.should_not raise_error
74
+ lambda { subject.range = :default }.should_not raise_error
75
+ end
76
+
77
+ it "with an invalid value" do
78
+ lambda { subject.range = :something }.should raise_error(ArgumentError, "You must specify a valid range (\"[positive-number]Hz\", :\"x-low\", :low, :medium, :high, :\"x-high\", :default)")
79
+ end
80
+ end
81
+
82
+ context "with a Hertz value" do
83
+ describe "with a valid value" do
84
+ before { subject.range = '440Hz' }
85
+
86
+ its(:range) { should == '440Hz' }
87
+ end
88
+
89
+ it "with a negative value" do
90
+ lambda { subject.range = "-100Hz" }.should raise_error(ArgumentError, "You must specify a valid range (\"[positive-number]Hz\", :\"x-low\", :low, :medium, :high, :\"x-high\", :default)")
91
+ end
92
+
93
+ it "when missing 'hz'" do
94
+ lambda { subject.range = "440" }.should raise_error(ArgumentError, "You must specify a valid range (\"[positive-number]Hz\", :\"x-low\", :low, :medium, :high, :\"x-high\", :default)")
95
+ end
96
+ end
97
+ end
98
+
99
+ describe "#rate" do
100
+ context "with a pre-defined value" do
101
+ before { subject.rate = :medium }
102
+
103
+ its(:rate) { should == :medium }
104
+
105
+ it "with a valid value" do
106
+ lambda { subject.rate = :'x-slow' }.should_not raise_error
107
+ lambda { subject.rate = :slow }.should_not raise_error
108
+ lambda { subject.rate = :medium }.should_not raise_error
109
+ lambda { subject.rate = :fast }.should_not raise_error
110
+ lambda { subject.rate = :'x-fast' }.should_not raise_error
111
+ lambda { subject.rate = :default }.should_not raise_error
112
+ end
113
+
114
+ it "with an invalid value" do
115
+ lambda { subject.rate = :something }.should raise_error(ArgumentError, "You must specify a valid rate ([positive-number](multiplier), :\"x-slow\", :slow, :medium, :fast, :\"x-fast\", :default)")
116
+ end
117
+ end
118
+
119
+ context "with a multiplier value" do
120
+ describe "with a valid value" do
121
+ before { subject.rate = 1.5 }
122
+
123
+ its(:rate) { should == 1.5 }
124
+ end
125
+
126
+ it "with a negative value" do
127
+ lambda { subject.rate = -100 }.should raise_error(ArgumentError, "You must specify a valid rate ([positive-number](multiplier), :\"x-slow\", :slow, :medium, :fast, :\"x-fast\", :default)")
128
+ end
129
+ end
130
+ end
131
+
132
+ describe "#duration" do
133
+ context "with a valid value" do
134
+ before { subject.duration = 3.seconds }
135
+
136
+ its(:duration) { should == 3.seconds }
137
+ end
138
+
139
+ context "with a negative value" do
140
+ it do
141
+ lambda { subject.duration = -3.seconds }.should raise_error(ArgumentError, "You must specify a valid duration (positive float value in seconds)")
142
+ end
143
+ end
144
+
145
+ context "with an invalid value" do
146
+ it do
147
+ lambda { subject.duration = 'blah' }.should raise_error(ArgumentError, "You must specify a valid duration (positive float value in seconds)")
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "#volume" do
153
+ context "with a pre-defined value" do
154
+ before { subject.volume = :medium }
155
+
156
+ its(:volume) { should == :medium }
157
+
158
+ it "with a valid value" do
159
+ lambda { subject.volume = :silent }.should_not raise_error
160
+ lambda { subject.volume = :'x-soft' }.should_not raise_error
161
+ lambda { subject.volume = :soft }.should_not raise_error
162
+ lambda { subject.volume = :medium }.should_not raise_error
163
+ lambda { subject.volume = :loud }.should_not raise_error
164
+ lambda { subject.volume = :'x-loud' }.should_not raise_error
165
+ lambda { subject.volume = :default }.should_not raise_error
166
+ end
167
+
168
+ it "with an invalid value" do
169
+ lambda { subject.volume = :something }.should raise_error(ArgumentError, "You must specify a valid volume ([positive-number](0.0 -> 100.0), :silent, :\"x-soft\", :soft, :medium, :loud, :\"x-loud\", :default)")
170
+ end
171
+ end
172
+
173
+ context "with a multiplier" do
174
+ describe "with a valid value" do
175
+ before { subject.volume = 1.5 }
176
+
177
+ its(:volume) { should == 1.5 }
178
+ end
179
+
180
+ it "with a negative value" do
181
+ lambda { subject.volume = -1.5 }.should raise_error(ArgumentError, "You must specify a valid volume ([positive-number](0.0 -> 100.0), :silent, :\"x-soft\", :soft, :medium, :loud, :\"x-loud\", :default)")
182
+ lambda { subject.volume = 100.5 }.should raise_error(ArgumentError, "You must specify a valid volume ([positive-number](0.0 -> 100.0), :silent, :\"x-soft\", :soft, :medium, :loud, :\"x-loud\", :default)")
183
+ end
184
+ end
185
+ end
186
+
187
+ describe "comparing objects" do
188
+ it "should be equal if the content, strength and base uri are the same" do
189
+ Prosody.new(pitch: :medium, contour: "something", range: '20Hz', rate: 2, duration: 10.seconds, volume: :loud, content: "Hello there").should == Prosody.new(pitch: :medium, contour: "something", range: '20Hz', rate: 2, duration: 10.seconds, volume: :loud, content: "Hello there")
190
+ end
191
+
192
+ describe "when the content is different" do
193
+ it "should not be equal" do
194
+ Prosody.new(content: "Hello").should_not == Prosody.new(content: "Hello there")
195
+ end
196
+ end
197
+
198
+ describe "when the pitch is different" do
199
+ it "should not be equal" do
200
+ Prosody.new(pitch: :medium).should_not == Prosody.new(pitch: :high)
201
+ end
202
+ end
203
+
204
+ describe "when the contour is different" do
205
+ it "should not be equal" do
206
+ Prosody.new(contour: 'foo').should_not == Prosody.new(contour: 'bar')
207
+ end
208
+ end
209
+
210
+ describe "when the range is different" do
211
+ it "should not be equal" do
212
+ Prosody.new(range: '20Hz').should_not == Prosody.new(range: '30Hz')
213
+ end
214
+ end
215
+
216
+ describe "when the rate is different" do
217
+ it "should not be equal" do
218
+ Prosody.new(rate: 2).should_not == Prosody.new(rate: 3)
219
+ end
220
+ end
221
+
222
+ describe "when the duration is different" do
223
+ it "should not be equal" do
224
+ Prosody.new(duration: 10.seconds).should_not == Prosody.new(duration: 20.seconds)
225
+ end
226
+ end
227
+
228
+ describe "when the volume is different" do
229
+ it "should not be equal" do
230
+ Prosody.new(volume: :loud).should_not == Prosody.new(volume: :soft)
231
+ end
232
+ end
233
+ end
234
+
235
+ describe "<<" do
236
+ it "should accept String" do
237
+ lambda { subject << 'anything' }.should_not raise_error
238
+ end
239
+
240
+ it "should accept Audio" do
241
+ pending
242
+ lambda { subject << Audio.new }.should_not raise_error
243
+ end
244
+
245
+ it "should accept Break" do
246
+ lambda { subject << Break.new }.should_not raise_error
247
+ end
248
+
249
+ it "should accept Emphasis" do
250
+ lambda { subject << Emphasis.new }.should_not raise_error
251
+ end
252
+
253
+ it "should accept Mark" do
254
+ pending
255
+ lambda { subject << Mark.new }.should_not raise_error
256
+ end
257
+
258
+ it "should accept Phoneme" do
259
+ pending
260
+ lambda { subject << Phoneme.new }.should_not raise_error
261
+ end
262
+
263
+ it "should accept Prosody" do
264
+ lambda { subject << Prosody.new }.should_not raise_error
265
+ end
266
+
267
+ it "should accept SayAs" do
268
+ lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
269
+ end
270
+
271
+ it "should accept Sub" do
272
+ pending
273
+ lambda { subject << Sub.new }.should_not raise_error
274
+ end
275
+
276
+ it "should accept Voice" do
277
+ lambda { subject << Voice.new }.should_not raise_error
278
+ end
279
+
280
+ it "should raise InvalidChildError with non-acceptable objects" do
281
+ lambda { subject << 1 }.should raise_error(InvalidChildError, "A Prosody can only accept String, Audio, Break, Emphasis, Mark, P, Phoneme, Prosody, SayAs, Sub, S, Voice as children")
282
+ end
283
+ end
284
+ end # Prosody
285
+ end # SSML
286
+ end # RubySpeech