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
@@ -3,57 +3,60 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  describe SSML do
5
5
  describe "#draw" do
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
6
8
  it "should create an SSML document" do
7
- expected_doc = SSML::Speak.new
9
+ expected_doc = SSML::Speak.new doc
8
10
  SSML.draw.should == expected_doc
11
+ SSML.draw.document.xpath('ns:speak', ns: 'http://www.w3.org/2001/10/synthesis').size.should == 1
9
12
  end
10
13
 
11
14
  it "can draw with a language" do
12
- expected_doc = SSML::Speak.new language: 'pt-BR'
15
+ expected_doc = SSML::Speak.new doc, language: 'pt-BR'
13
16
  SSML.draw(language: 'pt-BR').should == expected_doc
14
17
  end
15
18
 
16
19
  describe "when the return value of the block is a string" do
17
20
  it "should be inserted into the document" do
18
- expected_doc = SSML::Speak.new(:content => "Hi, I'm Fred")
21
+ expected_doc = SSML::Speak.new(doc, :content => "Hi, I'm Fred")
19
22
  SSML.draw { "Hi, I'm Fred" }.should == expected_doc
20
23
  end
21
24
  end
22
25
 
23
26
  describe "when the return value of the block is not a string" do
24
27
  it "should not be inserted into the document" do
25
- expected_doc = SSML::Speak.new
28
+ expected_doc = SSML::Speak.new doc
26
29
  SSML.draw { :foo }.should == expected_doc
27
30
  end
28
31
  end
29
32
 
30
33
  describe "when inserting a string" do
31
34
  it "should work" do
32
- expected_doc = SSML::Speak.new(:content => "Hi, I'm Fred")
35
+ expected_doc = SSML::Speak.new(doc, :content => "Hi, I'm Fred")
33
36
  SSML.draw { string "Hi, I'm Fred" }.should == expected_doc
34
37
  end
35
38
  end
36
39
 
37
40
  it "should allow other SSML elements to be inserted in the document" do
38
- doc = SSML.draw { voice :gender => :male, :name => 'fred' }
39
- expected_doc = SSML::Speak.new
40
- expected_doc << SSML::Voice.new(:gender => :male, :name => 'fred')
41
- doc.should == expected_doc
41
+ expected_doc = SSML::Speak.new doc
42
+ expected_doc << SSML::Voice.new(doc, :gender => :male, :name => 'fred')
43
+ SSML.draw { voice :gender => :male, :name => 'fred' }.should == expected_doc
42
44
  end
43
45
 
44
46
  it "should allow nested block return values" do
47
+ expected_doc = SSML::Speak.new doc
48
+ expected_doc << SSML::Voice.new(doc, :gender => :male, :name => 'fred', :content => "Hi, I'm Fred.")
49
+
45
50
  doc = RubySpeech::SSML.draw do
46
51
  voice :gender => :male, :name => 'fred' do
47
52
  "Hi, I'm Fred."
48
53
  end
49
54
  end
50
- expected_doc = SSML::Speak.new
51
- expected_doc << SSML::Voice.new(:gender => :male, :name => 'fred', :content => "Hi, I'm Fred.")
52
55
  doc.should == expected_doc
53
56
  end
54
57
 
55
58
  it "should allow nested SSML elements" do
56
- doc = RubySpeech::SSML.draw do
59
+ drawn_doc = RubySpeech::SSML.draw do
57
60
  voice :gender => :male, :name => 'fred' do
58
61
  string "Hi, I'm Fred. The time is currently "
59
62
  say_as :interpret_as => 'date', :format => 'dmy' do
@@ -61,11 +64,12 @@ module RubySpeech
61
64
  end
62
65
  end
63
66
  end
64
- voice = SSML::Voice.new(:gender => :male, :name => 'fred', :content => "Hi, I'm Fred. The time is currently ")
65
- voice << SSML::SayAs.new(:interpret_as => 'date', :format => 'dmy', :content => "01/02/1960")
66
- expected_doc = SSML::Speak.new
67
+
68
+ voice = SSML::Voice.new(doc, :gender => :male, :name => 'fred', :content => "Hi, I'm Fred. The time is currently ")
69
+ voice << SSML::SayAs.new(doc, :interpret_as => 'date', :format => 'dmy', :content => "01/02/1960")
70
+ expected_doc = SSML::Speak.new doc
67
71
  expected_doc << voice
68
- doc.should == expected_doc
72
+ drawn_doc.should == expected_doc
69
73
  end
70
74
 
71
75
  it "should allow accessing methods defined outside the block" do
@@ -73,12 +77,8 @@ module RubySpeech
73
77
  'bar'
74
78
  end
75
79
 
76
- doc = SSML.draw do
77
- string foo
78
- end
79
-
80
- expected_doc = SSML::Speak.new :content => foo
81
- doc.should == expected_doc
80
+ expected_doc = SSML::Speak.new doc, :content => foo
81
+ SSML.draw { string foo }.should == expected_doc
82
82
  end
83
83
 
84
84
  describe "embedding" do
@@ -109,7 +109,7 @@ module RubySpeech
109
109
  end
110
110
 
111
111
  it "SSML elements" do
112
- element = SSML::Emphasis.new(:content => "HELLO?")
112
+ element = SSML::Emphasis.new(doc, :content => "HELLO?")
113
113
 
114
114
  doc = RubySpeech::SSML.draw do
115
115
  voice :gender => :male, :name => 'fred' do
@@ -148,19 +148,19 @@ module RubySpeech
148
148
  end
149
149
 
150
150
  it "should properly escape string input" do
151
- doc = RubySpeech::SSML.draw do
151
+ drawn_doc = RubySpeech::SSML.draw do
152
152
  voice { string "I <3 nachos." }
153
153
  voice { "I <3 nachos." }
154
154
  end
155
- expected_doc = SSML::Speak.new
155
+ expected_doc = SSML::Speak.new doc
156
156
  2.times do
157
- expected_doc << SSML::Voice.new(:native_content => "I <3 nachos.")
157
+ expected_doc << SSML::Voice.new(doc, :native_content => "I <3 nachos.")
158
158
  end
159
- doc.should == expected_doc
159
+ drawn_doc.should == expected_doc
160
160
  end
161
161
 
162
162
  it "should allow all permutations of possible nested SSML elements" do
163
- doc = RubySpeech::SSML.draw do
163
+ drawn_doc = RubySpeech::SSML.draw do
164
164
  string "Hello world."
165
165
  ssml_break
166
166
  audio :src => "hello" do
@@ -211,56 +211,57 @@ module RubySpeech
211
211
  end
212
212
  end
213
213
  end
214
- expected_doc = SSML::Speak.new(:content => "Hello world.")
215
- expected_doc << SSML::Break.new
216
- audio = SSML::Audio.new(:src => "hello", :content => "HELLO?")
217
- audio << SSML::Break.new
218
- audio << SSML::Audio.new(:src => "hello")
219
- audio << SSML::Emphasis.new
220
- audio << SSML::Prosody.new
221
- audio << SSML::SayAs.new(:interpret_as => 'date')
222
- audio << SSML::Voice.new
214
+ expected_doc = SSML::Speak.new(doc, :content => "Hello world.")
215
+ expected_doc << SSML::Break.new(doc)
216
+ audio = SSML::Audio.new(doc, :src => "hello", :content => "HELLO?")
217
+ audio << SSML::Break.new(doc)
218
+ audio << SSML::Audio.new(doc, :src => "hello")
219
+ audio << SSML::Emphasis.new(doc)
220
+ audio << SSML::Prosody.new(doc)
221
+ audio << SSML::SayAs.new(doc, :interpret_as => 'date')
222
+ audio << SSML::Voice.new(doc)
223
223
  expected_doc << audio
224
- emphasis = SSML::Emphasis.new(:content => "HELLO?")
225
- emphasis << SSML::Break.new
226
- emphasis << SSML::Audio.new(:src => "hello")
227
- emphasis << SSML::Emphasis.new
228
- emphasis << SSML::Prosody.new
229
- emphasis << SSML::SayAs.new(:interpret_as => 'date')
230
- emphasis << SSML::Voice.new
224
+ emphasis = SSML::Emphasis.new(doc, :content => "HELLO?")
225
+ emphasis << SSML::Break.new(doc)
226
+ emphasis << SSML::Audio.new(doc, :src => "hello")
227
+ emphasis << SSML::Emphasis.new(doc)
228
+ emphasis << SSML::Prosody.new(doc)
229
+ emphasis << SSML::SayAs.new(doc, :interpret_as => 'date')
230
+ emphasis << SSML::Voice.new(doc)
231
231
  expected_doc << emphasis
232
- prosody = SSML::Prosody.new(:rate => :slow, :content => "H...E...L...L...O?")
233
- prosody << SSML::Break.new
234
- prosody << SSML::Audio.new(:src => "hello")
235
- prosody << SSML::Emphasis.new
236
- prosody << SSML::Prosody.new
237
- prosody << SSML::SayAs.new(:interpret_as => 'date')
238
- prosody << SSML::Voice.new
232
+ prosody = SSML::Prosody.new(doc, :rate => :slow, :content => "H...E...L...L...O?")
233
+ prosody << SSML::Break.new(doc)
234
+ prosody << SSML::Audio.new(doc, :src => "hello")
235
+ prosody << SSML::Emphasis.new(doc)
236
+ prosody << SSML::Prosody.new(doc)
237
+ prosody << SSML::SayAs.new(doc, :interpret_as => 'date')
238
+ prosody << SSML::Voice.new(doc)
239
239
  expected_doc << prosody
240
- expected_doc << SSML::SayAs.new(:interpret_as => 'date', :format => 'dmy', :content => "01/02/1960")
241
- voice = SSML::Voice.new(:gender => :male, :name => 'fred', :content => "Hi, I'm Fred. The time is currently ")
242
- voice << SSML::SayAs.new(:interpret_as => 'date', :format => 'dmy', :content => "01/02/1960")
243
- voice << SSML::Break.new
244
- voice << SSML::Audio.new(:src => "hello")
245
- voice << SSML::Emphasis.new(:content => "I'm so old")
246
- voice << SSML::Prosody.new(:rate => :fast, :content => "And yet so spritely!")
247
- voice << SSML::Voice.new(:age => 12, :content => "And I'm young Fred")
240
+ expected_doc << SSML::SayAs.new(doc, :interpret_as => 'date', :format => 'dmy', :content => "01/02/1960")
241
+ voice = SSML::Voice.new(doc, :gender => :male, :name => 'fred', :content => "Hi, I'm Fred. The time is currently ")
242
+ voice << SSML::SayAs.new(doc, :interpret_as => 'date', :format => 'dmy', :content => "01/02/1960")
243
+ voice << SSML::Break.new(doc)
244
+ voice << SSML::Audio.new(doc, :src => "hello")
245
+ voice << SSML::Emphasis.new(doc, :content => "I'm so old")
246
+ voice << SSML::Prosody.new(doc, :rate => :fast, :content => "And yet so spritely!")
247
+ voice << SSML::Voice.new(doc, :age => 12, :content => "And I'm young Fred")
248
248
  expected_doc << voice
249
- doc.should == expected_doc
249
+ drawn_doc.should == expected_doc
250
250
  end
251
251
  end
252
252
 
253
253
  describe "importing nested tags" do
254
- let(:say_as) { SSML::SayAs.new :interpret_as => 'date', :format => 'dmy', :content => "01/02/1960" }
254
+ let(:doc) { Nokogiri::XML::Document.new }
255
+ let(:say_as) { SSML::SayAs.new doc, :interpret_as => 'date', :format => 'dmy', :content => "01/02/1960" }
255
256
  let(:string) { "Hi, I'm Fred. The time is currently " }
256
257
  let :voice do
257
- SSML::Voice.new(:gender => :male, :name => 'fred', :content => string).tap do |voice|
258
+ SSML::Voice.new(doc, :gender => :male, :name => 'fred', :content => string).tap do |voice|
258
259
  voice << say_as
259
260
  end
260
261
  end
261
262
 
262
263
  let :document do
263
- SSML::Speak.new.tap { |doc| doc << voice }.to_s
264
+ SSML::Speak.new(doc).tap { |doc| doc << voice }.to_s
264
265
  end
265
266
 
266
267
  let(:import) { SSML.import document }
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  require 'ruby_speech'
2
2
 
3
- include RubySpeech::GRXML
4
- include RubySpeech::XML::Language
5
-
6
3
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
7
4
 
8
5
  schema_file_path = File.expand_path File.join(__FILE__, '../../assets/synthesis.xsd')
metadata CHANGED
@@ -1,55 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_speech
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Langfeld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-05 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: niceogiri
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '1.1'
20
- - - '>='
21
- - !ruby/object:Gem::Version
22
- version: 1.1.2
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '1.1'
30
- - - '>='
31
- - !ruby/object:Gem::Version
32
- version: 1.1.2
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: nokogiri
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
17
  - - ~>
38
18
  - !ruby/object:Gem::Version
39
- version: '1.5'
40
- - - '>='
41
- - !ruby/object:Gem::Version
42
- version: 1.5.6
19
+ version: '1.6'
43
20
  type: :runtime
44
21
  prerelease: false
45
22
  version_requirements: !ruby/object:Gem::Requirement
46
23
  requirements:
47
24
  - - ~>
48
25
  - !ruby/object:Gem::Version
49
- version: '1.5'
50
- - - '>='
51
- - !ruby/object:Gem::Version
52
- version: 1.5.6
26
+ version: '1.6'
53
27
  - !ruby/object:Gem::Dependency
54
28
  name: activesupport
55
29
  requirement: !ruby/object:Gem::Requirement
@@ -57,6 +31,9 @@ dependencies:
57
31
  - - '>='
58
32
  - !ruby/object:Gem::Version
59
33
  version: 3.0.7
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: 5.0.0
60
37
  type: :runtime
61
38
  prerelease: false
62
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -64,6 +41,9 @@ dependencies:
64
41
  - - '>='
65
42
  - !ruby/object:Gem::Version
66
43
  version: 3.0.7
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: 5.0.0
67
47
  - !ruby/object:Gem::Dependency
68
48
  name: bundler
69
49
  requirement: !ruby/object:Gem::Requirement
@@ -265,7 +245,6 @@ files:
265
245
  - lib/ruby_speech/ssml/sub.rb
266
246
  - lib/ruby_speech/ssml/voice.rb
267
247
  - lib/ruby_speech/version.rb
268
- - lib/ruby_speech/xml.rb
269
248
  - lib/ruby_speech/xml/language.rb
270
249
  - ruby_speech.gemspec
271
250
  - spec/ruby_speech/grxml/grammar_spec.rb
@@ -1,11 +0,0 @@
1
- module RubySpeech
2
- module XML
3
- extend ActiveSupport::Autoload
4
-
5
- eager_autoload do
6
- autoload :Language
7
- end
8
- end # XML
9
- end # RubySpeech
10
-
11
- ActiveSupport::Autoload.eager_autoload!