-
Notifications
You must be signed in to change notification settings - Fork 41
/
speak.rb
69 lines (60 loc) · 1.84 KB
/
speak.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module RubySpeech
module SSML
##
# The Speech Synthesis Markup Language is an XML application. The root element is speak.
#
# http://www.w3.org/TR/speech-synthesis/#S3.1.1
#
class Speak < Element
include XML::Language
register :speak
VALID_CHILD_TYPES = [Nokogiri::XML::Element, Nokogiri::XML::Text, String, Audio, Break, Emphasis, Prosody, SayAs, Voice].freeze
##
# Create a new SSML speak root element
#
# @param [Hash] atts Key-value pairs of options mapping to setter methods
#
# @return [Speak] an element for use in an SSML document
#
def self.new(atts = {}, &block)
new_node = super('speak', atts)
new_node[:version] = '1.0'
new_node.namespace = SSML_NAMESPACE
new_node.language ||= "en-US"
new_node.instance_eval &block if block_given?
new_node
end
##
# @return [String] the base URI to which relative URLs are resolved
#
def base_uri
read_attr :base
end
##
# @param [String] uri the base URI to which relative URLs are resolved
#
def base_uri=(uri)
write_attr 'xml:base', uri
end
def <<(arg)
raise InvalidChildError, "A Speak 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
def to_doc
Nokogiri::XML::Document.new.tap do |doc|
doc << self
end
end
def +(other)
self.class.new(:base_uri => base_uri).tap do |new_speak|
(self.children + other.children).each do |child|
new_speak << child
end
end
end
def eql?(o)
super o, :language, :base_uri
end
end # Speak
end # SSML
end # RubySpeech