ruby_speech 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.1.3
2
+ Bugfix: Strings included via the DSL (both as a block return value and by calling #string) are now properly escaped
3
+
1
4
  # 0.1.2
2
5
  API Change: SSML.draw now returns a Speak
3
6
  Feature: Speak objects can be turned into an XML document using #to_doc
@@ -2,10 +2,10 @@ module RubySpeech
2
2
  module SSML
3
3
  class Element < Niceogiri::XML::Node
4
4
  def self.new(element_name, atts = {}, &block)
5
- super element_name do |new_node|
5
+ super(element_name) do |new_node|
6
6
  atts.each_pair { |k, v| new_node.send :"#{k}=", v }
7
7
  block_return = new_node.instance_eval &block if block_given?
8
- new_node << block_return if block_return.is_a?(String)
8
+ new_node << new_node.encode_special_chars(block_return) if block_return.is_a?(String)
9
9
  end
10
10
  end
11
11
 
@@ -13,7 +13,11 @@ module RubySpeech
13
13
  const_name = method_name.to_s.sub('ssml', '').titleize.gsub(' ', '')
14
14
  const = SSML.const_get const_name
15
15
  if const && self.class::VALID_CHILD_TYPES.include?(const)
16
- self << const.new(*args, &block)
16
+ if const == String
17
+ self << encode_special_chars(args.first)
18
+ else
19
+ self << const.new(*args, &block)
20
+ end
17
21
  else
18
22
  super
19
23
  end
@@ -32,7 +32,7 @@ module RubySpeech
32
32
  # @return [Prosody] an element for use in an SSML document
33
33
  #
34
34
  def self.new(interpret_as, atts = {}, &block)
35
- super 'say-as', atts.merge(interpret_as: interpret_as), &block
35
+ super 'say-as', atts.merge(:interpret_as => interpret_as), &block
36
36
  end
37
37
 
38
38
  ##
@@ -18,12 +18,12 @@ module RubySpeech
18
18
  # @return [Speak] an element for use in an SSML document
19
19
  #
20
20
  def self.new(atts = {}, &block)
21
- super('speak', atts) do
22
- self[:version] = '1.0'
23
- self.namespace = 'http://www.w3.org/2001/10/synthesis'
24
- self.language ||= "en-US"
25
- instance_eval &block if block_given?
26
- end
21
+ new_node = super('speak', atts)
22
+ new_node[:version] = '1.0'
23
+ new_node.namespace = 'http://www.w3.org/2001/10/synthesis'
24
+ new_node.language ||= "en-US"
25
+ new_node.instance_eval &block if block_given?
26
+ new_node
27
27
  end
28
28
 
29
29
  ##
@@ -1,3 +1,3 @@
1
1
  module RubySpeech
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -59,24 +59,24 @@ module RubySpeech
59
59
 
60
60
  describe "comparing objects" do
61
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")
62
+ Break.new(:strength => :strong, :time => 1.second, :content => "Hello there").should == Break.new(:strength => :strong, :time => 1.second, :content => "Hello there")
63
63
  end
64
64
 
65
65
  describe "when the content is different" do
66
66
  it "should not be equal" do
67
- Break.new(content: "Hello").should_not == Break.new(content: "Hello there")
67
+ Break.new(:content => "Hello").should_not == Break.new(:content => "Hello there")
68
68
  end
69
69
  end
70
70
 
71
71
  describe "when the strength is different" do
72
72
  it "should not be equal" do
73
- Break.new(strength: :strong).should_not == Break.new(strength: :weak)
73
+ Break.new(:strength => :strong).should_not == Break.new(:strength => :weak)
74
74
  end
75
75
  end
76
76
 
77
77
  describe "when the time is different" do
78
78
  it "should not be equal" do
79
- Break.new(time: 1.second).should_not == Break.new(time: 2.seconds)
79
+ Break.new(:time => 1.second).should_not == Break.new(:time => 2.seconds)
80
80
  end
81
81
  end
82
82
  end
@@ -30,18 +30,18 @@ module RubySpeech
30
30
 
31
31
  describe "comparing objects" do
32
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")
33
+ Emphasis.new(:level => :strong, :content => "Hello there").should == Emphasis.new(:level => :strong, :content => "Hello there")
34
34
  end
35
35
 
36
36
  describe "when the content is different" do
37
37
  it "should not be equal" do
38
- Emphasis.new(content: "Hello").should_not == Emphasis.new(content: "Hello there")
38
+ Emphasis.new(:content => "Hello").should_not == Emphasis.new(:content => "Hello there")
39
39
  end
40
40
  end
41
41
 
42
42
  describe "when the level is different" do
43
43
  it "should not be equal" do
44
- Emphasis.new(level: :strong).should_not == Emphasis.new(level: :reduced)
44
+ Emphasis.new(:level => :strong).should_not == Emphasis.new(:level => :reduced)
45
45
  end
46
46
  end
47
47
  end
@@ -186,48 +186,48 @@ module RubySpeech
186
186
 
187
187
  describe "comparing objects" do
188
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")
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
190
  end
191
191
 
192
192
  describe "when the content is different" do
193
193
  it "should not be equal" do
194
- Prosody.new(content: "Hello").should_not == Prosody.new(content: "Hello there")
194
+ Prosody.new(:content => "Hello").should_not == Prosody.new(:content => "Hello there")
195
195
  end
196
196
  end
197
197
 
198
198
  describe "when the pitch is different" do
199
199
  it "should not be equal" do
200
- Prosody.new(pitch: :medium).should_not == Prosody.new(pitch: :high)
200
+ Prosody.new(:pitch => :medium).should_not == Prosody.new(:pitch => :high)
201
201
  end
202
202
  end
203
203
 
204
204
  describe "when the contour is different" do
205
205
  it "should not be equal" do
206
- Prosody.new(contour: 'foo').should_not == Prosody.new(contour: 'bar')
206
+ Prosody.new(:contour => 'foo').should_not == Prosody.new(:contour => 'bar')
207
207
  end
208
208
  end
209
209
 
210
210
  describe "when the range is different" do
211
211
  it "should not be equal" do
212
- Prosody.new(range: '20Hz').should_not == Prosody.new(range: '30Hz')
212
+ Prosody.new(:range => '20Hz').should_not == Prosody.new(:range => '30Hz')
213
213
  end
214
214
  end
215
215
 
216
216
  describe "when the rate is different" do
217
217
  it "should not be equal" do
218
- Prosody.new(rate: 2).should_not == Prosody.new(rate: 3)
218
+ Prosody.new(:rate => 2).should_not == Prosody.new(:rate => 3)
219
219
  end
220
220
  end
221
221
 
222
222
  describe "when the duration is different" do
223
223
  it "should not be equal" do
224
- Prosody.new(duration: 10.seconds).should_not == Prosody.new(duration: 20.seconds)
224
+ Prosody.new(:duration => 10.seconds).should_not == Prosody.new(:duration => 20.seconds)
225
225
  end
226
226
  end
227
227
 
228
228
  describe "when the volume is different" do
229
229
  it "should not be equal" do
230
- Prosody.new(volume: :loud).should_not == Prosody.new(volume: :soft)
230
+ Prosody.new(:volume => :loud).should_not == Prosody.new(:volume => :soft)
231
231
  end
232
232
  end
233
233
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module SSML
5
5
  describe SayAs do
6
- subject { SayAs.new 'one', format: 'two', detail: 'three' }
6
+ subject { SayAs.new 'one', :format => 'two', :detail => 'three' }
7
7
 
8
8
  its(:name) { should == 'say-as' }
9
9
 
@@ -19,12 +19,12 @@ module RubySpeech
19
19
 
20
20
  describe "comparing objects" do
21
21
  it "should be equal if the content, interpret_as, format, age, variant, name are the same" do
22
- SayAs.new('jp', format: 'foo', detail: 'bar', content: "hello").should == SayAs.new('jp', format: 'foo', detail: 'bar', content: "hello")
22
+ SayAs.new('jp', :format => 'foo', :detail => 'bar', :content => "hello").should == SayAs.new('jp', :format => 'foo', :detail => 'bar', :content => "hello")
23
23
  end
24
24
 
25
25
  describe "when the content is different" do
26
26
  it "should not be equal" do
27
- SayAs.new('jp', content: "Hello").should_not == SayAs.new('jp', content: "Hello there")
27
+ SayAs.new('jp', :content => "Hello").should_not == SayAs.new('jp', :content => "Hello there")
28
28
  end
29
29
  end
30
30
 
@@ -36,13 +36,13 @@ module RubySpeech
36
36
 
37
37
  describe "when the format is different" do
38
38
  it "should not be equal" do
39
- SayAs.new('jp', format: 'foo').should_not == SayAs.new('jp', format: 'bar')
39
+ SayAs.new('jp', :format => 'foo').should_not == SayAs.new('jp', :format => 'bar')
40
40
  end
41
41
  end
42
42
 
43
43
  describe "when the detail is different" do
44
44
  it "should not be equal" do
45
- SayAs.new('jp', detail: 'foo').should_not == SayAs.new('jp', detail: 'bar')
45
+ SayAs.new('jp', :detail => 'foo').should_not == SayAs.new('jp', :detail => 'bar')
46
46
  end
47
47
  end
48
48
  end
@@ -29,33 +29,33 @@ module RubySpeech
29
29
 
30
30
  describe "comparing objects" do
31
31
  it "should be equal if the content, language and base uri are the same" do
32
- Speak.new(language: 'en-GB', base_uri: 'blah', content: "Hello there").should == Speak.new(language: 'en-GB', base_uri: 'blah', content: "Hello there")
32
+ Speak.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there").should == Speak.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there")
33
33
  end
34
34
 
35
35
  describe "when the content is different" do
36
36
  it "should not be equal" do
37
- Speak.new(content: "Hello").should_not == Speak.new(content: "Hello there")
37
+ Speak.new(:content => "Hello").should_not == Speak.new(:content => "Hello there")
38
38
  end
39
39
  end
40
40
 
41
41
  describe "when the language is different" do
42
42
  it "should not be equal" do
43
- Speak.new(language: 'en-US').should_not == Speak.new(language: 'en-GB')
43
+ Speak.new(:language => 'en-US').should_not == Speak.new(:language => 'en-GB')
44
44
  end
45
45
  end
46
46
 
47
47
  describe "when the base URI is different" do
48
48
  it "should not be equal" do
49
- Speak.new(base_uri: 'foo').should_not == Speak.new(base_uri: 'bar')
49
+ Speak.new(:base_uri => 'foo').should_not == Speak.new(:base_uri => 'bar')
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
54
  it "should allow creating child SSML elements" do
55
55
  s = Speak.new
56
- s.voice gender: :male, content: 'Hello'
56
+ s.voice :gender => :male, :content => 'Hello'
57
57
  expected_s = Speak.new
58
- expected_s << Voice.new(gender: :male, content: 'Hello')
58
+ expected_s << Voice.new(:gender => :male, :content => 'Hello')
59
59
  s.should == expected_s
60
60
  end
61
61
 
@@ -133,15 +133,15 @@ module RubySpeech
133
133
 
134
134
  it "should allow concatenation" do
135
135
  speak1 = Speak.new
136
- speak1 << Voice.new(name: 'frank', content: "Hi, I'm Frank")
136
+ speak1 << Voice.new(:name => 'frank', :content => "Hi, I'm Frank")
137
137
  speak2 = Speak.new
138
- speak2 << Voice.new(name: 'millie', content: "Hi, I'm Millie")
138
+ speak2 << Voice.new(:name => 'millie', :content => "Hi, I'm Millie")
139
139
 
140
140
  expected_concat = Speak.new
141
- expected_concat << Voice.new(name: 'frank', content: "Hi, I'm Frank")
142
- expected_concat << Voice.new(name: 'millie', content: "Hi, I'm Millie")
141
+ expected_concat << Voice.new(:name => 'frank', :content => "Hi, I'm Frank")
142
+ expected_concat << Voice.new(:name => 'millie', :content => "Hi, I'm Millie")
143
143
 
144
- (speak1 + speak2).to_s.should == expected_concat.to_s
144
+ (speak1 + speak2).should == expected_concat
145
145
  end
146
146
  end # Speak
147
147
  end # SSML
@@ -84,42 +84,42 @@ module RubySpeech
84
84
 
85
85
  describe "comparing objects" do
86
86
  it "should be equal if the content, language, gender, age, variant, name are the same" do
87
- Voice.new(language: 'jp', gender: :male, age: 25, variant: 2, name: "paul", content: "hello").should == Voice.new(language: 'jp', gender: :male, age: 25, variant: 2, name: "paul", content: "hello")
87
+ Voice.new(:language => 'jp', :gender => :male, :age => 25, :variant => 2, :name => "paul", :content => "hello").should == Voice.new(:language => 'jp', :gender => :male, :age => 25, :variant => 2, :name => "paul", :content => "hello")
88
88
  end
89
89
 
90
90
  describe "when the content is different" do
91
91
  it "should not be equal" do
92
- Voice.new(content: "Hello").should_not == Voice.new(content: "Hello there")
92
+ Voice.new(:content => "Hello").should_not == Voice.new(:content => "Hello there")
93
93
  end
94
94
  end
95
95
 
96
96
  describe "when the language is different" do
97
97
  it "should not be equal" do
98
- Voice.new(language: "Hello").should_not == Voice.new(language: "Hello there")
98
+ Voice.new(:language => "Hello").should_not == Voice.new(:language => "Hello there")
99
99
  end
100
100
  end
101
101
 
102
102
  describe "when the gender is different" do
103
103
  it "should not be equal" do
104
- Voice.new(gender: :male).should_not == Voice.new(gender: :female)
104
+ Voice.new(:gender => :male).should_not == Voice.new(:gender => :female)
105
105
  end
106
106
  end
107
107
 
108
108
  describe "when the age is different" do
109
109
  it "should not be equal" do
110
- Voice.new(age: 20).should_not == Voice.new(age: 30)
110
+ Voice.new(:age => 20).should_not == Voice.new(:age => 30)
111
111
  end
112
112
  end
113
113
 
114
114
  describe "when the variant is different" do
115
115
  it "should not be equal" do
116
- Voice.new(variant: 1).should_not == Voice.new(variant: 2)
116
+ Voice.new(:variant => 1).should_not == Voice.new(:variant => 2)
117
117
  end
118
118
  end
119
119
 
120
120
  describe "when the name is different" do
121
121
  it "should not be equal" do
122
- Voice.new(name: "Hello").should_not == Voice.new(name: "Hello there")
122
+ Voice.new(:name => "Hello").should_not == Voice.new(:name => "Hello there")
123
123
  end
124
124
  end
125
125
  end
@@ -5,55 +5,67 @@ module RubySpeech
5
5
  describe "#draw" do
6
6
  it "should create an SSML document" do
7
7
  expected_doc = SSML::Speak.new
8
- SSML.draw.to_s.should == expected_doc.to_s
8
+ SSML.draw.should == expected_doc
9
9
  end
10
10
 
11
11
  describe "when the return value of the block is a string" do
12
12
  it "should be inserted into the document" do
13
- expected_doc = SSML::Speak.new(content: "Hi, I'm Fred")
14
- SSML.draw { "Hi, I'm Fred" }.to_s.should == expected_doc.to_s
13
+ expected_doc = SSML::Speak.new(:content => "Hi, I'm Fred")
14
+ SSML.draw { "Hi, I'm Fred" }.should == expected_doc
15
15
  end
16
16
  end
17
17
 
18
18
  describe "when the return value of the block is a string" do
19
19
  it "should not be inserted into the document" do
20
20
  expected_doc = SSML::Speak.new
21
- SSML.draw { :foo }.to_s.should == expected_doc.to_s
21
+ SSML.draw { :foo }.should == expected_doc
22
22
  end
23
23
  end
24
24
 
25
25
  it "should allow other SSML elements to be inserted in the document" do
26
- doc = SSML.draw { voice gender: :male, name: 'fred' }
26
+ doc = SSML.draw { voice :gender => :male, :name => 'fred' }
27
27
  expected_doc = SSML::Speak.new
28
- expected_doc << SSML::Voice.new(gender: :male, name: 'fred')
29
- doc.to_s.should == expected_doc.to_s
28
+ expected_doc << SSML::Voice.new(:gender => :male, :name => 'fred')
29
+ doc.should == expected_doc
30
30
  end
31
31
 
32
32
  it "should allow nested block return values" do
33
33
  doc = RubySpeech::SSML.draw do
34
- voice gender: :male, name: 'fred' do
34
+ voice :gender => :male, :name => 'fred' do
35
35
  "Hi, I'm Fred."
36
36
  end
37
37
  end
38
38
  expected_doc = SSML::Speak.new
39
- expected_doc <<SSML::Voice.new(gender: :male, name: 'fred', content: "Hi, I'm Fred.")
40
- doc.to_s.should == expected_doc.to_s
39
+ expected_doc << SSML::Voice.new(:gender => :male, :name => 'fred', :content => "Hi, I'm Fred.")
40
+ doc.should == expected_doc
41
41
  end
42
42
 
43
43
  it "should allow nested SSML elements" do
44
44
  doc = RubySpeech::SSML.draw do
45
- voice gender: :male, name: 'fred' do
45
+ voice :gender => :male, :name => 'fred' do
46
46
  string "Hi, I'm Fred. The time is currently "
47
- say_as 'date', format: 'dmy' do
47
+ say_as 'date', :format => 'dmy' do
48
48
  "01/02/1960"
49
49
  end
50
50
  end
51
51
  end
52
- voice = SSML::Voice.new(gender: :male, name: 'fred', content: "Hi, I'm Fred. The time is currently ")
53
- voice << SSML::SayAs.new('date', format: 'dmy', content: "01/02/1960")
52
+ voice = SSML::Voice.new(:gender => :male, :name => 'fred', :content => "Hi, I'm Fred. The time is currently ")
53
+ voice << SSML::SayAs.new('date', :format => 'dmy', :content => "01/02/1960")
54
54
  expected_doc = SSML::Speak.new
55
55
  expected_doc << voice
56
- doc.to_s.should == expected_doc.to_s
56
+ doc.should == expected_doc
57
+ end
58
+
59
+ it "should properly escape string input" do
60
+ doc = RubySpeech::SSML.draw do
61
+ voice { string "I <3 nachos." }
62
+ voice { "I <3 nachos." }
63
+ end
64
+ expected_doc = SSML::Speak.new
65
+ 2.times do
66
+ expected_doc << SSML::Voice.new(:content => "I <3 nachos.")
67
+ end
68
+ doc.should == expected_doc
57
69
  end
58
70
 
59
71
  it "should allow all permutations of possible nested SSML elements" do
@@ -68,7 +80,7 @@ module RubySpeech
68
80
  say_as 'date'
69
81
  voice
70
82
  end
71
- prosody rate: :slow do
83
+ prosody :rate => :slow do
72
84
  string "H...E...L...L...O?"
73
85
  ssml_break
74
86
  emphasis
@@ -76,51 +88,51 @@ module RubySpeech
76
88
  say_as 'date'
77
89
  voice
78
90
  end
79
- say_as 'date', format: 'dmy' do
91
+ say_as 'date', :format => 'dmy' do
80
92
  "01/02/1960"
81
93
  end
82
- voice gender: :male, name: 'fred' do
94
+ voice :gender => :male, :name => 'fred' do
83
95
  string "Hi, I'm Fred. The time is currently "
84
- say_as 'date', format: 'dmy' do
96
+ say_as 'date', :format => 'dmy' do
85
97
  "01/02/1960"
86
98
  end
87
99
  ssml_break
88
100
  emphasis do
89
101
  "I'm so old"
90
102
  end
91
- prosody rate: :fast do
103
+ prosody :rate => :fast do
92
104
  "And yet so spritely!"
93
105
  end
94
- voice age: 12 do
106
+ voice :age => 12 do
95
107
  "And I'm young Fred"
96
108
  end
97
109
  end
98
110
  end
99
- expected_doc = SSML::Speak.new(content: "Hello world.")
111
+ expected_doc = SSML::Speak.new(:content => "Hello world.")
100
112
  expected_doc << SSML::Break.new
101
- emphasis = SSML::Emphasis.new(content: "HELLO?")
113
+ emphasis = SSML::Emphasis.new(:content => "HELLO?")
102
114
  emphasis << SSML::Break.new
103
115
  emphasis << SSML::Emphasis.new
104
116
  emphasis << SSML::Prosody.new
105
117
  emphasis << SSML::SayAs.new('date')
106
118
  emphasis << SSML::Voice.new
107
119
  expected_doc << emphasis
108
- prosody = SSML::Prosody.new(rate: :slow, content: "H...E...L...L...O?")
120
+ prosody = SSML::Prosody.new(:rate => :slow, :content => "H...E...L...L...O?")
109
121
  prosody << SSML::Break.new
110
122
  prosody << SSML::Emphasis.new
111
123
  prosody << SSML::Prosody.new
112
124
  prosody << SSML::SayAs.new('date')
113
125
  prosody << SSML::Voice.new
114
126
  expected_doc << prosody
115
- expected_doc << SSML::SayAs.new('date', format: 'dmy', content: "01/02/1960")
116
- voice = SSML::Voice.new(gender: :male, name: 'fred', content: "Hi, I'm Fred. The time is currently ")
117
- voice << SSML::SayAs.new('date', format: 'dmy', content: "01/02/1960")
127
+ expected_doc << SSML::SayAs.new('date', :format => 'dmy', :content => "01/02/1960")
128
+ voice = SSML::Voice.new(:gender => :male, :name => 'fred', :content => "Hi, I'm Fred. The time is currently ")
129
+ voice << SSML::SayAs.new('date', :format => 'dmy', :content => "01/02/1960")
118
130
  voice << SSML::Break.new
119
- voice << SSML::Emphasis.new(content: "I'm so old")
120
- voice << SSML::Prosody.new(rate: :fast, content: "And yet so spritely!")
121
- voice << SSML::Voice.new(age: 12, content: "And I'm young Fred")
131
+ voice << SSML::Emphasis.new(:content => "I'm so old")
132
+ voice << SSML::Prosody.new(:rate => :fast, :content => "And yet so spritely!")
133
+ voice << SSML::Voice.new(:age => 12, :content => "And I'm young Fred")
122
134
  expected_doc << voice
123
- doc.to_s.should == expected_doc.to_s
135
+ doc.should == expected_doc
124
136
  end
125
137
  end
126
138
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben Langfeld
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-07 00:00:00 +01:00
17
+ date: 2011-07-10 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency