Module: Adhearsion::CallController::Output
- Extended by:
- ActiveSupport::Autoload
- Included in:
- Adhearsion::CallController
- Defined in:
- lib/adhearsion/call_controller/output.rb,
lib/adhearsion/call_controller/output/player.rb,
lib/adhearsion/call_controller/output/formatter.rb,
lib/adhearsion/call_controller/output/async_player.rb,
lib/adhearsion/call_controller/output/abstract_player.rb
Defined Under Namespace
Classes: AbstractPlayer, AsyncPlayer, Formatter, Player
Constant Summary collapse
- PlaybackError =
Represents failure to play audio, such as when the sound file cannot be found
Class.new Adhearsion::Error
- NoDocError =
Represents failure to provide documents to playback
Class.new Adhearsion::Error
Instance Method Summary collapse
-
#interruptible_play(*outputs, options) ⇒ String?
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.
-
#output_formatter ⇒ Formatter
An output formatter for the preparation of SSML documents for submission to the engine.
-
#play(*outputs, options) ⇒ Object
Plays the specified sound file names.
-
#play!(*outputs, options) ⇒ Punchblock::Component::Output
Plays the specified sound file names and returns as soon as it begins.
-
#play_audio(file, options = {}) ⇒ Object
Plays the given audio file.
-
#play_audio!(file, options = {}) ⇒ Punchblock::Component::Output
Plays the given audio file and returns as soon as it begins.
-
#play_numeric(number) ⇒ Object
Plays the given Numeric argument or string representing a decimal number.
-
#play_numeric!(number) ⇒ Punchblock::Component::Output
Plays the given Numeric argument or string representing a decimal number and returns as soon as it begins.
-
#play_time(time, options = {}) ⇒ Object
Plays the given Date, Time, or Integer (seconds since epoch) using the given timezone and format.
-
#play_time!(time, options = {}) ⇒ Punchblock::Component::Output
Plays the given Date, Time, or Integer (seconds since epoch) using the given timezone and format and returns as soon as it begins.
-
#say(text, options = {}) ⇒ Object
(also: #speak)
Speak output using text-to-speech (TTS).
-
#say!(text, options = {}) ⇒ Object
(also: #speak!)
Speak output using text-to-speech (TTS) and return as soon as it begins.
-
#say_characters(characters, options = {}) ⇒ Object
Speak characters using text-to-speech (TTS).
-
#say_characters!(characters, options = {}) ⇒ Object
Speak characters using text-to-speech (TTS) and return as soon as it begins.
Instance Method Details
#interruptible_play(*outputs, options) ⇒ String?
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
260 261 262 263 264 265 266 |
# File 'lib/adhearsion/call_controller/output.rb', line 260 def interruptible_play(*outputs, ) = outputs, outputs.find do |output| digit = stream_file output, '0123456789#*', return digit if digit end end |
#output_formatter ⇒ Formatter
Returns an output formatter for the preparation of SSML documents for submission to the engine.
320 321 322 |
# File 'lib/adhearsion/call_controller/output.rb', line 320 def output_formatter Formatter.new end |
#play(*outputs, options) ⇒ Object
Plays the specified sound file names. This method will handle Time/DateTime objects (e.g. Time.now), Fixnums (e.g. 1000), Strings which are valid Fixnums (e.g “123”), and direct sound files. To specify how the Date/Time objects are said pass in as an array with the first parameter as the Date/Time/DateTime object along with a hash with the additional options. See play_time for more information.
96 97 98 99 100 101 102 103 |
# File 'lib/adhearsion/call_controller/output.rb', line 96 def play(*outputs, ) = outputs, ssml = output_formatter.ssml_for_collection(outputs) || return player.play_ssml ssml, true rescue NoDocError false end |
#play!(*outputs, options) ⇒ Punchblock::Component::Output
Plays the specified sound file names and returns as soon as it begins. This method will handle Time/DateTime objects (e.g. Time.now), Fixnums (e.g. 1000), Strings which are valid Fixnums (e.g “123”), and direct sound files. To specify how the Date/Time objects are said pass in as an array with the first parameter as the Date/Time/DateTime object along with a hash with the additional options. See play_time for more information.
128 129 130 131 132 133 134 |
# File 'lib/adhearsion/call_controller/output.rb', line 128 def play!(*outputs, ) = outputs, ssml = output_formatter.ssml_for_collection(outputs) || return async_player.play_ssml ssml, rescue NoDocError false end |
#play_audio(file, options = {}) ⇒ Object
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.
148 149 150 151 152 |
# File 'lib/adhearsion/call_controller/output.rb', line 148 def play_audio(file, = {}) renderer = .delete :renderer player.play_ssml(output_formatter.ssml_for_audio(file, ), renderer: renderer) true end |
#play_audio!(file, options = {}) ⇒ Punchblock::Component::Output
Plays the given audio file and returns as soon as it begins. 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.
166 167 168 169 |
# File 'lib/adhearsion/call_controller/output.rb', line 166 def play_audio!(file, = {}) renderer = .delete :renderer async_player.play_ssml(output_formatter.ssml_for_audio(file, ), renderer: renderer) end |
#play_numeric(number) ⇒ Object
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”) is pronounced as “one hundred” instead of “one zero zero”.
222 223 224 225 226 |
# File 'lib/adhearsion/call_controller/output.rb', line 222 def play_numeric(number) raise ArgumentError unless number.kind_of?(Numeric) || number =~ /^\d+$/ player.play_ssml output_formatter.ssml_for_numeric(number) true end |
#play_numeric!(number) ⇒ Punchblock::Component::Output
Plays the given Numeric argument or string representing a decimal number and returns as soon as it begins. When playing numbers, Adhearsion assumes you’re saying the number, not the digits. For example, play(“100”) is pronounced as “one hundred” instead of “one zero zero”.
238 239 240 241 |
# File 'lib/adhearsion/call_controller/output.rb', line 238 def play_numeric!(number) raise ArgumentError unless number.kind_of?(Numeric) || number =~ /^\d+$/ async_player.play_ssml output_formatter.ssml_for_numeric(number) end |
#play_time(time, options = {}) ⇒ Object
Plays the given Date, Time, or Integer (seconds since epoch) using the given timezone and format.
186 187 188 189 190 |
# File 'lib/adhearsion/call_controller/output.rb', line 186 def play_time(time, = {}) raise ArgumentError unless [Date, Time, DateTime].include?(time.class) && .is_a?(Hash) player.play_ssml output_formatter.ssml_for_time(time, ) true end |
#play_time!(time, options = {}) ⇒ Punchblock::Component::Output
Plays the given Date, Time, or Integer (seconds since epoch) using the given timezone and format and returns as soon as it begins.
208 209 210 211 |
# File 'lib/adhearsion/call_controller/output.rb', line 208 def play_time!(time, = {}) raise ArgumentError unless [Date, Time, DateTime].include?(time.class) && .is_a?(Hash) async_player.play_ssml output_formatter.ssml_for_time(time, ) end |
#say(text, options = {}) ⇒ Object Also known as: speak
Speak output using text-to-speech (TTS)
24 25 26 27 |
# File 'lib/adhearsion/call_controller/output.rb', line 24 def say(text, = {}) return unless text player.play_ssml(text, ) || player.output(output_formatter.ssml_for_text(text.to_s), ) end |
#say!(text, options = {}) ⇒ Object Also known as: speak!
Speak output using text-to-speech (TTS) and return as soon as it begins
38 39 40 41 |
# File 'lib/adhearsion/call_controller/output.rb', line 38 def say!(text, = {}) return unless text async_player.play_ssml(text, ) || async_player.output(output_formatter.ssml_for_text(text.to_s), ) end |
#say_characters(characters, options = {}) ⇒ Object
Speak characters using text-to-speech (TTS)
55 56 57 58 |
# File 'lib/adhearsion/call_controller/output.rb', line 55 def say_characters(characters, = {}) player.play_ssml output_formatter.ssml_for_characters(characters), true end |
#say_characters!(characters, options = {}) ⇒ Object
Speak characters using text-to-speech (TTS) and return as soon as it begins
70 71 72 |
# File 'lib/adhearsion/call_controller/output.rb', line 70 def say_characters!(characters, = {}) async_player.play_ssml output_formatter.ssml_for_characters(characters), end |