ruby_speech 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -2
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +23 -0
  5. data/ext/ruby_speech/extconf.rb +3 -1
  6. data/ext/ruby_speech/ruby_speech.c +4 -1
  7. data/lib/ruby_speech.rb +6 -19
  8. data/lib/ruby_speech/generic_element.rb +141 -29
  9. data/lib/ruby_speech/grxml.rb +16 -22
  10. data/lib/ruby_speech/grxml/element.rb +6 -6
  11. data/lib/ruby_speech/grxml/grammar.rb +29 -12
  12. data/lib/ruby_speech/grxml/item.rb +13 -0
  13. data/lib/ruby_speech/grxml/matcher.rb +5 -1
  14. data/lib/ruby_speech/grxml/one_of.rb +4 -0
  15. data/lib/ruby_speech/grxml/rule.rb +10 -0
  16. data/lib/ruby_speech/grxml/token.rb +3 -0
  17. data/lib/ruby_speech/nlsml.rb +3 -9
  18. data/lib/ruby_speech/ssml.rb +20 -22
  19. data/lib/ruby_speech/ssml/audio.rb +17 -0
  20. data/lib/ruby_speech/ssml/desc.rb +4 -0
  21. data/lib/ruby_speech/ssml/element.rb +5 -3
  22. data/lib/ruby_speech/ssml/emphasis.rb +17 -0
  23. data/lib/ruby_speech/ssml/mark.rb +2 -0
  24. data/lib/ruby_speech/ssml/p.rb +21 -0
  25. data/lib/ruby_speech/ssml/phoneme.rb +2 -0
  26. data/lib/ruby_speech/ssml/prosody.rb +15 -0
  27. data/lib/ruby_speech/ssml/s.rb +20 -0
  28. data/lib/ruby_speech/ssml/say_as.rb +2 -0
  29. data/lib/ruby_speech/ssml/speak.rb +19 -1
  30. data/lib/ruby_speech/ssml/sub.rb +2 -0
  31. data/lib/ruby_speech/ssml/voice.rb +19 -0
  32. data/lib/ruby_speech/version.rb +1 -1
  33. data/ruby_speech.gemspec +2 -3
  34. data/spec/ruby_speech/grxml/grammar_spec.rb +35 -30
  35. data/spec/ruby_speech/grxml/item_spec.rb +8 -6
  36. data/spec/ruby_speech/grxml/one_of_spec.rb +7 -3
  37. data/spec/ruby_speech/grxml/rule_spec.rb +14 -12
  38. data/spec/ruby_speech/grxml/ruleref_spec.rb +5 -3
  39. data/spec/ruby_speech/grxml/tag_spec.rb +6 -2
  40. data/spec/ruby_speech/grxml/token_spec.rb +6 -2
  41. data/spec/ruby_speech/grxml_spec.rb +57 -69
  42. data/spec/ruby_speech/ssml/audio_spec.rb +20 -16
  43. data/spec/ruby_speech/ssml/break_spec.rb +14 -10
  44. data/spec/ruby_speech/ssml/desc_spec.rb +9 -5
  45. data/spec/ruby_speech/ssml/emphasis_spec.rb +17 -13
  46. data/spec/ruby_speech/ssml/mark_spec.rb +7 -3
  47. data/spec/ruby_speech/ssml/p_spec.rb +18 -14
  48. data/spec/ruby_speech/ssml/phoneme_spec.rb +10 -6
  49. data/spec/ruby_speech/ssml/prosody_spec.rb +29 -25
  50. data/spec/ruby_speech/ssml/s_spec.rb +17 -13
  51. data/spec/ruby_speech/ssml/say_as_spec.rb +11 -7
  52. data/spec/ruby_speech/ssml/speak_spec.rb +48 -32
  53. data/spec/ruby_speech/ssml/sub_spec.rb +9 -5
  54. data/spec/ruby_speech/ssml/voice_spec.rb +23 -19
  55. data/spec/ruby_speech/ssml_spec.rb +64 -63
  56. data/spec/spec_helper.rb +0 -3
  57. metadata +10 -31
  58. data/lib/ruby_speech/xml.rb +0 -11
@@ -1,3 +1,5 @@
1
+ require 'ruby_speech/ssml/element'
2
+
1
3
  module RubySpeech
2
4
  module SSML
3
5
  ##
@@ -1,3 +1,6 @@
1
+ require 'ruby_speech/ssml/element'
2
+ require 'ruby_speech/xml/language'
3
+
1
4
  module RubySpeech
2
5
  module SSML
3
6
  ##
@@ -6,11 +9,26 @@ module RubySpeech
6
9
  # http://www.w3.org/TR/speech-synthesis/#S3.1.1
7
10
  #
8
11
  class Speak < Element
12
+
13
+ %w{
14
+ audio
15
+ break
16
+ desc
17
+ emphasis
18
+ mark
19
+ phoneme
20
+ prosody
21
+ s
22
+ say_as
23
+ sub
24
+ voice
25
+ }.each { |f| require "ruby_speech/ssml/#{f}" }
26
+
9
27
  include XML::Language
10
28
 
11
29
  register :speak
12
30
 
13
- self.defaults = { :version => '1.0', :language => "en-US" }
31
+ self.defaults = { :version => '1.0', :language => "en-US", namespace: SSML_NAMESPACE }
14
32
 
15
33
  VALID_CHILD_TYPES = [Nokogiri::XML::Element, Nokogiri::XML::Text, String, Audio, Break, Emphasis, Mark, P, Phoneme, Prosody, S, SayAs, Sub, Voice].freeze
16
34
 
@@ -1,3 +1,5 @@
1
+ require 'ruby_speech/ssml/element'
2
+
1
3
  module RubySpeech
2
4
  module SSML
3
5
  ##
@@ -1,3 +1,6 @@
1
+ require 'ruby_speech/ssml/element'
2
+ require 'ruby_speech/xml/language'
3
+
1
4
  module RubySpeech
2
5
  module SSML
3
6
  ##
@@ -6,6 +9,22 @@ module RubySpeech
6
9
  # http://www.w3.org/TR/speech-synthesis/#S3.2.1
7
10
  #
8
11
  class Voice < Element
12
+
13
+ %w{
14
+ audio
15
+ break
16
+ desc
17
+ emphasis
18
+ mark
19
+ p
20
+ phoneme
21
+ prosody
22
+ s
23
+ say_as
24
+ speak
25
+ sub
26
+ }.each { |f| require "ruby_speech/ssml/#{f}" }
27
+
9
28
  include XML::Language
10
29
 
11
30
  register :voice
@@ -1,3 +1,3 @@
1
1
  module RubySpeech
2
- VERSION = "2.1.2"
2
+ VERSION = "2.2.0"
3
3
  end
data/ruby_speech.gemspec CHANGED
@@ -25,9 +25,8 @@ Gem::Specification.new do |s|
25
25
  s.extensions = ['ext/ruby_speech/extconf.rb']
26
26
  end
27
27
 
28
- s.add_runtime_dependency %q<niceogiri>, ["~> 1.1", ">= 1.1.2"]
29
- s.add_runtime_dependency %q<nokogiri>, ["~> 1.5", ">= 1.5.6"]
30
- s.add_runtime_dependency %q<activesupport>, [">= 3.0.7"]
28
+ s.add_runtime_dependency %q<nokogiri>, ["~> 1.6"]
29
+ s.add_runtime_dependency %q<activesupport>, [">= 3.0.7", "< 5.0.0"]
31
30
 
32
31
  s.add_development_dependency %q<bundler>, [">= 1.0.0"]
33
32
  s.add_development_dependency %q<rspec>, [">= 2.7"]
@@ -3,13 +3,17 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module GRXML
5
5
  describe Grammar do
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { described_class.new doc }
9
+
6
10
  it { should be_a_valid_grxml_document }
7
11
 
8
12
  its(:name) { should == 'grammar' }
9
13
  its(:language) { should == 'en-US' }
10
14
 
11
15
  describe "setting options in initializers" do
12
- subject { Grammar.new :language => 'jp', :base_uri => 'blah', :root => "main_rule", :tag_format => "semantics/1.0" }
16
+ subject { Grammar.new doc, :language => 'jp', :base_uri => 'blah', :root => "main_rule", :tag_format => "semantics/1.0" }
13
17
 
14
18
  its(:language) { should == 'jp' }
15
19
  its(:base_uri) { should == 'blah' }
@@ -18,14 +22,14 @@ module RubySpeech
18
22
  end
19
23
 
20
24
  describe "setting dtmf mode" do
21
- subject { Grammar.new :mode => 'dtmf' }
25
+ subject { Grammar.new doc, :mode => 'dtmf' }
22
26
  its(:mode) { should == :dtmf }
23
27
  its(:dtmf?) { should be true }
24
28
  its(:voice?) { should be false }
25
29
  end
26
30
 
27
31
  describe "setting voice mode" do
28
- subject { Grammar.new :mode => 'voice' }
32
+ subject { Grammar.new doc, :mode => 'voice' }
29
33
  its(:mode) { should == :voice }
30
34
  its(:voice?) { should be true }
31
35
  its(:dtmf?) { should be false }
@@ -66,33 +70,33 @@ module RubySpeech
66
70
 
67
71
  describe "comparing objects" do
68
72
  it "should be equal if the content, language and base uri are the same" do
69
- Grammar.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there").should == Grammar.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there")
73
+ Grammar.new(doc, :language => 'en-GB', :base_uri => 'blah', :content => "Hello there").should == Grammar.new(doc, :language => 'en-GB', :base_uri => 'blah', :content => "Hello there")
70
74
  end
71
75
 
72
76
  describe "when the content is different" do
73
77
  it "should not be equal" do
74
- Grammar.new(:content => "Hello").should_not == Grammar.new(:content => "Hello there")
78
+ Grammar.new(doc, :content => "Hello").should_not == Grammar.new(doc, :content => "Hello there")
75
79
  end
76
80
  end
77
81
 
78
82
  describe "when the language is different" do
79
83
  it "should not be equal" do
80
- Grammar.new(:language => 'en-US').should_not == Grammar.new(:language => 'en-GB')
84
+ Grammar.new(doc, :language => 'en-US').should_not == Grammar.new(doc, :language => 'en-GB')
81
85
  end
82
86
  end
83
87
 
84
88
  describe "when the base URI is different" do
85
89
  it "should not be equal" do
86
- Grammar.new(:base_uri => 'foo').should_not == Grammar.new(:base_uri => 'bar')
90
+ Grammar.new(doc, :base_uri => 'foo').should_not == Grammar.new(doc, :base_uri => 'bar')
87
91
  end
88
92
  end
89
93
 
90
94
  describe "when the children are different" do
91
95
  it "should not be equal" do
92
- g1 = Grammar.new
93
- g1 << Rule.new(:id => 'main1')
94
- g2 = Grammar.new
95
- g2 << Rule.new(:id => 'main2')
96
+ g1 = Grammar.new doc
97
+ g1 << Rule.new(doc, :id => 'main1')
98
+ g2 = Grammar.new doc
99
+ g2 << Rule.new(doc, :id => 'main2')
96
100
 
97
101
  g1.should_not == g2
98
102
  end
@@ -100,20 +104,20 @@ module RubySpeech
100
104
  end
101
105
 
102
106
  it "should allow creating child GRXML elements" do
103
- g = Grammar.new
104
- g.Rule :id => :main, :scope => 'public'
105
- expected_g = Grammar.new
106
- expected_g << Rule.new(:id => :main, :scope => 'public')
107
+ g = Grammar.new doc
108
+ g.rule :id => :main, :scope => 'public'
109
+ expected_g = Grammar.new doc
110
+ expected_g << Rule.new(doc, :id => :main, :scope => 'public')
107
111
  g.should == expected_g
108
112
  end
109
113
 
110
114
  describe "<<" do
111
115
  it "should accept Rule" do
112
- lambda { subject << Rule.new }.should_not raise_error
116
+ lambda { subject << Rule.new(doc) }.should_not raise_error
113
117
  end
114
118
 
115
119
  it "should accept Tag" do
116
- lambda { subject << Tag.new }.should_not raise_error
120
+ lambda { subject << Tag.new(doc) }.should_not raise_error
117
121
  end
118
122
 
119
123
  it "should raise InvalidChildError with non-acceptable objects" do
@@ -135,26 +139,27 @@ module RubySpeech
135
139
 
136
140
  describe "concat" do
137
141
  it "should allow concatenation" do
138
- grammar1 = Grammar.new
139
- grammar1 << Rule.new(:id => 'frank', :scope => 'public', :content => "Hi Frank")
140
- grammar2 = Grammar.new
141
- grammar2 << Rule.new(:id => 'millie', :scope => 'public', :content => "Hi Millie")
142
+ grammar1 = Grammar.new doc
143
+ grammar1 << Rule.new(doc, :id => 'frank', :scope => 'public', :content => "Hi Frank")
144
+ grammar2 = Grammar.new doc
145
+ grammar2 << Rule.new(doc, :id => 'millie', :scope => 'public', :content => "Hi Millie")
142
146
 
143
- expected_concat = Grammar.new
144
- expected_concat << Rule.new(:id => 'frank', :scope => 'public', :content => "Hi Frank")
145
- expected_concat << Rule.new(:id => 'millie', :scope => 'public', :content => "Hi Millie")
147
+ expected_concat = Grammar.new doc
148
+ expected_concat << Rule.new(doc, :id => 'frank', :scope => 'public', :content => "Hi Frank")
149
+ expected_concat << Rule.new(doc, :id => 'millie', :scope => 'public', :content => "Hi Millie")
146
150
 
147
151
  concat = grammar1 + grammar2
148
152
  concat.should == expected_concat
153
+ concat.document.root.should == concat
149
154
  concat.to_s.should_not include('default')
150
155
  end
151
156
  end
152
157
 
153
158
  it "should allow finding its root rule" do
154
- grammar = GRXML::Grammar.new :root => 'foo'
155
- bar = GRXML::Rule.new :id => 'bar'
159
+ grammar = GRXML::Grammar.new doc, :root => 'foo'
160
+ bar = GRXML::Rule.new doc, :id => 'bar'
156
161
  grammar << bar
157
- foo = GRXML::Rule.new :id => 'foo'
162
+ foo = GRXML::Rule.new doc, :id => 'foo'
158
163
  grammar << foo
159
164
 
160
165
  grammar.root_rule.should == foo
@@ -229,7 +234,7 @@ module RubySpeech
229
234
 
230
235
  let(:tokenized_version) do
231
236
  expected_tokens = Array(tokens).map do |s|
232
- Token.new.tap { |t| t << s }
237
+ Token.new(doc).tap { |t| t << s }
233
238
  end
234
239
  single_rule_grammar expected_tokens
235
240
  end
@@ -291,7 +296,7 @@ module RubySpeech
291
296
  end
292
297
 
293
298
  context "with a single XML token" do
294
- let(:content) { [Token.new.tap { |t| t << 'San Francisco' }] }
299
+ let(:content) { [Token.new(doc).tap { |t| t << 'San Francisco' }] }
295
300
  let(:tokens) { ['San Francisco'] }
296
301
 
297
302
  it "should tokenize correctly" do
@@ -303,7 +308,7 @@ module RubySpeech
303
308
  let(:content) do
304
309
  [
305
310
  'Welcome to "San Francisco"',
306
- Token.new.tap { |t| t << 'Have Fun!' }
311
+ Token.new(doc).tap { |t| t << 'Have Fun!' }
307
312
  ]
308
313
  end
309
314
 
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module GRXML
5
5
  describe Item do
6
- subject { Item.new :weight => 1.1, :repeat => '1' }
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { Item.new doc, :weight => 1.1, :repeat => '1' }
7
9
 
8
10
  its(:name) { should == 'item' }
9
11
 
@@ -168,23 +170,23 @@ module RubySpeech
168
170
  end
169
171
 
170
172
  it "should accept OneOf" do
171
- lambda { subject << OneOf.new }.should_not raise_error
173
+ lambda { subject << OneOf.new(doc) }.should_not raise_error
172
174
  end
173
175
 
174
176
  it "should accept Item" do
175
- lambda { subject << Item.new }.should_not raise_error
177
+ lambda { subject << Item.new(doc) }.should_not raise_error
176
178
  end
177
179
 
178
180
  it "should accept Ruleref" do
179
- lambda { subject << Ruleref.new }.should_not raise_error
181
+ lambda { subject << Ruleref.new(doc) }.should_not raise_error
180
182
  end
181
183
 
182
184
  it "should accept Tag" do
183
- lambda { subject << Tag.new }.should_not raise_error
185
+ lambda { subject << Tag.new(doc) }.should_not raise_error
184
186
  end
185
187
 
186
188
  it "should accept Token" do
187
- lambda { subject << Token.new }.should_not raise_error
189
+ lambda { subject << Token.new(doc) }.should_not raise_error
188
190
  end
189
191
  end
190
192
  end # Item
@@ -3,6 +3,10 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module GRXML
5
5
  describe OneOf do
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { described_class.new doc }
9
+
6
10
  its(:name) { should == 'one-of' }
7
11
 
8
12
  it 'registers itself' do
@@ -25,7 +29,7 @@ module RubySpeech
25
29
 
26
30
  describe "<<" do
27
31
  it "should accept Item" do
28
- lambda { subject << Item.new }.should_not raise_error
32
+ lambda { subject << Item.new(doc) }.should_not raise_error
29
33
  end
30
34
 
31
35
  it "should raise InvalidChildError with non-acceptable objects" do
@@ -35,12 +39,12 @@ module RubySpeech
35
39
 
36
40
  describe "comparing objects" do
37
41
  it "should be equal if the language (when specified) is the same" do
38
- OneOf.new(:language => "jp").should == OneOf.new(:language => "jp")
42
+ OneOf.new(doc, :language => "jp").should == OneOf.new(doc, :language => "jp")
39
43
  end
40
44
 
41
45
  describe "when the language is different" do
42
46
  it "should not be equal" do
43
- OneOf.new(:language => "jp").should_not == OneOf.new(:content => "fr-CA")
47
+ OneOf.new(doc, :language => "jp").should_not == OneOf.new(doc, :content => "fr-CA")
44
48
  end
45
49
  end
46
50
  end
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module GRXML
5
5
  describe Rule do
6
- subject { Rule.new :id => 'one', :scope => 'public' }
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { Rule.new doc, :id => 'one', :scope => 'public' }
7
9
 
8
10
  its(:name) { should == 'rule' }
9
11
 
@@ -63,30 +65,30 @@ module RubySpeech
63
65
 
64
66
  describe "comparing objects" do
65
67
  it "should be equal if the content, language, id, and scope are the same" do
66
- Rule.new(:language => 'jp', :id => :main, :scope => :public, :content => "hello").should == Rule.new(:language => 'jp', :id => :main, :scope => :public, :content => "hello")
68
+ Rule.new(doc, :language => 'jp', :id => :main, :scope => :public, :content => "hello").should == Rule.new(doc, :language => 'jp', :id => :main, :scope => :public, :content => "hello")
67
69
  end
68
70
 
69
71
  describe "when the content is different" do
70
72
  it "should not be equal" do
71
- Rule.new(:content => "Hello").should_not == Rule.new(:content => "Hello there")
73
+ Rule.new(doc, :content => "Hello").should_not == Rule.new(doc, :content => "Hello there")
72
74
  end
73
75
  end
74
76
 
75
77
  describe "when the language is different" do
76
78
  it "should not be equal" do
77
- Rule.new(:language => "jp").should_not == Rule.new(:language => "esperanto")
79
+ Rule.new(doc, :language => "jp").should_not == Rule.new(doc, :language => "esperanto")
78
80
  end
79
81
  end
80
82
 
81
83
  describe "when the id is different" do
82
84
  it "should not be equal" do
83
- Rule.new(:id => :main).should_not == Rule.new(:id => :dtmf)
85
+ Rule.new(doc, :id => :main).should_not == Rule.new(doc, :id => :dtmf)
84
86
  end
85
87
  end
86
88
 
87
89
  describe "when the scope is different" do
88
90
  it "should not be equal" do
89
- Rule.new(:scope => :public).should_not == Rule.new(:scope => :private)
91
+ Rule.new(doc, :scope => :public).should_not == Rule.new(doc, :scope => :private)
90
92
  end
91
93
  end
92
94
  end
@@ -97,28 +99,28 @@ module RubySpeech
97
99
  end
98
100
 
99
101
  it "should accept OneOf" do
100
- lambda { subject << OneOf.new }.should_not raise_error
102
+ lambda { subject << OneOf.new(doc) }.should_not raise_error
101
103
  end
102
104
 
103
105
  it "should accept Item" do
104
- lambda { subject << Item.new }.should_not raise_error
106
+ lambda { subject << Item.new(doc) }.should_not raise_error
105
107
  end
106
108
 
107
109
  it "should accept Ruleref" do
108
- lambda { subject << Ruleref.new }.should_not raise_error
110
+ lambda { subject << Ruleref.new(doc) }.should_not raise_error
109
111
  end
110
112
 
111
113
  it "should accept Tag" do
112
- lambda { subject << Tag.new }.should_not raise_error
114
+ lambda { subject << Tag.new(doc) }.should_not raise_error
113
115
  end
114
116
 
115
117
  it "should accept Token" do
116
- lambda { subject << Token.new }.should_not raise_error
118
+ lambda { subject << Token.new(doc) }.should_not raise_error
117
119
  end
118
120
  end
119
121
 
120
122
  it "should raise ArgumentError with any other scope" do
121
- lambda { Rule.new :id => 'one', :scope => 'invalid_scope' }.should raise_error(ArgumentError, "A Rule's scope can only be 'public' or 'private'")
123
+ lambda { Rule.new doc, :id => 'one', :scope => 'invalid_scope' }.should raise_error(ArgumentError, "A Rule's scope can only be 'public' or 'private'")
122
124
  end
123
125
  end # Rule
124
126
  end # GRXML
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module GRXML
5
5
  describe Ruleref do
6
- subject { Ruleref.new :uri => '#testrule' }
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { Ruleref.new doc, :uri => '#testrule' }
7
9
 
8
10
  its(:name) { should == 'ruleref' }
9
11
  its(:uri) { should == '#testrule' }
@@ -23,7 +25,7 @@ module RubySpeech
23
25
  end
24
26
 
25
27
  describe "#special" do
26
- subject { Ruleref.new }
28
+ subject { Ruleref.new doc }
27
29
 
28
30
  context "with reserved values" do
29
31
  it "with a valid value" do
@@ -47,7 +49,7 @@ module RubySpeech
47
49
 
48
50
  describe "only uri or special can be specified" do
49
51
  it "should raise an error" do
50
- lambda { subject << Ruleref.new(:uri => '#test', :special => :NULL) }.should raise_error(ArgumentError, "A Ruleref can only take uri or special")
52
+ lambda { subject << Ruleref.new(doc, :uri => '#test', :special => :NULL) }.should raise_error(ArgumentError, "A Ruleref can only take uri or special")
51
53
  end
52
54
  end
53
55
  end # Ruleref