Class: SsmlBuilder::Builder
- Inherits:
-
Object
- Object
- SsmlBuilder::Builder
- Defined in:
- lib/ssml_builder/builder.rb
Instance Attribute Summary collapse
-
#ssml_content ⇒ Object
readonly
Returns the value of attribute ssml_content.
Instance Method Summary collapse
- #address(string) ⇒ Object
- #amazon_noun(string) ⇒ Object
- #amazon_participle(string) ⇒ Object
- #amazon_sense(string, sense = 1) ⇒ Object
- #amazon_verb(string) ⇒ Object
- #audio(url) ⇒ Object
- #break(length = "medium") ⇒ Object
- #cardinal(string) ⇒ Object
- #characters(string) ⇒ Object
- #date(year = nil, month = nil, day = nil) ⇒ Object
- #digits(string) ⇒ Object
- #emphasis(string, level = "moderate") ⇒ Object
- #expletive(string) ⇒ Object
- #fraction(string) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #interjection(string) ⇒ Object
- #number(string) ⇒ Object
- #ordinal(string) ⇒ Object
- #p(string) ⇒ Object
- #paragraph(string) ⇒ Object
- #pause(length = "medium") ⇒ Object
- #phone(string) ⇒ Object
- #phoneme(string, alphabet = "ipa", ph = "") ⇒ Object
- #pitch(string, pitch = "medium") ⇒ Object
- #prosody ⇒ Object
- #rate(string, rate = "medium") ⇒ Object
- #say(string) ⇒ Object
- #sentence(string) ⇒ Object
- #spell_out(string) ⇒ Object
- #ssml ⇒ Object
- #sub(string, alias_str) ⇒ Object
- #telephone(string) ⇒ Object
- #time(string) ⇒ Object
- #unit(string) ⇒ Object
- #volume(string, volume = "medium") ⇒ Object
- #whisper(string) ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
6 7 8 |
# File 'lib/ssml_builder/builder.rb', line 6 def initialize @ssml_content = "" end |
Instance Attribute Details
#ssml_content ⇒ Object (readonly)
Returns the value of attribute ssml_content.
4 5 6 |
# File 'lib/ssml_builder/builder.rb', line 4 def ssml_content @ssml_content end |
Instance Method Details
#address(string) ⇒ Object
146 147 148 149 |
# File 'lib/ssml_builder/builder.rb', line 146 def address(string) space_precheck @ssml_content += "<say-as interpret-as=\"address\">" + string + "</say-as>" end |
#amazon_noun(string) ⇒ Object
183 184 185 186 |
# File 'lib/ssml_builder/builder.rb', line 183 def amazon_noun(string) space_precheck @ssml_content += "<w role=\"amazon:NN\">" + string + "</w>" end |
#amazon_participle(string) ⇒ Object
178 179 180 181 |
# File 'lib/ssml_builder/builder.rb', line 178 def amazon_participle(string) space_precheck @ssml_content += "<w role=\"amazon:VBD\">" + string + "</w>" end |
#amazon_sense(string, sense = 1) ⇒ Object
188 189 190 191 |
# File 'lib/ssml_builder/builder.rb', line 188 def amazon_sense(string,sense = 1) space_precheck @ssml_content += "<w role=\"SENSE_" + sense.to_s + "\">" + string + "</w>" end |
#amazon_verb(string) ⇒ Object
173 174 175 176 |
# File 'lib/ssml_builder/builder.rb', line 173 def amazon_verb(string) space_precheck @ssml_content += "<w role=\"amazon:VB\">" + string + "</w>" end |
#audio(url) ⇒ Object
78 79 80 81 |
# File 'lib/ssml_builder/builder.rb', line 78 def audio(url) space_precheck @ssml_content += "<audio src=\"" + url + "\"/>" end |
#break(length = "medium") ⇒ Object
68 69 70 71 |
# File 'lib/ssml_builder/builder.rb', line 68 def break(length = "medium") # ALIAS for pause pause(length) end |
#cardinal(string) ⇒ Object
93 94 95 96 |
# File 'lib/ssml_builder/builder.rb', line 93 def cardinal(string) space_precheck @ssml_content += "<say-as interpret-as=\"cardinal\">" + string + "</say-as>" end |
#characters(string) ⇒ Object
88 89 90 91 |
# File 'lib/ssml_builder/builder.rb', line 88 def characters(string) space_precheck @ssml_content += "<say-as interpret-as=\"characters\">" + string + "</say-as>" end |
#date(year = nil, month = nil, day = nil) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/ssml_builder/builder.rb', line 123 def date(year = nil, month = nil, day = nil) space_precheck year = year.nil? ? "????" : year.to_s month = month.nil? ? "??" : month.to_s.rjust(2, '0') day = day.nil? ? "??" : day.to_s.rjust(2, '0') @ssml_content += "<say-as interpret-as=\"date\">" + year + month + day + "</say-as>" end |
#digits(string) ⇒ Object
108 109 110 111 |
# File 'lib/ssml_builder/builder.rb', line 108 def digits(string) space_precheck @ssml_content += "<say-as interpret-as=\"digits\">" + string + "</say-as>" end |
#emphasis(string, level = "moderate") ⇒ Object
73 74 75 76 |
# File 'lib/ssml_builder/builder.rb', line 73 def emphasis(string,level = "moderate") space_precheck @ssml_content += "<emphasis level=\"" + level + "\">" + string + "</emphasis>" end |
#expletive(string) ⇒ Object
156 157 158 159 |
# File 'lib/ssml_builder/builder.rb', line 156 def expletive(string) space_precheck @ssml_content += "<say-as interpret-as=\"expletive\">" + string + "</say-as>" end |
#fraction(string) ⇒ Object
113 114 115 116 |
# File 'lib/ssml_builder/builder.rb', line 113 def fraction(string) space_precheck @ssml_content += "<say-as interpret-as=\"fraction\">" + string + "</say-as>" end |
#interjection(string) ⇒ Object
151 152 153 154 |
# File 'lib/ssml_builder/builder.rb', line 151 def interjection(string) space_precheck @ssml_content += "<say-as interpret-as=\"interjection\">" + string + "</say-as>" end |
#number(string) ⇒ Object
98 99 100 101 |
# File 'lib/ssml_builder/builder.rb', line 98 def number(string) space_precheck @ssml_content += "<say-as interpret-as=\"number\">" + string + "</say-as>" end |
#ordinal(string) ⇒ Object
103 104 105 106 |
# File 'lib/ssml_builder/builder.rb', line 103 def ordinal(string) space_precheck @ssml_content += "<say-as interpret-as=\"ordinal\">" + string + "</say-as>" end |
#p(string) ⇒ Object
19 20 21 22 |
# File 'lib/ssml_builder/builder.rb', line 19 def p(string) # ALIAS for paragraph paragraph(string) end |
#paragraph(string) ⇒ Object
15 16 17 |
# File 'lib/ssml_builder/builder.rb', line 15 def paragraph(string) @ssml_content += "<p>" + remove_characters(string) + "</p>" end |
#pause(length = "medium") ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/ssml_builder/builder.rb', line 59 def pause(length = "medium") space_precheck if ["none", "x-weak", "weak", "medium", "strong", "x-strong"].include?(length.downcase) @ssml_content += "<break strength=\"" + length.downcase + "\"/>" else @ssml_content += "<break time=\"" + length + "\"/>" end end |
#phone(string) ⇒ Object
141 142 143 144 |
# File 'lib/ssml_builder/builder.rb', line 141 def phone(string) # ALIAS of telephone telephone(string) end |
#phoneme(string, alphabet = "ipa", ph = "") ⇒ Object
193 194 195 196 |
# File 'lib/ssml_builder/builder.rb', line 193 def phoneme(string,alphabet = "ipa",ph = "") space_precheck @ssml_content += "<phoneme alphabet=\"" + alphabet + "\" ph=\"" + ph + "\">" + string + "</phoneme>" end |
#pitch(string, pitch = "medium") ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/ssml_builder/builder.rb', line 36 def pitch(string,pitch = "medium") space_precheck if !["x-low", "low", "medium", "high", "x-high"].include?(pitch) pitch = pitch.to_f > -33.3 ? pitch.to_f : -33.3 pitch = (pitch.to_f < 50.0 ? pitch : 50.0) pitch = pitch > 0 ? "+%g%" % ("%.2f" % pitch) : "%g%" % ("%.2f" % pitch) end @ssml_content += "<prosody pitch=\"" + pitch + "\">" + remove_characters(string) + "</prosody>" end |
#prosody ⇒ Object
55 56 57 |
# File 'lib/ssml_builder/builder.rb', line 55 def prosody # UNKOWN HOW I WANT TO USE end |
#rate(string, rate = "medium") ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ssml_builder/builder.rb', line 28 def rate(string,rate = "medium") space_precheck if !["x-slow", "slow", "medium", "fast", "x-fast"].include?(rate) rate = (rate.to_i > 20 ? rate.to_i : 20).to_s + "%" end @ssml_content += "<prosody rate=\"" + rate + "\">" + remove_characters(string) + "</prosody>" end |
#say(string) ⇒ Object
10 11 12 13 |
# File 'lib/ssml_builder/builder.rb', line 10 def say(string) space_precheck @ssml_content += remove_characters(string) end |
#sentence(string) ⇒ Object
24 25 26 |
# File 'lib/ssml_builder/builder.rb', line 24 def sentence(string) @ssml_content += "<s>" + remove_characters(string) + "</s>" end |
#spell_out(string) ⇒ Object
83 84 85 86 |
# File 'lib/ssml_builder/builder.rb', line 83 def spell_out(string) space_precheck @ssml_content += "<say-as interpret-as=\"spell-out\">" + string + "</say-as>" end |
#ssml ⇒ Object
198 199 200 |
# File 'lib/ssml_builder/builder.rb', line 198 def ssml return "<speak>" + @ssml_content + "</speak>" end |
#sub(string, alias_str) ⇒ Object
161 162 163 164 |
# File 'lib/ssml_builder/builder.rb', line 161 def sub(string,alias_str) space_precheck @ssml_content += "<sub alias=\"" + alias_str + "\">" + string + "</sub>" end |
#telephone(string) ⇒ Object
136 137 138 139 |
# File 'lib/ssml_builder/builder.rb', line 136 def telephone(string) space_precheck @ssml_content += "<say-as interpret-as=\"telephone\">" + string + "</say-as>" end |
#time(string) ⇒ Object
131 132 133 134 |
# File 'lib/ssml_builder/builder.rb', line 131 def time(string) space_precheck @ssml_content += "<say-as interpret-as=\"time\">" + string + "</say-as>" end |
#unit(string) ⇒ Object
118 119 120 121 |
# File 'lib/ssml_builder/builder.rb', line 118 def unit(string) space_precheck @ssml_content += "<say-as interpret-as=\"unit\">" + string.gsub(/ /,'') + "</say-as>" end |
#volume(string, volume = "medium") ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/ssml_builder/builder.rb', line 46 def volume(string,volume = "medium") space_precheck if !["silent", "x-soft", "soft", "medium", "loud", "x-loud"].include?(volume) volume = volume.to_f < 4.08 ? volume.to_f : 4.08 volume = volume > 0 ? "+%gdB" % ("%.2f" % volume) : "%gdB" % ("%.2f" % volume) end @ssml_content += "<prosody volume=\"" + volume + "\">" + remove_characters(string) + "</prosody>" end |
#whisper(string) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/ssml_builder/builder.rb', line 166 def whisper(string) if !string.nil? && !string.empty? space_precheck @ssml_content += "<amazon:effect name=\"whispered\">" + string + "</amazon:effect>" end end |