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



160
161
162
# File 'lib/punchblock/component/output.rb', line 160

def inspect_attributes
  super + [:voice, :ssml, :interrupt_on, :start_offset, :start_paused, :repeat_interval, :repeat_times, :max_time]
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:



190
191
192
193
194
195
196
# File 'lib/punchblock/component/output.rb', line 190

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



183
184
185
# File 'lib/punchblock/component/output.rb', line 183

def pause_action
  Pause.new :component_id => component_id, :target_call_id => target_call_id
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:



215
216
217
218
219
220
221
# File 'lib/punchblock/component/output.rb', line 215

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



208
209
210
# File 'lib/punchblock/component/output.rb', line 208

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:



250
251
252
253
254
255
# File 'lib/punchblock/component/output.rb', line 250

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



241
242
243
244
245
# File 'lib/punchblock/component/output.rb', line 241

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:



341
342
343
344
345
346
# File 'lib/punchblock/component/output.rb', line 341

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



332
333
334
335
336
# File 'lib/punchblock/component/output.rb', line 332

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:



315
316
317
318
319
320
# File 'lib/punchblock/component/output.rb', line 315

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



306
307
308
309
310
# File 'lib/punchblock/component/output.rb', line 306

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:



435
436
437
438
439
440
# File 'lib/punchblock/component/output.rb', line 435

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



426
427
428
429
430
# File 'lib/punchblock/component/output.rb', line 426

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:



409
410
411
412
413
414
# File 'lib/punchblock/component/output.rb', line 409

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



400
401
402
403
404
# File 'lib/punchblock/component/output.rb', line 400

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