ruby_speech 2.1.0-java

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.
Files changed (90) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +17 -0
  4. data/CHANGELOG.md +144 -0
  5. data/Gemfile +3 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE.md +20 -0
  8. data/README.md +314 -0
  9. data/Rakefile +34 -0
  10. data/assets/grammar-core.xsd +317 -0
  11. data/assets/grammar.xsd +37 -0
  12. data/assets/synthesis-core.xsd +445 -0
  13. data/assets/synthesis.xsd +63 -0
  14. data/assets/xml.xsd +287 -0
  15. data/ext/ruby_speech/RubySpeechGRXMLMatcher.java +64 -0
  16. data/ext/ruby_speech/RubySpeechService.java +23 -0
  17. data/ext/ruby_speech/extconf.rb +7 -0
  18. data/ext/ruby_speech/ruby_speech.c +97 -0
  19. data/lib/ruby_speech/generic_element.rb +169 -0
  20. data/lib/ruby_speech/grxml/element.rb +29 -0
  21. data/lib/ruby_speech/grxml/grammar.rb +189 -0
  22. data/lib/ruby_speech/grxml/item.rb +144 -0
  23. data/lib/ruby_speech/grxml/match.rb +16 -0
  24. data/lib/ruby_speech/grxml/matcher.rb +126 -0
  25. data/lib/ruby_speech/grxml/max_match.rb +6 -0
  26. data/lib/ruby_speech/grxml/no_match.rb +10 -0
  27. data/lib/ruby_speech/grxml/one_of.rb +31 -0
  28. data/lib/ruby_speech/grxml/potential_match.rb +10 -0
  29. data/lib/ruby_speech/grxml/rule.rb +73 -0
  30. data/lib/ruby_speech/grxml/ruleref.rb +69 -0
  31. data/lib/ruby_speech/grxml/tag.rb +29 -0
  32. data/lib/ruby_speech/grxml/token.rb +31 -0
  33. data/lib/ruby_speech/grxml.rb +39 -0
  34. data/lib/ruby_speech/nlsml/builder.rb +34 -0
  35. data/lib/ruby_speech/nlsml/document.rb +120 -0
  36. data/lib/ruby_speech/nlsml.rb +18 -0
  37. data/lib/ruby_speech/ruby_speech.jar +0 -0
  38. data/lib/ruby_speech/ssml/audio.rb +47 -0
  39. data/lib/ruby_speech/ssml/break.rb +62 -0
  40. data/lib/ruby_speech/ssml/desc.rb +24 -0
  41. data/lib/ruby_speech/ssml/element.rb +23 -0
  42. data/lib/ruby_speech/ssml/emphasis.rb +44 -0
  43. data/lib/ruby_speech/ssml/mark.rb +43 -0
  44. data/lib/ruby_speech/ssml/p.rb +25 -0
  45. data/lib/ruby_speech/ssml/phoneme.rb +72 -0
  46. data/lib/ruby_speech/ssml/prosody.rb +172 -0
  47. data/lib/ruby_speech/ssml/s.rb +25 -0
  48. data/lib/ruby_speech/ssml/say_as.rb +100 -0
  49. data/lib/ruby_speech/ssml/speak.rb +27 -0
  50. data/lib/ruby_speech/ssml/sub.rb +42 -0
  51. data/lib/ruby_speech/ssml/voice.rb +108 -0
  52. data/lib/ruby_speech/ssml.rb +39 -0
  53. data/lib/ruby_speech/version.rb +3 -0
  54. data/lib/ruby_speech/xml/language.rb +13 -0
  55. data/lib/ruby_speech/xml.rb +11 -0
  56. data/lib/ruby_speech.rb +36 -0
  57. data/ruby_speech.gemspec +42 -0
  58. data/spec/ruby_speech/grxml/grammar_spec.rb +341 -0
  59. data/spec/ruby_speech/grxml/item_spec.rb +192 -0
  60. data/spec/ruby_speech/grxml/match_spec.rb +15 -0
  61. data/spec/ruby_speech/grxml/matcher_spec.rb +688 -0
  62. data/spec/ruby_speech/grxml/max_match_spec.rb +17 -0
  63. data/spec/ruby_speech/grxml/no_match_spec.rb +17 -0
  64. data/spec/ruby_speech/grxml/one_of_spec.rb +49 -0
  65. data/spec/ruby_speech/grxml/potential_match_spec.rb +17 -0
  66. data/spec/ruby_speech/grxml/rule_spec.rb +125 -0
  67. data/spec/ruby_speech/grxml/ruleref_spec.rb +55 -0
  68. data/spec/ruby_speech/grxml/tag_spec.rb +41 -0
  69. data/spec/ruby_speech/grxml/token_spec.rb +62 -0
  70. data/spec/ruby_speech/grxml_spec.rb +339 -0
  71. data/spec/ruby_speech/nlsml_spec.rb +353 -0
  72. data/spec/ruby_speech/ssml/audio_spec.rb +121 -0
  73. data/spec/ruby_speech/ssml/break_spec.rb +100 -0
  74. data/spec/ruby_speech/ssml/desc_spec.rb +57 -0
  75. data/spec/ruby_speech/ssml/emphasis_spec.rb +110 -0
  76. data/spec/ruby_speech/ssml/mark_spec.rb +53 -0
  77. data/spec/ruby_speech/ssml/p_spec.rb +96 -0
  78. data/spec/ruby_speech/ssml/phoneme_spec.rb +65 -0
  79. data/spec/ruby_speech/ssml/prosody_spec.rb +309 -0
  80. data/spec/ruby_speech/ssml/s_spec.rb +92 -0
  81. data/spec/ruby_speech/ssml/say_as_spec.rb +71 -0
  82. data/spec/ruby_speech/ssml/speak_spec.rb +166 -0
  83. data/spec/ruby_speech/ssml/sub_spec.rb +57 -0
  84. data/spec/ruby_speech/ssml/voice_spec.rb +200 -0
  85. data/spec/ruby_speech/ssml_spec.rb +285 -0
  86. data/spec/ruby_speech_spec.rb +124 -0
  87. data/spec/spec_helper.rb +21 -0
  88. data/spec/support/match_examples.rb +43 -0
  89. data/spec/support/matchers.rb +46 -0
  90. metadata +405 -0
@@ -0,0 +1,309 @@
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
+ it 'registers itself' do
20
+ Element.class_from_registration(:prosody).should == Prosody
21
+ end
22
+
23
+ describe "from a document" do
24
+ let(:document) { '<prosody pitch="medium" contour="something" range="20Hz" rate="2" duration="10" volume="loud"/>' }
25
+
26
+ subject { Element.import document }
27
+
28
+ it { should be_instance_of Prosody }
29
+
30
+ its(:pitch) { should == :medium }
31
+ its(:contour) { should == 'something' }
32
+ its(:range) { should == '20Hz' }
33
+ its(:rate) { should == 2 }
34
+ its(:duration) { should == 10.seconds }
35
+ its(:volume) { should == :loud }
36
+ end
37
+
38
+ describe "#pitch" do
39
+ context "with a pre-defined value" do
40
+ before { subject.pitch = :medium }
41
+
42
+ its(:pitch) { should == :medium }
43
+
44
+ it "with a valid value" do
45
+ lambda { subject.pitch = :'x-low' }.should_not raise_error
46
+ lambda { subject.pitch = :low }.should_not raise_error
47
+ lambda { subject.pitch = :medium }.should_not raise_error
48
+ lambda { subject.pitch = :high }.should_not raise_error
49
+ lambda { subject.pitch = :'x-high' }.should_not raise_error
50
+ lambda { subject.pitch = :default }.should_not raise_error
51
+ end
52
+
53
+ it "with an invalid value" do
54
+ 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)")
55
+ end
56
+ end
57
+
58
+ context "with a Hertz value" do
59
+ describe "with a valid value" do
60
+ before { subject.pitch = '440Hz' }
61
+
62
+ its(:pitch) { should == '440Hz' }
63
+ end
64
+
65
+ it "with a negative value" do
66
+ 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)")
67
+ end
68
+
69
+ it "when missing 'hz'" do
70
+ 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)")
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "#contour" do
76
+ before { subject.contour = "blah" }
77
+
78
+ its(:contour) { should == "blah" }
79
+ end
80
+
81
+ describe "#range" do
82
+ context "with a pre-defined value" do
83
+ before { subject.range = :medium }
84
+
85
+ its(:range) { should == :medium }
86
+
87
+ it "with a valid value" do
88
+ lambda { subject.range = :'x-low' }.should_not raise_error
89
+ lambda { subject.range = :low }.should_not raise_error
90
+ lambda { subject.range = :medium }.should_not raise_error
91
+ lambda { subject.range = :high }.should_not raise_error
92
+ lambda { subject.range = :'x-high' }.should_not raise_error
93
+ lambda { subject.range = :default }.should_not raise_error
94
+ end
95
+
96
+ it "with an invalid value" do
97
+ 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)")
98
+ end
99
+ end
100
+
101
+ context "with a Hertz value" do
102
+ describe "with a valid value" do
103
+ before { subject.range = '440Hz' }
104
+
105
+ its(:range) { should == '440Hz' }
106
+ end
107
+
108
+ it "with a negative value" do
109
+ 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)")
110
+ end
111
+
112
+ it "when missing 'hz'" do
113
+ 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)")
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#rate" do
119
+ context "with a pre-defined value" do
120
+ before { subject.rate = :medium }
121
+
122
+ its(:rate) { should == :medium }
123
+
124
+ it "with a valid value" do
125
+ lambda { subject.rate = :'x-slow' }.should_not raise_error
126
+ lambda { subject.rate = :slow }.should_not raise_error
127
+ lambda { subject.rate = :medium }.should_not raise_error
128
+ lambda { subject.rate = :fast }.should_not raise_error
129
+ lambda { subject.rate = :'x-fast' }.should_not raise_error
130
+ lambda { subject.rate = :default }.should_not raise_error
131
+ end
132
+
133
+ it "with an invalid value" do
134
+ 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)")
135
+ end
136
+ end
137
+
138
+ context "with a multiplier value" do
139
+ describe "with a valid value" do
140
+ before { subject.rate = 1.5 }
141
+
142
+ its(:rate) { should == 1.5 }
143
+ end
144
+
145
+ it "with a negative value" do
146
+ 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)")
147
+ end
148
+ end
149
+ end
150
+
151
+ describe "#duration" do
152
+ context "with a valid value" do
153
+ before { subject.duration = 3.seconds }
154
+
155
+ its(:duration) { should == 3.seconds }
156
+ end
157
+
158
+ context "with a negative value" do
159
+ it do
160
+ lambda { subject.duration = -3.seconds }.should raise_error(ArgumentError, "You must specify a valid duration (positive float value in seconds)")
161
+ end
162
+ end
163
+
164
+ context "with an invalid value" do
165
+ it do
166
+ lambda { subject.duration = 'blah' }.should raise_error(ArgumentError, "You must specify a valid duration (positive float value in seconds)")
167
+ end
168
+ end
169
+ end
170
+
171
+ describe "#volume" do
172
+ context "with a pre-defined value" do
173
+ before { subject.volume = :medium }
174
+
175
+ its(:volume) { should == :medium }
176
+
177
+ it "with a valid value" do
178
+ lambda { subject.volume = :silent }.should_not raise_error
179
+ lambda { subject.volume = :'x-soft' }.should_not raise_error
180
+ lambda { subject.volume = :soft }.should_not raise_error
181
+ lambda { subject.volume = :medium }.should_not raise_error
182
+ lambda { subject.volume = :loud }.should_not raise_error
183
+ lambda { subject.volume = :'x-loud' }.should_not raise_error
184
+ lambda { subject.volume = :default }.should_not raise_error
185
+ end
186
+
187
+ it "with an invalid value" do
188
+ 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)")
189
+ end
190
+ end
191
+
192
+ context "with a multiplier" do
193
+ describe "with a valid value" do
194
+ before { subject.volume = 1.5 }
195
+
196
+ its(:volume) { should == 1.5 }
197
+ end
198
+
199
+ it "with a negative value" do
200
+ 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)")
201
+ 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)")
202
+ end
203
+ end
204
+ end
205
+
206
+ describe "comparing objects" do
207
+ it "should be equal if the content, strength and base uri are the same" do
208
+ 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")
209
+ end
210
+
211
+ describe "when the content is different" do
212
+ it "should not be equal" do
213
+ Prosody.new(:content => "Hello").should_not == Prosody.new(:content => "Hello there")
214
+ end
215
+ end
216
+
217
+ describe "when the pitch is different" do
218
+ it "should not be equal" do
219
+ Prosody.new(:pitch => :medium).should_not == Prosody.new(:pitch => :high)
220
+ end
221
+ end
222
+
223
+ describe "when the contour is different" do
224
+ it "should not be equal" do
225
+ Prosody.new(:contour => 'foo').should_not == Prosody.new(:contour => 'bar')
226
+ end
227
+ end
228
+
229
+ describe "when the range is different" do
230
+ it "should not be equal" do
231
+ Prosody.new(:range => '20Hz').should_not == Prosody.new(:range => '30Hz')
232
+ end
233
+ end
234
+
235
+ describe "when the rate is different" do
236
+ it "should not be equal" do
237
+ Prosody.new(:rate => 2).should_not == Prosody.new(:rate => 3)
238
+ end
239
+ end
240
+
241
+ describe "when the duration is different" do
242
+ it "should not be equal" do
243
+ Prosody.new(:duration => 10.seconds).should_not == Prosody.new(:duration => 20.seconds)
244
+ end
245
+ end
246
+
247
+ describe "when the volume is different" do
248
+ it "should not be equal" do
249
+ Prosody.new(:volume => :loud).should_not == Prosody.new(:volume => :soft)
250
+ end
251
+ end
252
+ end
253
+
254
+ describe "<<" do
255
+ it "should accept String" do
256
+ lambda { subject << 'anything' }.should_not raise_error
257
+ end
258
+
259
+ it "should accept Audio" do
260
+ lambda { subject << Audio.new }.should_not raise_error
261
+ end
262
+
263
+ it "should accept Break" do
264
+ lambda { subject << Break.new }.should_not raise_error
265
+ end
266
+
267
+ it "should accept Emphasis" do
268
+ lambda { subject << Emphasis.new }.should_not raise_error
269
+ end
270
+
271
+ it "should accept Mark" do
272
+ lambda { subject << Mark.new }.should_not raise_error
273
+ end
274
+
275
+ it "should accept P" do
276
+ lambda { subject << P.new }.should_not raise_error
277
+ end
278
+
279
+ it "should accept Phoneme" do
280
+ lambda { subject << Phoneme.new }.should_not raise_error
281
+ end
282
+
283
+ it "should accept Prosody" do
284
+ lambda { subject << Prosody.new }.should_not raise_error
285
+ end
286
+
287
+ it "should accept S" do
288
+ lambda { subject << S.new }.should_not raise_error
289
+ end
290
+
291
+ it "should accept SayAs" do
292
+ lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
293
+ end
294
+
295
+ it "should accept Sub" do
296
+ lambda { subject << Sub.new }.should_not raise_error
297
+ end
298
+
299
+ it "should accept Voice" do
300
+ lambda { subject << Voice.new }.should_not raise_error
301
+ end
302
+
303
+ it "should raise InvalidChildError with non-acceptable objects" do
304
+ 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")
305
+ end
306
+ end
307
+ end # Prosody
308
+ end # SSML
309
+ end # RubySpeech
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe S do
6
+ its(:name) { should == 's' }
7
+
8
+ describe "setting options in initializers" do
9
+ subject { S.new :language => 'jp' }
10
+
11
+ its(:language) { should == 'jp' }
12
+ end
13
+
14
+ it 'registers itself' do
15
+ Element.class_from_registration(:s).should == S
16
+ end
17
+
18
+ describe "from a document" do
19
+ let(:document) { '<s>foo</s>' }
20
+
21
+ subject { Element.import document }
22
+
23
+ it { should be_instance_of S }
24
+ its(:content) { should == 'foo' }
25
+ end
26
+
27
+ describe "comparing objects" do
28
+ it "should be equal if the content and language are the same" do
29
+ S.new(:language => 'jp', :content => "Hello there").should == S.new(:language => 'jp', :content => "Hello there")
30
+ end
31
+
32
+ describe "when the content is different" do
33
+ it "should not be equal" do
34
+ S.new(:content => "Hello").should_not == S.new(:content => "Hello there")
35
+ end
36
+ end
37
+
38
+ describe "when the language is different" do
39
+ it "should not be equal" do
40
+ S.new(:language => 'jp').should_not == S.new(:language => 'en')
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "<<" do
46
+ it "should accept String" do
47
+ lambda { subject << 'anything' }.should_not raise_error
48
+ end
49
+
50
+ it "should accept Audio" do
51
+ lambda { subject << Audio.new }.should_not raise_error
52
+ end
53
+
54
+ it "should accept Break" do
55
+ lambda { subject << Break.new }.should_not raise_error
56
+ end
57
+
58
+ it "should accept Emphasis" do
59
+ lambda { subject << Emphasis.new }.should_not raise_error
60
+ end
61
+
62
+ it "should accept Mark" do
63
+ lambda { subject << Mark.new }.should_not raise_error
64
+ end
65
+
66
+ it "should accept Phoneme" do
67
+ lambda { subject << Phoneme.new }.should_not raise_error
68
+ end
69
+
70
+ it "should accept Prosody" do
71
+ lambda { subject << Prosody.new }.should_not raise_error
72
+ end
73
+
74
+ it "should accept SayAs" do
75
+ lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
76
+ end
77
+
78
+ it "should accept Sub" do
79
+ lambda { subject << Sub.new }.should_not raise_error
80
+ end
81
+
82
+ it "should accept Voice" do
83
+ lambda { subject << Voice.new }.should_not raise_error
84
+ end
85
+
86
+ it "should raise InvalidChildError with non-acceptable objects" do
87
+ lambda { subject << 1 }.should raise_error(InvalidChildError, "An S can only accept String, Audio, Break, Emphasis, Mark, Phoneme, Prosody, SayAs, Sub, Voice as children")
88
+ end
89
+ end
90
+ end # S
91
+ end # SSML
92
+ end # RubySpeech
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe SayAs do
6
+ subject { SayAs.new :interpret_as => 'one', :format => 'two', :detail => 'three' }
7
+
8
+ its(:name) { should == 'say-as' }
9
+
10
+ its(:interpret_as) { should == 'one' }
11
+ its(:format) { should == 'two' }
12
+ its(:detail) { should == 'three' }
13
+
14
+ it 'registers itself' do
15
+ Element.class_from_registration(:'say-as').should == SayAs
16
+ end
17
+
18
+ describe "from a document" do
19
+ let(:document) { '<say-as interpret-as="one" format="two" detail="three"/>' }
20
+
21
+ subject { Element.import document }
22
+
23
+ it { should be_instance_of SayAs }
24
+
25
+ its(:interpret_as) { should == 'one' }
26
+ its(:format) { should == 'two' }
27
+ its(:detail) { should == 'three' }
28
+ end
29
+
30
+ describe "comparing objects" do
31
+ it "should be equal if the content, interpret_as, format, age, variant, name are the same" do
32
+ SayAs.new(:interpret_as => 'jp', :format => 'foo', :detail => 'bar', :content => "hello").should == SayAs.new(:interpret_as => 'jp', :format => 'foo', :detail => 'bar', :content => "hello")
33
+ end
34
+
35
+ describe "when the content is different" do
36
+ it "should not be equal" do
37
+ SayAs.new(:interpret_as => 'jp', :content => "Hello").should_not == SayAs.new(:interpret_as => 'jp', :content => "Hello there")
38
+ end
39
+ end
40
+
41
+ describe "when the interpret_as is different" do
42
+ it "should not be equal" do
43
+ SayAs.new(:interpret_as => "Hello").should_not == SayAs.new(:interpret_as => "Hello there")
44
+ end
45
+ end
46
+
47
+ describe "when the format is different" do
48
+ it "should not be equal" do
49
+ SayAs.new(:interpret_as => 'jp', :format => 'foo').should_not == SayAs.new(:interpret_as => 'jp', :format => 'bar')
50
+ end
51
+ end
52
+
53
+ describe "when the detail is different" do
54
+ it "should not be equal" do
55
+ SayAs.new(:interpret_as => 'jp', :detail => 'foo').should_not == SayAs.new(:interpret_as => 'jp', :detail => 'bar')
56
+ end
57
+ end
58
+ end
59
+
60
+ describe "<<" do
61
+ it "should accept String" do
62
+ lambda { subject << 'anything' }.should_not raise_error
63
+ end
64
+
65
+ it "should raise InvalidChildError with non-acceptable objects" do
66
+ lambda { subject << Voice.new }.should raise_error(InvalidChildError, "A SayAs can only accept Strings as children")
67
+ end
68
+ end
69
+ end # SayAs
70
+ end # SSML
71
+ end # RubySpeech
@@ -0,0 +1,166 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe Speak do
6
+ it { should be_a_valid_ssml_document }
7
+
8
+ its(:name) { should == 'speak' }
9
+ its(:language) { should == 'en-US' }
10
+
11
+ describe "setting options in initializers" do
12
+ subject { Speak.new :language => 'jp', :base_uri => 'blah' }
13
+
14
+ its(:language) { should == 'jp' }
15
+ its(:base_uri) { should == 'blah' }
16
+ end
17
+
18
+ it 'registers itself' do
19
+ Element.class_from_registration(:speak).should == Speak
20
+ end
21
+
22
+ describe "from a document" do
23
+ let(:document) { '<speak xmlns="http://www.w3.org/2001/10/synthesis" version="1.0" xml:lang="jp" xml:base="blah"/>' }
24
+
25
+ subject { Element.import document }
26
+
27
+ it { should be_instance_of Speak }
28
+
29
+ its(:language) { should == 'jp' }
30
+ its(:base_uri) { should == 'blah' }
31
+ end
32
+
33
+ describe "#language" do
34
+ before { subject.language = 'jp' }
35
+
36
+ its(:language) { should == 'jp' }
37
+ end
38
+
39
+ describe "#base_uri" do
40
+ before { subject.base_uri = 'blah' }
41
+
42
+ its(:base_uri) { should == 'blah' }
43
+ end
44
+
45
+ describe "comparing objects" do
46
+ it "should be equal if the content, language and base uri are the same" do
47
+ Speak.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there").should == Speak.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there")
48
+ end
49
+
50
+ describe "when the content is different" do
51
+ it "should not be equal" do
52
+ Speak.new(:content => "Hello").should_not == Speak.new(:content => "Hello there")
53
+ end
54
+ end
55
+
56
+ describe "when the language is different" do
57
+ it "should not be equal" do
58
+ Speak.new(:language => 'en-US').should_not == Speak.new(:language => 'en-GB')
59
+ end
60
+ end
61
+
62
+ describe "when the base URI is different" do
63
+ it "should not be equal" do
64
+ Speak.new(:base_uri => 'foo').should_not == Speak.new(:base_uri => 'bar')
65
+ end
66
+ end
67
+
68
+ describe "when the children are different" do
69
+ it "should not be equal" do
70
+ s1 = Speak.new
71
+ s1 << SayAs.new(:interpret_as => 'date')
72
+ s2 = Speak.new
73
+ s2 << SayAs.new(:interpret_as => 'time')
74
+
75
+ s1.should_not == s2
76
+ end
77
+ end
78
+ end
79
+
80
+ it "should allow creating child SSML elements" do
81
+ s = Speak.new
82
+ s.voice :gender => :male, :content => 'Hello'
83
+ expected_s = Speak.new
84
+ expected_s << Voice.new(:gender => :male, :content => 'Hello')
85
+ s.should == expected_s
86
+ end
87
+
88
+ describe "<<" do
89
+ it "should accept String" do
90
+ lambda { subject << 'anything' }.should_not raise_error
91
+ end
92
+
93
+ it "should accept Audio" do
94
+ lambda { subject << Audio.new }.should_not raise_error
95
+ end
96
+
97
+ it "should accept Break" do
98
+ lambda { subject << Break.new }.should_not raise_error
99
+ end
100
+
101
+ it "should accept Emphasis" do
102
+ lambda { subject << Emphasis.new }.should_not raise_error
103
+ end
104
+
105
+ it "should accept Mark" do
106
+ lambda { subject << Mark.new }.should_not raise_error
107
+ end
108
+
109
+ it "should accept P" do
110
+ lambda { subject << P.new }.should_not raise_error
111
+ end
112
+
113
+ it "should accept Phoneme" do
114
+ lambda { subject << Phoneme.new }.should_not raise_error
115
+ end
116
+
117
+ it "should accept Prosody" do
118
+ lambda { subject << Prosody.new }.should_not raise_error
119
+ end
120
+
121
+ it "should accept SayAs" do
122
+ lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
123
+ end
124
+
125
+ it "should accept Sub" do
126
+ lambda { subject << Sub.new }.should_not raise_error
127
+ end
128
+
129
+ it "should accept S" do
130
+ lambda { subject << S.new }.should_not raise_error
131
+ end
132
+
133
+ it "should accept Voice" do
134
+ lambda { subject << Voice.new }.should_not raise_error
135
+ end
136
+
137
+ it "should raise InvalidChildError with non-acceptable objects" do
138
+ lambda { subject << 1 }.should raise_error(InvalidChildError, "A Speak can only accept String, Audio, Break, Emphasis, Mark, P, Phoneme, Prosody, SayAs, Sub, S, Voice as children")
139
+ end
140
+ end
141
+
142
+ describe "#to_doc" do
143
+ it "should create an XML document from the grammar" do
144
+ subject.to_doc.should == subject.document
145
+ end
146
+ end
147
+
148
+ it "should allow concatenation" do
149
+ speak1 = Speak.new
150
+ speak1 << Voice.new(:name => 'frank', :content => "Hi, I'm Frank")
151
+ speak2 = Speak.new
152
+ speak2 << "Hello there"
153
+ speak2 << Voice.new(:name => 'millie', :content => "Hi, I'm Millie")
154
+
155
+ expected_concat = Speak.new
156
+ expected_concat << Voice.new(:name => 'frank', :content => "Hi, I'm Frank")
157
+ expected_concat << "Hello there"
158
+ expected_concat << Voice.new(:name => 'millie', :content => "Hi, I'm Millie")
159
+
160
+ concat = (speak1 + speak2)
161
+ concat.should == expected_concat
162
+ concat.to_s.should_not include('default')
163
+ end
164
+ end # Speak
165
+ end # SSML
166
+ end # RubySpeech
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe Sub do
6
+ its(:name) { should == 'sub' }
7
+
8
+ describe "setting options in initializers" do
9
+ subject { Sub.new :alias => 'foo' }
10
+
11
+ its(:alias) { should == 'foo' }
12
+ end
13
+
14
+ it 'registers itself' do
15
+ Element.class_from_registration(:sub).should == Sub
16
+ end
17
+
18
+ describe "from a document" do
19
+ let(:document) { '<sub alias="foo"/>' }
20
+
21
+ subject { Element.import document }
22
+
23
+ it { should be_instance_of Sub }
24
+
25
+ its(:alias) { should == 'foo' }
26
+ end
27
+
28
+ describe "comparing objects" do
29
+ it "should be equal if the content and alias are the same" do
30
+ Sub.new(:alias => 'jp', :content => "Hello there").should == Sub.new(:alias => 'jp', :content => "Hello there")
31
+ end
32
+
33
+ describe "when the content is different" do
34
+ it "should not be equal" do
35
+ Sub.new(:content => "Hello").should_not == Sub.new(:content => "Hello there")
36
+ end
37
+ end
38
+
39
+ describe "when the alias is different" do
40
+ it "should not be equal" do
41
+ Sub.new(:alias => 'jp').should_not == Sub.new(:alias => 'en')
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "<<" do
47
+ it "should accept String" do
48
+ lambda { subject << 'anything' }.should_not raise_error
49
+ end
50
+
51
+ it "should raise InvalidChildError with non-acceptable objects" do
52
+ lambda { subject << Voice.new }.should raise_error(InvalidChildError, "A Sub can only accept Strings as children")
53
+ end
54
+ end
55
+ end # Desc
56
+ end # SSML
57
+ end # RubySpeech