ruby_speech 2.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.bundle
4
+ *.jar
5
+ Gemfile.lock
6
+ pkg/*
7
+ spec/reports
8
+ .yardoc
9
+ doc
10
+ .*.swp
11
+ vendor
12
+ tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --colour
3
+ --tty
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - jruby-19mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ matrix:
11
+ allow_failures:
12
+ # - rvm: jruby-19mode
13
+ before_install:
14
+ - sudo apt-get install libpcre3 libpcre3-dev
15
+
16
+ notifications:
17
+ irc: "irc.freenode.org#adhearsion"
data/CHANGELOG.md ADDED
@@ -0,0 +1,144 @@
1
+ # [develop](https://github.com/benlangfeld/ruby_speech)
2
+
3
+ # [2.1.0](https://github.com/benlangfeld/ruby_speech/compare/v2.0.2...v2.1.0) - [2013-05-07](https://rubygems.org/gems/ruby_speech/versions/2.1.0)
4
+ * Feature: Support for SISR literal syntax
5
+
6
+ # [2.0.2](https://github.com/benlangfeld/ruby_speech/compare/v2.0.1...v2.0.2) - [2013-05-01](https://rubygems.org/gems/ruby_speech/versions/2.0.2)
7
+ * Bugfix: Differentiate between GRXML match cases with are and are not maximal
8
+ * A Match can accept further input while still matching, while a a MaxMatch cannot.
9
+ * Matching implementation moved down to C/Java to avoid repeated regex compilation and confusing jumping about.
10
+ * Bugfix: Back to functioning on JRuby with latest Nokogiri release
11
+
12
+ # [2.0.1](https://github.com/benlangfeld/ruby_speech/compare/v2.0.0...v2.0.1) - [2013-04-27](https://rubygems.org/gems/ruby_speech/versions/2.0.1)
13
+ * Bugfix: Build native C extension in the correct location
14
+
15
+ # [2.0.0](https://github.com/benlangfeld/ruby_speech/compare/v1.1.0...v2.0.0) - [2013-04-27](https://rubygems.org/gems/ruby_speech/versions/2.0.0)
16
+ * Change: Comply with MRCPv2 flavour of NLSML
17
+ * Confidence is now a float in the XML representation
18
+ * Models are no longer used
19
+ * XForms no longer used
20
+ * Now have a true namespace
21
+ * Instance is in the NLSML namespace
22
+ * Must support string instances
23
+ * Change: Grammar matching now uses a Matcher rather than directly on the Grammar element
24
+ * Feature: Grammar matching now uses native C/Java regexes with PCRE/java.util.regex for clean partial matching and SPEEEEEED
25
+ * Bugfix: Item repeats now work correctly
26
+
27
+ # [1.1.0](https://github.com/benlangfeld/ruby_speech/compare/v1.0.2...v1.1.0) - [2013-03-02](https://rubygems.org/gems/ruby_speech/versions/1.1.0)
28
+ * Feature: NLSML building & parsing
29
+
30
+ # [1.0.2](https://github.com/benlangfeld/ruby_speech/compare/v1.0.1...v1.0.2) - [2012-12-26](https://rubygems.org/gems/ruby_speech/versions/1.0.2)
31
+ * Bugfix: Get test suite passing on JRuby
32
+
33
+ # [1.0.1](https://github.com/benlangfeld/ruby_speech/compare/v1.0.0...v1.0.1) - [2012-10-24](https://rubygems.org/gems/ruby_speech/versions/1.0.1)
34
+ * Bugfix: Don't load rubygems because it is evil
35
+ * Bugfix: Allow setting language (and other) attributes on root of SSML doc when using #draw DSL
36
+
37
+ # 1.0.0 - 2012-03-13
38
+ * Bump major version because we have a stable API
39
+
40
+ # 0.5.1 - 2012-01-09
41
+ * Feature: Chaining child injection using #<< now works
42
+ * Feature: Reading the repeat value for a GRXML Item now returns an Integer or a Range, rather than the plain string
43
+ * Feature: Most simple GRXML grammars now return PotentialMatch when the provided input is valid but incomplete. This does not work for complex grammars including repeats and deep nesting. Fixes for these coming soon.
44
+
45
+ # 0.5.0 - 2012-01-03
46
+ * Feature: Add a whole bunch more SSML elements:
47
+ * p & s
48
+ * mark
49
+ * desc
50
+ * sub
51
+ * phoneme
52
+ * Feature: Added the ability to inline grammar rule references in both destructive and non-destructive modes
53
+ * Feature: Added the ability to tokenize a grammar, turning all tokens into unambiguous `<token/>` elements
54
+ * Feature: Added the ability to whitespace normalize a grammar
55
+ * Feature: Added the ability to match an input string against a Grammar
56
+ * Feature: Constructing a GRXML grammar with a root rule specified but not provided will raise an exception
57
+ * Feature: Embedding a GRXML grammar of a mode different from the host will raise an exception
58
+ * Bugfix: Fix upward traversal through a document via #parent
59
+
60
+ # 0.4.0 - 2011-12-30
61
+ * Feature: Add the ability to look up child elements by name/attributes easily
62
+ * Feature: Allow easy access to a GRXML grammar's root rule element
63
+ * Feature: Allow inlining a Grammar's rulerefs
64
+ * Bugfix: Ruby 1.8 and JRuby don't do a tree-search for const_defined?
65
+ * Bugfix: Don't try to pass a method call up to the DSL block binding if it doesn't respond to the method either
66
+
67
+ # 0.3.4
68
+ * Eager-autoload all elements so that importing will work with elements that havn't been used yet directly
69
+ * Allow using the DSL with method calls out of the block
70
+ * Fix inspection/comparison of some elements that don't have a language attribute
71
+
72
+ # 0.3.3
73
+ * Allow `SSML::Element.import` and `GRXML::Element.import` to take a string as well as a Nokogiri::XML::Node
74
+ * Allow importing GRXML/SSML documents via their respective modules (eg `RubySpeech::GRXML.import '<grammar ... />'`)
75
+
76
+ # 0.3.2
77
+ * Fix inheriting an `SSML::Speak`'s language. Previously an imported `<speak/>` would end up with a `lang` attribute in addition to `xml:lang`, and `xml:lang` would have the default value (`en-US`). This required a Niceogiri dependency update.
78
+
79
+ # 0.3.1
80
+ * Get the whole test suite passing on Ruby 1.8.7 and JRuby (thanks to Taylor Carpenter!)
81
+
82
+ # 0.3.0
83
+ * Feature (Taylor Carpenter): Added support for GRXML documents with most elements implemented.
84
+
85
+ # 0.2.2
86
+ * Feature: The SSML DSL now supports embedding SSML documents, elements or strings via the `embed` method. This behaves as you might expect:
87
+
88
+ ```ruby
89
+ doc1 = RubySpeech::SSML.draw do
90
+ string "Hi, I'm Fred. The time is currently "
91
+ say_as :interpret_as => 'date', :format => 'dmy' do
92
+ "01/02/1960"
93
+ end
94
+ end
95
+
96
+ doc2 = RubySpeech::SSML.draw do
97
+ voice :gender => :male, :name => 'fred' do
98
+ embed doc1
99
+ end
100
+ end
101
+
102
+ doc2.to_s
103
+ ```
104
+
105
+ ```xml
106
+ <speak xmlns="http://www.w3.org/2001/10/synthesis" version="1.0" xml:lang="en-US">
107
+ <voice gender="male" name="fred">
108
+ Hi, I'm Fred. The time is currently
109
+ <say-as interpret-as="date" format="dmy">
110
+ 01/02/1960
111
+ </say-as>
112
+ </voice>
113
+ </speak>
114
+ ```
115
+
116
+ # 0.2.1
117
+ * Bugfix: SSML element's children now include any text content, and text content is copied when importing/concatenating documents
118
+
119
+ # 0.2.0
120
+ * API Change: SSML::SayAs.new (and the DSL method `say_as`) now take `:interpret_as` in the options hash, rather than a separate first argument. This is for consistency with the other element types.
121
+ * Feature: SSML elements can now be imported from a Nokogiri Node or a string
122
+ * Feature: SSML elements now respond to #children with an array of SSML elements, rather than a Nokogiri NodeSet
123
+ * Bugfix/Feature: Comparing SSML elements now compares children
124
+
125
+ # 0.1.5
126
+ * Feature: Now added support for SSML `<audio/>`
127
+
128
+ # 0.1.4
129
+ * Bugfix: Speak#+ now returns a brand new Speak rather than modifying the original object
130
+ * Bugfix: Speak#+ now re-sets the namespace on child elements to ensure no default namespace prefix is added
131
+
132
+ # 0.1.3
133
+ * Bugfix: Strings included via the DSL (both as a block return value and by calling #string) are now properly escaped
134
+
135
+ # 0.1.2
136
+ * API Change: SSML.draw now returns a Speak
137
+ * Feature: Speak objects can be turned into an XML document using #to_doc
138
+ * Feature: Speak objects can now be concatenated such that children are merged together
139
+
140
+ # 0.1.1
141
+ * Bugfix: DSL now allows for nesting all allowed elements within each other
142
+
143
+ # 0.1.0
144
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ guard 'rake', :task => 'compile' do
2
+ watch(%r{^ext/(.+)\.(c|java)$})
3
+ end
4
+
5
+ guard 'rspec', :cli => '--format documentation' do
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec/" }
9
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ben Langfeld
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,314 @@
1
+ # RubySpeech
2
+ RubySpeech is a library for constructing and parsing Text to Speech (TTS) and Automatic Speech Recognition (ASR) documents such as [SSML](http://www.w3.org/TR/speech-synthesis), [GRXML](http://www.w3.org/TR/speech-grammar/) and [NLSML](http://www.w3.org/TR/nl-spec/). Such documents can be constructed to be processed by TTS and ASR engines, parsed as the result from such, or used in the implementation of such engines.
3
+
4
+ ## Installation
5
+ gem install ruby_speech
6
+
7
+ ## Library
8
+
9
+ ### SSML
10
+ RubySpeech provides a DSL for constructing SSML documents like so:
11
+
12
+ ```ruby
13
+ require 'ruby_speech'
14
+
15
+ speak = RubySpeech::SSML.draw do
16
+ voice gender: :male, name: 'fred' do
17
+ string "Hi, I'm Fred. The time is currently "
18
+ say_as interpret_as: 'date', format: 'dmy' do
19
+ "01/02/1960"
20
+ end
21
+ end
22
+ end
23
+
24
+ speak.to_s
25
+ ```
26
+
27
+ becomes:
28
+
29
+ ```xml
30
+ <speak xmlns="http://www.w3.org/2001/10/synthesis" version="1.0" xml:lang="en-US">
31
+ <voice gender="male" name="fred">
32
+ Hi, I'm Fred. The time is currently <say-as format="dmy" interpret-as="date">01/02/1960</say-as>
33
+ </voice>
34
+ </speak>
35
+ ```
36
+
37
+ Once your `Speak` is fully prepared and you're ready to send it off for processing, you must call `to_doc` on it to add the XML header:
38
+
39
+ ```xml
40
+ <?xml version="1.0"?>
41
+ <speak xmlns="http://www.w3.org/2001/10/synthesis" version="1.0" xml:lang="en-US">
42
+ <voice gender="male" name="fred">
43
+ Hi, I'm Fred. The time is currently <say-as format="dmy" interpret-as="date">01/02/1960</say-as>
44
+ </voice>
45
+ </speak>
46
+ ```
47
+
48
+ You may also then need to call `to_s`.
49
+
50
+ ### GRXML
51
+
52
+ Construct a GRXML (SRGS) document like this:
53
+
54
+ ```ruby
55
+ require 'ruby_speech'
56
+
57
+ grammy = RubySpeech::GRXML.draw mode: :dtmf, root: 'pin' do
58
+ rule id: 'digit' do
59
+ one_of do
60
+ ('0'..'9').map { |d| item { d } }
61
+ end
62
+ end
63
+
64
+ rule id: 'pin', scope: 'public' do
65
+ one_of do
66
+ item do
67
+ item repeat: '4' do
68
+ ruleref uri: '#digit'
69
+ end
70
+ "#"
71
+ end
72
+ item do
73
+ "* 9"
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ grammy.to_s
80
+ ```
81
+
82
+ which becomes
83
+
84
+ ```xml
85
+ <grammar xmlns="http://www.w3.org/2001/06/grammar" version="1.0" xml:lang="en-US" mode="dtmf" root="pin">
86
+ <rule id="digit">
87
+ <one-of>
88
+ <item>0</item>
89
+ <item>1</item>
90
+ <item>2</item>
91
+ <item>3</item>
92
+ <item>4</item>
93
+ <item>5</item>
94
+ <item>6</item>
95
+ <item>7</item>
96
+ <item>8</item>
97
+ <item>9</item>
98
+ </one-of>
99
+ </rule>
100
+ <rule id="pin" scope="public">
101
+ <one-of>
102
+ <item><item repeat="4"><ruleref uri="#digit"/></item>#</item>
103
+ <item>* 9</item>
104
+ </one-of>
105
+ </rule>
106
+ </grammar>
107
+ ```
108
+
109
+ #### Grammar matching
110
+
111
+ It is possible to match some arbitrary input against a GRXML grammar, like so:
112
+
113
+ ```ruby
114
+ require 'ruby_speech'
115
+
116
+ >> grammar = RubySpeech::GRXML.draw mode: :dtmf, root: 'pin' do
117
+ rule id: 'digit' do
118
+ one_of do
119
+ ('0'..'9').map { |d| item { d } }
120
+ end
121
+ end
122
+
123
+ rule id: 'pin', scope: 'public' do
124
+ one_of do
125
+ item do
126
+ item repeat: '4' do
127
+ ruleref uri: '#digit'
128
+ end
129
+ "#"
130
+ end
131
+ item do
132
+ "* 9"
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ matcher = RubySpeech::GRXML::Matcher.new grammar
139
+
140
+ >> matcher.match '*9'
141
+ => #<RubySpeech::GRXML::Match:0x00000100ae5d98
142
+ @mode = :dtmf,
143
+ @confidence = 1,
144
+ @utterance = "*9",
145
+ @interpretation = "*9"
146
+ >
147
+ >> matcher.match '1234#'
148
+ => #<RubySpeech::GRXML::Match:0x00000100b7e020
149
+ @mode = :dtmf,
150
+ @confidence = 1,
151
+ @utterance = "1234#",
152
+ @interpretation = "1234#"
153
+ >
154
+ >> matcher.match '5678#'
155
+ => #<RubySpeech::GRXML::Match:0x00000101218688
156
+ @mode = :dtmf,
157
+ @confidence = 1,
158
+ @utterance = "5678#",
159
+ @interpretation = "5678#"
160
+ >
161
+ >> matcher.match '1111#'
162
+ => #<RubySpeech::GRXML::Match:0x000001012f69d8
163
+ @mode = :dtmf,
164
+ @confidence = 1,
165
+ @utterance = "1111#",
166
+ @interpretation = "1111#"
167
+ >
168
+ >> matcher.match '111'
169
+ => #<RubySpeech::GRXML::NoMatch:0x00000101371660>
170
+ ```
171
+
172
+ ### NLSML
173
+
174
+ [Natural Language Semantics Markup Language](http://tools.ietf.org/html/draft-ietf-speechsc-mrcpv2-27#section-6.3.1) is the format used by many Speech Recognition engines and natural language processors to add semantic information to human language. RubySpeech is capable of generating and parsing such documents.
175
+
176
+ It is possible to generate an NLSML document like so:
177
+
178
+ ```ruby
179
+ require 'ruby_speech'
180
+
181
+ nlsml = RubySpeech::NLSML.draw grammar: 'http://flight' do
182
+ interpretation confidence: 0.6 do
183
+ input "I want to go to Pittsburgh", mode: :speech
184
+
185
+ instance do
186
+ airline do
187
+ to_city 'Pittsburgh'
188
+ end
189
+ end
190
+ end
191
+
192
+ interpretation confidence: 0.4 do
193
+ input "I want to go to Stockholm"
194
+
195
+ instance do
196
+ airline do
197
+ to_city "Stockholm"
198
+ end
199
+ end
200
+ end
201
+ end
202
+
203
+ nlsml.to_s
204
+ ```
205
+
206
+ becomes:
207
+
208
+ ```xml
209
+ <?xml version="1.0"?>
210
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
211
+ <interpretation confidence="0.6">
212
+ <input mode="speech">I want to go to Pittsburgh</input>
213
+ <instance>
214
+ <airline>
215
+ <to_city>Pittsburgh</to_city>
216
+ </airline>
217
+ </instance>
218
+ </interpretation>
219
+ <interpretation confidence="0.4">
220
+ <input>I want to go to Stockholm</input>
221
+ <instance>
222
+ <airline>
223
+ <to_city>Stockholm</to_city>
224
+ </airline>
225
+ </instance>
226
+ </interpretation>
227
+ </result>
228
+ ```
229
+
230
+ It's also possible to parse an NLSML document and extract useful information from it. Taking the above example, one may do:
231
+
232
+ ```ruby
233
+ document = RubySpeech.parse nlsml.to_s
234
+
235
+ document.match? # => true
236
+ document.interpretations # => [
237
+ {
238
+ confidence: 0.6,
239
+ input: { mode: :speech, content: 'I want to go to Pittsburgh' },
240
+ instance: { airline: { to_city: 'Pittsburgh' } }
241
+ },
242
+ {
243
+ confidence: 0.4,
244
+ input: { content: 'I want to go to Stockholm' },
245
+ instance: { airline: { to_city: 'Stockholm' } }
246
+ }
247
+ ]
248
+ document.best_interpretation # => {
249
+ confidence: 0.6,
250
+ input: { mode: :speech, content: 'I want to go to Pittsburgh' },
251
+ instance: { airline: { to_city: 'Pittsburgh' } }
252
+ }
253
+ ```
254
+
255
+ Check out the [YARD documentation](http://rdoc.info/github/benlangfeld/ruby_speech/master/frames) for more
256
+
257
+ ## Features:
258
+ ### SSML
259
+ * Document construction
260
+ * `<voice/>`
261
+ * `<prosody/>`
262
+ * `<emphasis/>`
263
+ * `<say-as/>`
264
+ * `<break/>`
265
+ * `<audio/>`
266
+ * `<p/>` and `<s/>`
267
+ * `<phoneme/>`
268
+ * `<sub/>`
269
+
270
+ #### Misc
271
+ * `<mark/>`
272
+ * `<desc/>`
273
+
274
+ ### GRXML
275
+ * Document construction
276
+ * `<item/>`
277
+ * `<one-of/>`
278
+ * `<rule/>`
279
+ * `<ruleref/>`
280
+ * `<tag/>`
281
+ * `<token/>`
282
+
283
+ ### NLSML
284
+ * Document construction
285
+ * Simple data extraction from documents
286
+
287
+ ## TODO:
288
+ ### SSML
289
+ * `<lexicon/>`
290
+ * `<meta/>` and `<metadata/>`
291
+
292
+ ### GRXML
293
+ * `<meta/>` and `<metadata/>`
294
+ * `<example/>`
295
+ * `<lexicon/>`
296
+
297
+ ## Links:
298
+ * [Source](https://github.com/benlangfeld/ruby_speech)
299
+ * [Documentation](http://rdoc.info/gems/ruby_speech/frames)
300
+ * [Bug Tracker](https://github.com/benlangfeld/ruby_speech/issues)
301
+ * [CI](https://travis-ci.org/#!/benlangfeld/ruby_speech)
302
+
303
+ ## Note on Patches/Pull Requests
304
+
305
+ * Fork the project.
306
+ * Make your feature addition or bug fix.
307
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
308
+ * Commit, do not mess with rakefile, version, or history.
309
+ * If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull
310
+ * Send me a pull request. Bonus points for topic branches.
311
+
312
+ ## Copyright
313
+
314
+ Copyright (c) 2013 Ben Langfeld. MIT licence (see LICENSE for details).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require 'bundler/gem_tasks'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ require 'ci/reporter/rake/rspec'
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.pattern = 'spec/**/*_spec.rb'
9
+ spec.rspec_opts = '--color'
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
13
+ spec.pattern = 'spec/**/*_spec.rb'
14
+ spec.rcov = true
15
+ spec.rspec_opts = '--color'
16
+ end
17
+
18
+ task :default => [:compile, :spec]
19
+ task :ci => ['ci:setup:rspec', :compile, :spec]
20
+
21
+ require 'yard'
22
+ YARD::Rake::YardocTask.new
23
+
24
+ if RUBY_PLATFORM =~ /java/
25
+ require 'rake/javaextensiontask'
26
+ Rake::JavaExtensionTask.new 'ruby_speech' do |ext|
27
+ ext.lib_dir = 'lib/ruby_speech'
28
+ end
29
+ else
30
+ require 'rake/extensiontask'
31
+ Rake::ExtensionTask.new 'ruby_speech' do |ext|
32
+ ext.lib_dir = 'lib/ruby_speech'
33
+ end
34
+ end