module AdhearsionCpa::ControllerMethods

Public Instance Methods

detect_tone(*arguments) click to toggle source

Detects a tone

@example Wait 5 seconds to detect a fax tone

detect_tone "fax-cng", timeout: 5

@example Check for multiple tone types

detect_tone "fax-ced", :modem, timeout: 5

@example Check for a type, with options

detect_tone :speech, maxTime: 4000, minSpeechDuration: 4000, timeout: 5

@example Check for a type, with options, and another type without

detect_tone({:dtmf => {}, speech: {maxTime: 4000, minSpeechDuration: 4000}}, timeout: 5)

@return [PunchBlock::Signal] if one of the requested tones was detected @return [nil] if none of the requested tones were detected in time

# File lib/adhearsion_cpa/controller_methods.rb, line 18
def detect_tone(*arguments)
  options = arguments.last.is_a?(Hash) && arguments.count > 1 ? arguments.pop : {}
  ToneDetector.new(self).detect_tones arguments, options
end
detect_tone!(*arguments) click to toggle source

Begin asynchronous tone detection, and run the block when the tone is detected

@example Asynchronous wait for a dtmf

detect_tone :dtmf { |detected| logger.info "Beep! Customer pushed #{detected.inspect}"}

@example Asynchronous wait for dtmf presses, running the block multiple times if multiple signals are detected

# File lib/adhearsion_cpa/controller_methods.rb, line 28
def detect_tone!(*arguments)
  options = arguments.last.is_a?(Hash) && arguments.count > 1 ? arguments.pop : {}
  ToneDetector.new(self).detect_tones arguments, options.merge(async: true), &Proc.new
end