lib/adhearsion/call_controller/output.rb in adhearsion-2.1.3 vs lib/adhearsion/call_controller/output.rb in adhearsion-2.2.0
- old
+ new
@@ -19,11 +19,11 @@
# @param [Hash] options A set of options for output
#
# @raises [PlaybackError] if the given argument could not be played
#
def say(text, options = {})
- player.play_ssml(text, options) || player.output(Formatter.ssml_for_text(text.to_s), options)
+ player.play_ssml(text, options) || player.output(output_formatter.ssml_for_text(text.to_s), options)
end
alias :speak :say
#
# Speak output using text-to-speech (TTS) and return as soon as it begins
@@ -32,11 +32,11 @@
# @param [Hash] options A set of options for output
#
# @raises [PlaybackError] if the given argument could not be played
#
def say!(text, options = {})
- async_player.play_ssml(text, options) || async_player.output(Formatter.ssml_for_text(text.to_s), options)
+ async_player.play_ssml(text, options) || async_player.output(output_formatter.ssml_for_text(text.to_s), options)
end
alias :speak! :say!
#
# Plays the specified sound file names. This method will handle Time/DateTime objects (e.g. Time.now),
@@ -59,11 +59,11 @@
# 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 Formatter.ssml_for_collection(arguments)
+ player.play_ssml output_formatter.ssml_for_collection(arguments)
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,11 +87,11 @@
#
# @raises [PlaybackError] if (one of) the given argument(s) could not be played
# @returns [Punchblock::Component::Output]
#
def play!(*arguments)
- async_player.play_ssml Formatter.ssml_for_collection(arguments)
+ async_player.play_ssml output_formatter.ssml_for_collection(arguments)
end
#
# Plays the given audio file.
# SSML supports http:// paths and full disk paths.
@@ -102,11 +102,11 @@
# @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
#
def play_audio(file, options = nil)
- player.play_ssml Formatter.ssml_for_audio(file, options)
+ player.play_ssml output_formatter.ssml_for_audio(file, options)
true
end
#
# Plays the given audio file and returns as soon as it begins.
@@ -119,11 +119,11 @@
#
# @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 Formatter.ssml_for_audio(file, options)
+ async_player.play_ssml output_formatter.ssml_for_audio(file, options)
end
#
# Plays the given Date, Time, or Integer (seconds since epoch)
# using the given timezone and format.
@@ -139,11 +139,11 @@
#
# @raises [ArgumentError] if the given argument can not be played
#
def play_time(time, options = {})
raise ArgumentError unless [Date, Time, DateTime].include?(time.class) && options.is_a?(Hash)
- player.play_ssml Formatter.ssml_for_time(time, options)
+ player.play_ssml output_formatter.ssml_for_time(time, options)
true
end
#
# Plays the given Date, Time, or Integer (seconds since epoch)
@@ -161,11 +161,11 @@
# @raises [ArgumentError] if the given argument can not be played
# @returns [Punchblock::Component::Output]
#
def play_time!(time, options = {})
raise ArgumentError unless [Date, Time, DateTime].include?(time.class) && options.is_a?(Hash)
- async_player.play_ssml Formatter.ssml_for_time(time, options)
+ async_player.play_ssml output_formatter.ssml_for_time(time, options)
end
#
# Plays the given Numeric argument or string representing a decimal number.
# When playing numbers, Adhearsion assumes you're saying the number, not the digits. For example, play("100")
@@ -175,11 +175,11 @@
#
# @raises [ArgumentError] if the given argument can not be played
#
def play_numeric(number)
raise ArgumentError unless number.kind_of?(Numeric) || number =~ /^\d+$/
- player.play_ssml Formatter.ssml_for_numeric(number)
+ player.play_ssml output_formatter.ssml_for_numeric(number)
true
end
#
# Plays the given Numeric argument or string representing a decimal number and returns as soon as it begins.
@@ -191,11 +191,11 @@
# @raises [ArgumentError] if the given argument can not be played
# @returns [Punchblock::Component::Output]
#
def play_numeric!(number)
raise ArgumentError unless number.kind_of?(Numeric) || number =~ /^\d+$/
- async_player.play_ssml Formatter.ssml_for_numeric(number)
+ async_player.play_ssml output_formatter.ssml_for_numeric(number)
end
#
# Plays the given output, allowing for DTMF input of a single digit from the user
# At the end of the played file it returns nil
@@ -234,31 +234,37 @@
stopper = Punchblock::Component::Input.new :mode => :dtmf,
:grammar => {
:value => grammar_accept(digits)
}
- player.output Formatter.ssml_for(argument) do |output_component|
+ player.output output_formatter.ssml_for(argument) 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
stopper.stop! if stopper.executing?
reason = stopper.complete_event.reason
- result = reason.interpretation if reason.respond_to? :interpretation
- return parse_single_dtmf result unless result.nil?
- result
+ result = reason.respond_to?(:utterance) ? reason.utterance : nil
+ parse_dtmf result
end
# @private
def player
@player ||= Player.new(self)
end
# @private
def async_player
@async_player ||= AsyncPlayer.new(self)
+ end
+
+ #
+ # @return [Formatter] an output formatter for the preparation of SSML documents for submission to the engine
+ #
+ def output_formatter
+ Formatter.new
end
end # Output
end # CallController
end # Adhearsion