Class: RubySpeech::SSML::Voice

Inherits:
Element
  • Object
show all
Includes:
XML::Language
Defined in:
lib/ruby_speech/ssml/voice.rb

Overview

The voice element is a production element that requests a change in speaking voice.

www.w3.org/TR/speech-synthesis/#S3.2.1

Constant Summary collapse

VALID_GENDERS =
[:male, :female, :neutral].freeze
VALID_CHILD_TYPES =
[Nokogiri::XML::Element, Nokogiri::XML::Text, String, Audio, Break, Emphasis, Mark, P, Phoneme, Prosody, S, SayAs, Sub, Voice].freeze

Instance Attribute Summary

Attributes included from GenericElement

#parent

Instance Method Summary collapse

Methods included from XML::Language

#language, #language=

Methods inherited from Element

module, namespace, root_element, #to_doc

Methods included from GenericElement

#+, #==, #base_uri, #base_uri=, #build, #children, #clone, #create_node, #embed, #eval_dsl_block, included, #inherit, #initialize, #inspect, #mass_assign, #method_missing, #namespace=, #namespace_href, #node, #nokogiri_children, #read_attr, #respond_to_missing?, #string, #to_s, #traverse, #version, #version=, #write_attr

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubySpeech::GenericElement

Instance Method Details

#<<(arg) ⇒ Object

Raises:



117
118
119
120
# File 'lib/ruby_speech/ssml/voice.rb', line 117

def <<(arg)
  raise InvalidChildError, "A Voice can only accept String, Audio, Break, Emphasis, Mark, P, Phoneme, Prosody, SayAs, Sub, S, Voice as children" unless VALID_CHILD_TYPES.include? arg.class
  super
end

#ageInteger

Indicates the preferred age in years (since birth) of the voice to speak the contained text.

Returns:

  • (Integer)


59
60
61
# File 'lib/ruby_speech/ssml/voice.rb', line 59

def age
  read_attr :age, :to_i
end

#age=(i) ⇒ Object

Parameters:

  • i (Integer)

    the age of the voice

Raises:

  • (ArgumentError)


68
69
70
71
# File 'lib/ruby_speech/ssml/voice.rb', line 68

def age=(i)
  raise ArgumentError, "You must specify a valid age (non-negative integer)" unless i.is_a?(Integer) && i >= 0
  self[:age] = i
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/ruby_speech/ssml/voice.rb', line 122

def eql?(o)
  super o, :language, :gender, :age, :variant, :name
end

#genderSymbol

Indicates the preferred gender of the voice to speak the contained text. Enumerated values are: “male”, “female”, “neutral”.

Returns:

  • (Symbol)


40
41
42
# File 'lib/ruby_speech/ssml/voice.rb', line 40

def gender
  read_attr :gender, :to_sym
end

#gender=(g) ⇒ Object

Parameters:

  • g (Symbol)

    the gender selected from VALID_GENDERS

Raises:

  • (ArgumentError)


49
50
51
52
# File 'lib/ruby_speech/ssml/voice.rb', line 49

def gender=(g)
  raise ArgumentError, "You must specify a valid gender (#{VALID_GENDERS.map(&:inspect).join ', '})" unless VALID_GENDERS.include? g
  self[:gender] = g
end

#nameString, ...

A processor-specific voice name to speak the contained text.

Returns:

  • (String, Array, nil)

    the name or names of the voice



97
98
99
100
101
102
103
104
105
106
# File 'lib/ruby_speech/ssml/voice.rb', line 97

def name
  names = read_attr :name
  return unless names
  names = names.split ' '
  case names.count
  when 0 then nil
  when 1 then names.first
  else names
  end
end

#name=(n) ⇒ Object

Parameters:

  • the (String, Array)

    name or names of the voice. May be an array of names ordered from top preference down. The names must not contain any white space.



111
112
113
114
115
# File 'lib/ruby_speech/ssml/voice.rb', line 111

def name=(n)
  # TODO: Raise ArgumentError if names contain whitespace
  n = n.join(' ') if n.is_a? Array
  self[:name] = n
end

#variantInteger

Indicates a preferred variant of the other voice characteristics to speak the contained text. (e.g. the second male child voice).

Returns:

  • (Integer)


78
79
80
# File 'lib/ruby_speech/ssml/voice.rb', line 78

def variant
  read_attr :variant, :to_i
end

#variant=(i) ⇒ Object

Parameters:

  • i (Integer)

    the variant of the voice

Raises:

  • (ArgumentError)


87
88
89
90
# File 'lib/ruby_speech/ssml/voice.rb', line 87

def variant=(i)
  raise ArgumentError, "You must specify a valid variant (positive integer)" unless i.is_a?(Integer) && i > 0
  self[:variant] = i
end