class SsmlBuilder::Builder

Attributes

ssml_content[R]

Public Class Methods

new() click to toggle source
# File lib/ssml_builder/builder.rb, line 6
def initialize
  @ssml_content = ""
end

Public Instance Methods

address(string) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/ssml_builder/builder.rb, line 78
def audio(url)
  space_precheck
  @ssml_content += "<audio src=\"" + url + "\"/>"
end
break(length = "medium") click to toggle source
# File lib/ssml_builder/builder.rb, line 68
def break(length = "medium")
  # ALIAS for pause
  pause(length)
end
cardinal(string) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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") click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/ssml_builder/builder.rb, line 19
def p(string)
  # ALIAS for paragraph
  paragraph(string)
end
paragraph(string) click to toggle source
# File lib/ssml_builder/builder.rb, line 15
def paragraph(string)
  @ssml_content += "<p>" + remove_characters(string) + "</p>"
end
pause(length = "medium") click to toggle source
# 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) click to toggle source
# File lib/ssml_builder/builder.rb, line 141
def phone(string)
  # ALIAS of telephone
  telephone(string)
end
phoneme(string,alphabet = "ipa",ph = "") click to toggle source
# 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") click to toggle source
# 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() click to toggle source
# File lib/ssml_builder/builder.rb, line 55
def prosody
  # UNKOWN HOW I WANT TO USE
end
rate(string,rate = "medium") click to toggle source
# 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) click to toggle source
# File lib/ssml_builder/builder.rb, line 10
def say(string)
  space_precheck
  @ssml_content += remove_characters(string)
end
sentence(string) click to toggle source
# File lib/ssml_builder/builder.rb, line 24
def sentence(string)
  @ssml_content += "<s>" + remove_characters(string) + "</s>"
end
spell_out(string) click to toggle source
# 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() click to toggle source
# File lib/ssml_builder/builder.rb, line 198
def ssml
  return "<speak>" + @ssml_content + "</speak>"
end
sub(string,alias_str) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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") click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

remove_characters(string) click to toggle source
# File lib/ssml_builder/builder.rb, line 204
def remove_characters(string)
  return string.gsub(/['"`]/,'')
end
space_precheck() click to toggle source
# File lib/ssml_builder/builder.rb, line 208
def space_precheck
  if !@ssml_content.empty? && @ssml_content[-1] != " "
    @ssml_content += " "
  end
end