ruby_speech 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/CHANGELOG.md +15 -0
  2. data/README.md +108 -14
  3. data/lib/ruby_speech/generic_element.rb +71 -10
  4. data/lib/ruby_speech/grxml.rb +4 -1
  5. data/lib/ruby_speech/grxml/element.rb +4 -0
  6. data/lib/ruby_speech/grxml/grammar.rb +177 -46
  7. data/lib/ruby_speech/grxml/item.rb +12 -11
  8. data/lib/ruby_speech/grxml/match.rb +16 -0
  9. data/lib/ruby_speech/grxml/no_match.rb +10 -0
  10. data/lib/ruby_speech/grxml/one_of.rb +4 -11
  11. data/lib/ruby_speech/grxml/rule.rb +0 -11
  12. data/lib/ruby_speech/grxml/ruleref.rb +0 -11
  13. data/lib/ruby_speech/grxml/tag.rb +0 -11
  14. data/lib/ruby_speech/grxml/token.rb +8 -11
  15. data/lib/ruby_speech/ssml.rb +6 -0
  16. data/lib/ruby_speech/ssml/audio.rb +1 -12
  17. data/lib/ruby_speech/ssml/break.rb +0 -11
  18. data/lib/ruby_speech/ssml/desc.rb +24 -0
  19. data/lib/ruby_speech/ssml/emphasis.rb +1 -12
  20. data/lib/ruby_speech/ssml/mark.rb +43 -0
  21. data/lib/ruby_speech/ssml/p.rb +25 -0
  22. data/lib/ruby_speech/ssml/phoneme.rb +72 -0
  23. data/lib/ruby_speech/ssml/prosody.rb +1 -12
  24. data/lib/ruby_speech/ssml/s.rb +25 -0
  25. data/lib/ruby_speech/ssml/say_as.rb +0 -11
  26. data/lib/ruby_speech/ssml/speak.rb +2 -44
  27. data/lib/ruby_speech/ssml/sub.rb +42 -0
  28. data/lib/ruby_speech/ssml/voice.rb +1 -12
  29. data/lib/ruby_speech/version.rb +1 -1
  30. data/spec/ruby_speech/grxml/grammar_spec.rb +478 -35
  31. data/spec/ruby_speech/grxml/item_spec.rb +5 -2
  32. data/spec/ruby_speech/grxml/match_spec.rb +49 -0
  33. data/spec/ruby_speech/grxml/no_match_spec.rb +17 -0
  34. data/spec/ruby_speech/grxml/one_of_spec.rb +1 -1
  35. data/spec/ruby_speech/grxml/rule_spec.rb +1 -1
  36. data/spec/ruby_speech/grxml/ruleref_spec.rb +1 -1
  37. data/spec/ruby_speech/grxml/tag_spec.rb +1 -1
  38. data/spec/ruby_speech/grxml/token_spec.rb +11 -1
  39. data/spec/ruby_speech/grxml_spec.rb +64 -5
  40. data/spec/ruby_speech/ssml/audio_spec.rb +5 -6
  41. data/spec/ruby_speech/ssml/break_spec.rb +1 -1
  42. data/spec/ruby_speech/ssml/desc_spec.rb +57 -0
  43. data/spec/ruby_speech/ssml/emphasis_spec.rb +1 -4
  44. data/spec/ruby_speech/ssml/mark_spec.rb +53 -0
  45. data/spec/ruby_speech/ssml/p_spec.rb +96 -0
  46. data/spec/ruby_speech/ssml/phoneme_spec.rb +65 -0
  47. data/spec/ruby_speech/ssml/prosody_spec.rb +9 -4
  48. data/spec/ruby_speech/ssml/s_spec.rb +92 -0
  49. data/spec/ruby_speech/ssml/say_as_spec.rb +1 -1
  50. data/spec/ruby_speech/ssml/speak_spec.rb +1 -6
  51. data/spec/ruby_speech/ssml/sub_spec.rb +57 -0
  52. data/spec/ruby_speech/ssml/voice_spec.rb +1 -6
  53. data/spec/spec_helper.rb +0 -4
  54. data/spec/support/matchers.rb +13 -53
  55. metadata +200 -113
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe P do
6
+ its(:name) { should == 'p' }
7
+
8
+ describe "setting options in initializers" do
9
+ subject { P.new :language => 'jp' }
10
+
11
+ its(:language) { should == 'jp' }
12
+ end
13
+
14
+ it 'registers itself' do
15
+ Element.class_from_registration(:p).should == P
16
+ end
17
+
18
+ describe "from a document" do
19
+ let(:document) { '<p>foo</p>' }
20
+
21
+ subject { Element.import document }
22
+
23
+ it { should be_instance_of P }
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
+ P.new(:language => 'jp', :content => "Hello there").should == P.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
+ P.new(:content => "Hello").should_not == P.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
+ P.new(:language => 'jp').should_not == P.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 S" do
83
+ lambda { subject << S.new }.should_not raise_error
84
+ end
85
+
86
+ it "should accept Voice" do
87
+ lambda { subject << Voice.new }.should_not raise_error
88
+ end
89
+
90
+ it "should raise InvalidChildError with non-acceptable objects" do
91
+ lambda { subject << 1 }.should raise_error(InvalidChildError, "A P can only accept String, Audio, Break, Emphasis, Mark, Phoneme, Prosody, SayAs, Sub, S, Voice as children")
92
+ end
93
+ end
94
+ end # P
95
+ end # SSML
96
+ end # RubySpeech
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module SSML
5
+ describe Phoneme do
6
+ its(:name) { should == 'phoneme' }
7
+
8
+ describe "setting options in initializers" do
9
+ subject { Phoneme.new :alphabet => 'foo', :ph => 'bar' }
10
+
11
+ its(:alphabet) { should == 'foo' }
12
+ its(:ph) { should == 'bar' }
13
+ end
14
+
15
+ it 'registers itself' do
16
+ Element.class_from_registration(:phoneme).should == Phoneme
17
+ end
18
+
19
+ describe "from a document" do
20
+ let(:document) { '<phoneme alphabet="foo" ph="bar"/>' }
21
+
22
+ subject { Element.import document }
23
+
24
+ it { should be_instance_of Phoneme }
25
+
26
+ its(:alphabet) { should == 'foo' }
27
+ its(:ph) { should == 'bar' }
28
+ end
29
+
30
+ describe "comparing objects" do
31
+ it "should be equal if the content, ph and alphabet are the same" do
32
+ Phoneme.new(:alphabet => 'jp', :ph => 'foo', :content => "Hello there").should == Phoneme.new(:alphabet => 'jp', :ph => 'foo', :content => "Hello there")
33
+ end
34
+
35
+ describe "when the content is different" do
36
+ it "should not be equal" do
37
+ Phoneme.new(:content => "Hello").should_not == Phoneme.new(:content => "Hello there")
38
+ end
39
+ end
40
+
41
+ describe "when the ph is different" do
42
+ it "should not be equal" do
43
+ Phoneme.new(:ph => 'jp').should_not == Phoneme.new(:ph => 'en')
44
+ end
45
+ end
46
+
47
+ describe "when the alphabet is different" do
48
+ it "should not be equal" do
49
+ Phoneme.new(:alphabet => 'jp').should_not == Phoneme.new(:alphabet => 'en')
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "<<" do
55
+ it "should accept String" do
56
+ lambda { subject << 'anything' }.should_not raise_error
57
+ end
58
+
59
+ it "should raise InvalidChildError with non-acceptable objects" do
60
+ lambda { subject << Voice.new }.should raise_error(InvalidChildError, "A Phoneme can only accept Strings as children")
61
+ end
62
+ end
63
+ end # Desc
64
+ end # SSML
65
+ end # RubySpeech
@@ -23,7 +23,7 @@ module RubySpeech
23
23
  describe "from a document" do
24
24
  let(:document) { '<prosody pitch="medium" contour="something" range="20Hz" rate="2" duration="10" volume="loud"/>' }
25
25
 
26
- subject { Element.import parse_xml(document).root }
26
+ subject { Element.import document }
27
27
 
28
28
  it { should be_instance_of Prosody }
29
29
 
@@ -269,12 +269,14 @@ module RubySpeech
269
269
  end
270
270
 
271
271
  it "should accept Mark" do
272
- pending
273
272
  lambda { subject << Mark.new }.should_not raise_error
274
273
  end
275
274
 
275
+ it "should accept P" do
276
+ lambda { subject << P.new }.should_not raise_error
277
+ end
278
+
276
279
  it "should accept Phoneme" do
277
- pending
278
280
  lambda { subject << Phoneme.new }.should_not raise_error
279
281
  end
280
282
 
@@ -282,12 +284,15 @@ module RubySpeech
282
284
  lambda { subject << Prosody.new }.should_not raise_error
283
285
  end
284
286
 
287
+ it "should accept S" do
288
+ lambda { subject << S.new }.should_not raise_error
289
+ end
290
+
285
291
  it "should accept SayAs" do
286
292
  lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
287
293
  end
288
294
 
289
295
  it "should accept Sub" do
290
- pending
291
296
  lambda { subject << Sub.new }.should_not raise_error
292
297
  end
293
298
 
@@ -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
@@ -18,7 +18,7 @@ module RubySpeech
18
18
  describe "from a document" do
19
19
  let(:document) { '<say-as interpret-as="one" format="two" detail="three"/>' }
20
20
 
21
- subject { Element.import parse_xml(document).root }
21
+ subject { Element.import document }
22
22
 
23
23
  it { should be_instance_of SayAs }
24
24
 
@@ -22,7 +22,7 @@ module RubySpeech
22
22
  describe "from a document" do
23
23
  let(:document) { '<speak xmlns="http://www.w3.org/2001/10/synthesis" version="1.0" xml:lang="jp" xml:base="blah"/>' }
24
24
 
25
- subject { Element.import parse_xml(document).root }
25
+ subject { Element.import document }
26
26
 
27
27
  it { should be_instance_of Speak }
28
28
 
@@ -103,17 +103,14 @@ module RubySpeech
103
103
  end
104
104
 
105
105
  it "should accept Mark" do
106
- pending
107
106
  lambda { subject << Mark.new }.should_not raise_error
108
107
  end
109
108
 
110
109
  it "should accept P" do
111
- pending
112
110
  lambda { subject << P.new }.should_not raise_error
113
111
  end
114
112
 
115
113
  it "should accept Phoneme" do
116
- pending
117
114
  lambda { subject << Phoneme.new }.should_not raise_error
118
115
  end
119
116
 
@@ -126,12 +123,10 @@ module RubySpeech
126
123
  end
127
124
 
128
125
  it "should accept Sub" do
129
- pending
130
126
  lambda { subject << Sub.new }.should_not raise_error
131
127
  end
132
128
 
133
129
  it "should accept S" do
134
- pending
135
130
  lambda { subject << S.new }.should_not raise_error
136
131
  end
137
132
 
@@ -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
@@ -23,7 +23,7 @@ module RubySpeech
23
23
  describe "from a document" do
24
24
  let(:document) { '<voice xml:lang="jp" gender="male" age="25" variant="2" name="paul"/>' }
25
25
 
26
- subject { Element.import parse_xml(document).root }
26
+ subject { Element.import document }
27
27
 
28
28
  it { should be_instance_of Voice }
29
29
 
@@ -160,17 +160,14 @@ module RubySpeech
160
160
  end
161
161
 
162
162
  it "should accept Mark" do
163
- pending
164
163
  lambda { subject << Mark.new }.should_not raise_error
165
164
  end
166
165
 
167
166
  it "should accept P" do
168
- pending
169
167
  lambda { subject << P.new }.should_not raise_error
170
168
  end
171
169
 
172
170
  it "should accept Phoneme" do
173
- pending
174
171
  lambda { subject << Phoneme.new }.should_not raise_error
175
172
  end
176
173
 
@@ -183,12 +180,10 @@ module RubySpeech
183
180
  end
184
181
 
185
182
  it "should accept Sub" do
186
- pending
187
183
  lambda { subject << Sub.new }.should_not raise_error
188
184
  end
189
185
 
190
186
  it "should accept S" do
191
- pending
192
187
  lambda { subject << S.new }.should_not raise_error
193
188
  end
194
189
 
@@ -23,7 +23,3 @@ RSpec.configure do |config|
23
23
  config.filter_run :focus => true
24
24
  config.run_all_when_everything_filtered = true
25
25
  end
26
-
27
- def parse_xml(xml)
28
- Nokogiri::XML.parse xml, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS
29
- end