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
- PlaybackError =
Represents failure to play audio, such as when the sound file cannot be found
Class.new Adhearsion::Error
Instance Method Summary (collapse)
-
- (String?) interruptible_play(*outputs)
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.
-
- (Formatter) output_formatter
An output formatter for the preparation of SSML documents for submission to the engine.
-
- (Object) play(*arguments)
Plays the specified sound file names.
-
- (Object) play!(*arguments)
Plays the specified sound file names and returns as soon as it begins.
-
- (Object) play_audio(file, options = {})
Plays the given audio file.
-
- (Object) play_audio!(file, options = {})
Plays the given audio file and returns as soon as it begins.
-
- (Object) play_numeric(number)
Plays the given Numeric argument or string representing a decimal number.
-
- (Object) play_numeric!(number)
Plays the given Numeric argument or string representing a decimal number and returns as soon as it begins.
-
- (Object) play_time(time, options = {})
Plays the given Date, Time, or Integer (seconds since epoch) using the given timezone and format.
-
- (Object) play_time!(time, options = {})
Plays the given Date, Time, or Integer (seconds since epoch) using the given timezone and format and returns as soon as it begins.
-
- (Object) say(text, options = {})
(also: #speak)
Speak output using text-to-speech (TTS).
-
- (Object) say!(text, options = {})
(also: #speak!)
Speak output using text-to-speech (TTS) and return as soon as it begins.
Instance Method Details
- (String?) interruptible_play(*outputs)
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
221 222 223 224 225 226 227 |
# File 'lib/adhearsion/call_controller/output.rb', line 221 def interruptible_play(*outputs) = outputs outputs.find do |output| digit = stream_file output, '0123456789#*', return digit if digit end end |
- (Formatter) output_formatter
An output formatter for the preparation of SSML documents for submission to the engine
276 277 278 |
# File 'lib/adhearsion/call_controller/output.rb', line 276 def output_formatter Formatter.new end |
- (Object) play(*arguments)
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.
63 64 65 66 67 |
# File 'lib/adhearsion/call_controller/output.rb', line 63 def play(*arguments) = arguments player.play_ssml output_formatter.ssml_for_collection(arguments), true end |
- (Object) play!(*arguments)
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.
92 93 94 95 |
# File 'lib/adhearsion/call_controller/output.rb', line 92 def play!(*arguments) = arguments async_player.play_ssml output_formatter.ssml_for_collection(arguments), end |
- (Object) play_audio(file, options = {})
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.
109 110 111 112 113 |
# File 'lib/adhearsion/call_controller/output.rb', line 109 def play_audio(file, = {}) renderer = .delete :renderer player.play_ssml(output_formatter.ssml_for_audio(file, ), renderer: renderer) true end |
- (Object) play_audio!(file, options = {})
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.
127 128 129 130 |
# File 'lib/adhearsion/call_controller/output.rb', line 127 def play_audio!(file, = {}) renderer = .delete :renderer async_player.play_ssml(output_formatter.ssml_for_audio(file, ), renderer: renderer) end |
- (Object) play_numeric(number)
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”.
183 184 185 186 187 |
# File 'lib/adhearsion/call_controller/output.rb', line 183 def play_numeric(number) raise ArgumentError unless number.kind_of?(Numeric) || number =~ /^\d+$/ player.play_ssml output_formatter.ssml_for_numeric(number) true end |
- (Object) play_numeric!(number)
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”.
199 200 201 202 |
# File 'lib/adhearsion/call_controller/output.rb', line 199 def play_numeric!(number) raise ArgumentError unless number.kind_of?(Numeric) || number =~ /^\d+$/ async_player.play_ssml output_formatter.ssml_for_numeric(number) end |
- (Object) play_time(time, options = {})
Plays the given Date, Time, or Integer (seconds since epoch) using the given timezone and format.
147 148 149 150 151 |
# File 'lib/adhearsion/call_controller/output.rb', line 147 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 |
- (Object) play_time!(time, options = {})
Plays the given Date, Time, or Integer (seconds since epoch) using the given timezone and format and returns as soon as it begins.
169 170 171 172 |
# File 'lib/adhearsion/call_controller/output.rb', line 169 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 |
- (Object) say(text, options = {}) Also known as: speak
Speak output using text-to-speech (TTS)
23 24 25 |
# File 'lib/adhearsion/call_controller/output.rb', line 23 def say(text, = {}) player.play_ssml(text, ) || player.output(output_formatter.ssml_for_text(text.to_s), ) end |
- (Object) say!(text, options = {}) Also known as: speak!
Speak output using text-to-speech (TTS) and return as soon as it begins
36 37 38 |
# File 'lib/adhearsion/call_controller/output.rb', line 36 def say!(text, = {}) async_player.play_ssml(text, ) || async_player.output(output_formatter.ssml_for_text(text.to_s), ) end |