Class: Punchblock::Component::Output

Inherits:
ComponentNode show all
Defined in:
lib/punchblock/component/output.rb

Defined Under Namespace

Classes: Complete, Pause, Resume, Seek, SlowDown, SpeedUp, VolumeDown, VolumeUp

Constant Summary

Constants inherited from RayoNode

RayoNode::InvalidNodeError

Instance Attribute Summary

Attributes inherited from RayoNode

#client, #component_id, #connection, #domain, #original_component, #target_call_id, #target_mixer_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ComponentNode

#add_event, #complete_event, #complete_event=, #initialize, #register_event_handler, #register_internal_handlers, #response=, #stop!, #stop_action, #trigger_event_handler, #write_action

Methods inherited from Punchblock::CommandNode

#initialize, #response, #response=, #write_attr

Methods inherited from RayoNode

class_from_registration, #eql?, import, #inspect, register, #source

Constructor Details

This class inherits a constructor from Punchblock::Component::ComponentNode

Class Method Details

.new(options = {}) ⇒ Command::Output

Creates an Rayo Output command

Examples:

output :text => 'Hello brown cow.'

returns:
  <output xmlns="urn:xmpp:rayo:output:1">Hello brown cow.</output>

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :text (String, Optional)

    to speak back

  • :voice (String, Optional)

    with which to render TTS

  • :ssml (String, Optional)

    document to render TTS

  • :interrupt_on (Symbol)

    input type on which to interrupt output. May be :speech, :dtmf or :any

  • :start_offset (Integer)

    Indicates some offset through which the output should be skipped before rendering begins.

  • :start_paused (true, false)

    Indicates wether or not the component should be started in a paused state to be resumed at a later time.

  • :repeat_interval (Integer)

    Indicates the duration of silence that should space repeats of the rendered document.

  • :repeat_times (Integer)

    Indicates the number of times the output should be played.

  • :max_time (Integer)

    Indicates the maximum amount of time for which the output should be allowed to run before being terminated. Includes repeats.

Returns:

  • (Command::Output)

    an Rayo “output” command



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/punchblock/component/output.rb', line 30

def self.new(options = {})
  super().tap do |new_node|
    case options
    when Hash
      new_node.ssml = options.delete(:ssml) if options[:ssml]
      new_node << options.delete(:text) if options[:text]
      options.each_pair { |k,v| new_node.send :"#{k}=", v }
    when Nokogiri::XML::Element
      new_node.inherit options
    end
  end
end

Instance Method Details

#inspect_attributesObject



174
175
176
# File 'lib/punchblock/component/output.rb', line 174

def inspect_attributes
  super + [:voice, :ssml, :interrupt_on, :start_offset, :start_paused, :repeat_interval, :repeat_times, :max_time, :renderer]
end

#interrupt_onSymbol

Returns input type on which to interrupt output.

Returns:

  • (Symbol)

    input type on which to interrupt output



79
80
81
# File 'lib/punchblock/component/output.rb', line 79

def interrupt_on
  read_attr :'interrupt-on', :to_sym
end

#interrupt_on=(other) ⇒ Object

Parameters:

  • other (Symbol)

    input type on which to interrupt output. May be :speech, :dtmf or :any



86
87
88
# File 'lib/punchblock/component/output.rb', line 86

def interrupt_on=(other)
  write_attr :'interrupt-on', other
end

#max_timeInteger

Returns Indicates the maximum amount of time for which the output should be allowed to run before being terminated. Includes repeats.

Returns:

  • (Integer)

    Indicates the maximum amount of time for which the output should be allowed to run before being terminated. Includes repeats.



149
150
151
# File 'lib/punchblock/component/output.rb', line 149

def max_time
  read_attr :'max-time', :to_i
end

#max_time=(other) ⇒ Object

Parameters:

  • other (Integer)

    Indicates the maximum amount of time for which the output should be allowed to run before being terminated. Includes repeats.



156
157
158
# File 'lib/punchblock/component/output.rb', line 156

def max_time=(other)
  write_attr :'max-time', other, :to_i
end

#pause!Object

Sends an Rayo pause message for the current Output

Raises:



204
205
206
207
208
209
210
# File 'lib/punchblock/component/output.rb', line 204

def pause!
  raise InvalidActionError, "Cannot pause a Output that is not executing" unless executing?
  pause_action.tap do |action|
    result = write_action action
    paused! if result
  end
end

#pause_actionCommand::Output::Pause

Pauses a running Output

Examples:

output_obj.pause_action.to_xml

returns:
  <pause xmlns="urn:xmpp:rayo:output:1"/>

Returns:

  • (Command::Output::Pause)

    an Rayo pause message for the current Output



197
198
199
# File 'lib/punchblock/component/output.rb', line 197

def pause_action
  Pause.new :component_id => component_id, :target_call_id => target_call_id
end

#rendererString

Returns the rendering engine requested by the component.

Returns:

  • (String)

    the rendering engine requested by the component



163
164
165
# File 'lib/punchblock/component/output.rb', line 163

def renderer
  read_attr :renderer
end

#renderer=(renderer) ⇒ Object

Parameters:

  • the (String)

    rendering engine to use with this component



170
171
172
# File 'lib/punchblock/component/output.rb', line 170

def renderer=(renderer)
  write_attr :renderer, renderer
end

#repeat_intervalInteger

Returns Indicates the duration of silence that should space repeats of the rendered document.

Returns:

  • (Integer)

    Indicates the duration of silence that should space repeats of the rendered document.



121
122
123
# File 'lib/punchblock/component/output.rb', line 121

def repeat_interval
  read_attr :'repeat-interval', :to_i
end

#repeat_interval=(other) ⇒ Object

Parameters:

  • other (Integer)

    Indicates the duration of silence that should space repeats of the rendered document.



128
129
130
# File 'lib/punchblock/component/output.rb', line 128

def repeat_interval=(other)
  write_attr :'repeat-interval', other, :to_i
end

#repeat_timesInteger

Returns Indicates the number of times the output should be played.

Returns:

  • (Integer)

    Indicates the number of times the output should be played.



135
136
137
# File 'lib/punchblock/component/output.rb', line 135

def repeat_times
  read_attr :'repeat-times', :to_i
end

#repeat_times=(other) ⇒ Object

Parameters:

  • other (Integer)

    Indicates the number of times the output should be played.



142
143
144
# File 'lib/punchblock/component/output.rb', line 142

def repeat_times=(other)
  write_attr :'repeat-times', other, :to_i
end

#resume!Object

Sends an Rayo resume message for the current Output

Raises:



229
230
231
232
233
234
235
# File 'lib/punchblock/component/output.rb', line 229

def resume!
  raise InvalidActionError, "Cannot resume a Output that is not paused." unless paused?
  resume_action.tap do |action|
    result = write_action action
    resumed! if result
  end
end

#resume_actionCommand::Output::Resume

Create an Rayo resume message for the current Output

Examples:

output_obj.resume_action.to_xml

returns:
  <resume xmlns="urn:xmpp:rayo:output:1"/>

Returns:

  • (Command::Output::Resume)

    an Rayo resume message



222
223
224
# File 'lib/punchblock/component/output.rb', line 222

def resume_action
  Resume.new :component_id => component_id, :target_call_id => target_call_id
end

#seek!(options = {}) ⇒ Object

Sends a Rayo seek message for the current Output

Raises:



264
265
266
267
268
269
# File 'lib/punchblock/component/output.rb', line 264

def seek!(options = {})
  raise InvalidActionError, "Cannot seek an Output that is already seeking." if seeking?
  seek_action(options).tap do |action|
    write_action action
  end
end

#seek_action(options = {}) ⇒ Command::Output::Seek

Creates an Rayo seek message for the current Output

Examples:

output_obj.seek_action.to_xml

returns:
  <seek xmlns="urn:xmpp:rayo:output:1"/>

Returns:

  • (Command::Output::Seek)

    a Rayo seek message



255
256
257
258
259
# File 'lib/punchblock/component/output.rb', line 255

def seek_action(options = {})
  Seek.new({ :component_id => component_id, :target_call_id => target_call_id }.merge(options)).tap do |s|
    s.original_component = self
  end
end

#slow_down!Object

Sends a Rayo slow down message for the current Output

Raises:



355
356
357
358
359
360
# File 'lib/punchblock/component/output.rb', line 355

def slow_down!
  raise InvalidActionError, "Cannot slow down an Output that is already speeding." unless not_speeding?
  slow_down_action.tap do |action|
    write_action action
  end
end

#slow_down_actionCommand::Output::SlowDown

Creates an Rayo slow down message for the current Output

Examples:

output_obj.slow_down_action.to_xml

returns:
  <speed-down xmlns="urn:xmpp:rayo:output:1"/>

Returns:

  • (Command::Output::SlowDown)

    a Rayo slow down message



346
347
348
349
350
# File 'lib/punchblock/component/output.rb', line 346

def slow_down_action
  SlowDown.new(:component_id => component_id, :target_call_id => target_call_id).tap do |s|
    s.original_component = self
  end
end

#speed_up!Object

Sends a Rayo speed up message for the current Output

Raises:



329
330
331
332
333
334
# File 'lib/punchblock/component/output.rb', line 329

def speed_up!
  raise InvalidActionError, "Cannot speed up an Output that is already speeding." unless not_speeding?
  speed_up_action.tap do |action|
    write_action action
  end
end

#speed_up_actionCommand::Output::SpeedUp

Creates an Rayo speed up message for the current Output

Examples:

output_obj.speed_up_action.to_xml

returns:
  <speed-up xmlns="urn:xmpp:rayo:output:1"/>

Returns:

  • (Command::Output::SpeedUp)

    a Rayo speed up message



320
321
322
323
324
# File 'lib/punchblock/component/output.rb', line 320

def speed_up_action
  SpeedUp.new(:component_id => component_id, :target_call_id => target_call_id).tap do |s|
    s.original_component = self
  end
end

#ssmlString

Returns the SSML document to render TTS.

Returns:

  • (String)

    the SSML document to render TTS



60
61
62
63
# File 'lib/punchblock/component/output.rb', line 60

def ssml
  node = children.first
  RubySpeech::SSML.import node if node
end

#ssml=(ssml) ⇒ Object

Parameters:

  • ssml (String)

    the SSML document to render TTS



68
69
70
71
72
73
74
# File 'lib/punchblock/component/output.rb', line 68

def ssml=(ssml)
  return unless ssml
  unless ssml.is_a?(RubySpeech::SSML::Element)
    ssml = RubySpeech::SSML.import ssml
  end
  self << ssml
end

#start_offsetInteger

Returns Indicates some offset through which the output should be skipped before rendering begins.

Returns:

  • (Integer)

    Indicates some offset through which the output should be skipped before rendering begins.



93
94
95
# File 'lib/punchblock/component/output.rb', line 93

def start_offset
  read_attr :'start-offset', :to_i
end

#start_offset=(other) ⇒ Object

Parameters:

  • other (Integer)

    Indicates some offset through which the output should be skipped before rendering begins.



100
101
102
# File 'lib/punchblock/component/output.rb', line 100

def start_offset=(other)
  write_attr :'start-offset', other, :to_i
end

#start_pausedtrue, false

Returns Indicates wether or not the component should be started in a paused state to be resumed at a later time.

Returns:

  • (true, false)

    Indicates wether or not the component should be started in a paused state to be resumed at a later time.



107
108
109
# File 'lib/punchblock/component/output.rb', line 107

def start_paused
  read_attr(:'start-paused') == 'true'
end

#start_paused=(other) ⇒ Object

Parameters:

  • other (true, false)

    Indicates wether or not the component should be started in a paused state to be resumed at a later time.



114
115
116
# File 'lib/punchblock/component/output.rb', line 114

def start_paused=(other)
  write_attr :'start-paused', other, :to_s
end

#voiceString

Returns the TTS voice to use.

Returns:

  • (String)

    the TTS voice to use



46
47
48
# File 'lib/punchblock/component/output.rb', line 46

def voice
  read_attr :voice
end

#voice=(voice) ⇒ Object

Parameters:

  • voice (String)

    to use when rendering TTS



53
54
55
# File 'lib/punchblock/component/output.rb', line 53

def voice=(voice)
  write_attr :voice, voice
end

#volume_down!Object

Sends a Rayo volume down message for the current Output

Raises:



449
450
451
452
453
454
# File 'lib/punchblock/component/output.rb', line 449

def volume_down!
  raise InvalidActionError, "Cannot volume down an Output that is already voluming." unless not_voluming?
  volume_down_action.tap do |action|
    write_action action
  end
end

#volume_down_actionCommand::Output::VolumeDown

Creates an Rayo volume down message for the current Output

Examples:

output_obj.volume_down_action.to_xml

returns:
  <volume-down xmlns="urn:xmpp:rayo:output:1"/>

Returns:

  • (Command::Output::VolumeDown)

    a Rayo volume down message



440
441
442
443
444
# File 'lib/punchblock/component/output.rb', line 440

def volume_down_action
  VolumeDown.new(:component_id => component_id, :target_call_id => target_call_id).tap do |s|
    s.original_component = self
  end
end

#volume_up!Object

Sends a Rayo volume up message for the current Output

Raises:



423
424
425
426
427
428
# File 'lib/punchblock/component/output.rb', line 423

def volume_up!
  raise InvalidActionError, "Cannot volume up an Output that is already voluming." unless not_voluming?
  volume_up_action.tap do |action|
    write_action action
  end
end

#volume_up_actionCommand::Output::VolumeUp

Creates an Rayo volume up message for the current Output

Examples:

output_obj.volume_up_action.to_xml

returns:
  <volume-up xmlns="urn:xmpp:rayo:output:1"/>

Returns:

  • (Command::Output::VolumeUp)

    a Rayo volume up message



414
415
416
417
418
# File 'lib/punchblock/component/output.rb', line 414

def volume_up_action
  VolumeUp.new(:component_id => component_id, :target_call_id => target_call_id).tap do |s|
    s.original_component = self
  end
end