lib/adhearsion/call_controller/output.rb in adhearsion-2.2.1 vs lib/adhearsion/call_controller/output.rb in adhearsion-2.3.0

- old
+ new

@@ -59,11 +59,12 @@ # play "/path/to/you-sound-cute.mp3", "/path/to/what-are-you-wearing.wav" # # @raises [PlaybackError] if (one of) the given argument(s) could not be played # def play(*arguments) - player.play_ssml output_formatter.ssml_for_collection(arguments) + options = process_output_options arguments + player.play_ssml output_formatter.ssml_for_collection(arguments), options true end # # Plays the specified sound file names and returns as soon as it begins. This method will handle Time/DateTime objects (e.g. Time.now), @@ -87,26 +88,29 @@ # # @raises [PlaybackError] if (one of) the given argument(s) could not be played # @returns [Punchblock::Component::Output] # def play!(*arguments) - async_player.play_ssml output_formatter.ssml_for_collection(arguments) + options = process_output_options arguments + async_player.play_ssml output_formatter.ssml_for_collection(arguments), options end # # Plays the given audio file. # SSML supports http:// paths and full disk paths. # The Punchblock backend will have to handle cases like Asterisk where there is a fixed sounds directory. # # @param [String] file http:// URL or full disk path to the sound file - # @param [Hash] options Additional options to specify how exactly to say time specified. + # @param [Hash] options Additional options # @option options [String] :fallback The text to play if the file is not available + # @option options [Symbol] :renderer The media engine to use for rendering the file # # @raises [PlaybackError] if (one of) the given argument(s) could not be played # - def play_audio(file, options = nil) - player.play_ssml output_formatter.ssml_for_audio(file, options) + def play_audio(file, options = {}) + renderer = options.delete :renderer + player.play_ssml(output_formatter.ssml_for_audio(file, options), renderer: renderer) true end # # Plays the given audio file and returns as soon as it begins. @@ -118,12 +122,13 @@ # @option options [String] :fallback The text to play if the file is not available # # @raises [PlaybackError] if (one of) the given argument(s) could not be played # @returns [Punchblock::Component::Output] # - def play_audio!(file, options = nil) - async_player.play_ssml output_formatter.ssml_for_audio(file, options) + def play_audio!(file, options = {}) + renderer = options.delete :renderer + async_player.play_ssml(output_formatter.ssml_for_audio(file, options), renderer: renderer) end # # Plays the given Date, Time, or Integer (seconds since epoch) # using the given timezone and format. @@ -212,12 +217,13 @@ # # @return [String, nil] The single DTMF character entered by the user, or nil if nothing was entered # @raises [PlaybackError] if (one of) the given argument(s) could not be played # def interruptible_play(*outputs) + options = process_output_options outputs outputs.find do |output| - digit = stream_file output + digit = stream_file output, '0123456789#*', options return digit if digit end end # @@ -227,18 +233,18 @@ # @param [String] String with the digits that are allowed to interrupt output # # @return [String, nil] The pressed digit, or nil if nothing was pressed # @private # - def stream_file(argument, digits = '0123456789#*') + def stream_file(argument, digits = '0123456789#*', output_options = {}) result = nil stopper = Punchblock::Component::Input.new :mode => :dtmf, :grammar => { :value => grammar_accept(digits) } - player.output output_formatter.ssml_for(argument) do |output_component| + player.output output_formatter.ssml_for(argument), output_options do |output_component| stopper.register_event_handler Punchblock::Event::Complete do |event| output_component.stop! unless output_component.complete? end write_and_await_response stopper end @@ -255,9 +261,14 @@ end # @private def async_player @async_player ||= AsyncPlayer.new(self) + end + + # @private + def process_output_options(arguments) + arguments.last.is_a?(Hash) && arguments.count > 1 ? arguments.pop : {} end # # @return [Formatter] an output formatter for the preparation of SSML documents for submission to the engine #