Module: Adhearsion::CallController::Output
- 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
- #locale ⇒ Object
- #locale=(l) ⇒ Object
-
#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) ⇒ Adhearsion::Rayo::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 = {}) ⇒ Adhearsion::Rayo::Component::Output
Plays the given audio file and returns as soon as it begins.
-
#play_document(url, options = {}) ⇒ Object
Plays the given SSML document from a URL.
-
#play_document!(url, options = {}) ⇒ Adhearsion::Rayo::Component::Output
Plays the given SSML document from a URL and returns as soon as it begins.
-
#play_numeric(number, options = {}) ⇒ Object
Plays the given Numeric argument or string representing a decimal number.
-
#play_numeric!(number, options = {}) ⇒ Adhearsion::Rayo::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 = {}) ⇒ Adhearsion::Rayo::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.
- #t(key, options = {}) ⇒ Object
Instance Method Details
#locale ⇒ Object
279 280 281 |
# File 'lib/adhearsion/call_controller/output.rb', line 279 def locale call[:locale] || Adhearsion::I18n.locale end |
#locale=(l) ⇒ Object
283 284 285 |
# File 'lib/adhearsion/call_controller/output.rb', line 283 def locale=(l) call[:locale] = l end |
#output_formatter ⇒ Formatter
Returns an output formatter for the preparation of SSML documents for submission to the engine.
310 311 312 |
# File 'lib/adhearsion/call_controller/output.rb', line 310 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.
100 101 102 103 104 105 106 107 |
# File 'lib/adhearsion/call_controller/output.rb', line 100 def play(*outputs, ) = outputs, ssml = output_formatter.ssml_for_collection(outputs) || return player.play_ssml ssml, true rescue NoDocError false end |
#play!(*outputs, options) ⇒ Adhearsion::Rayo::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.
135 136 137 138 139 140 141 |
# File 'lib/adhearsion/call_controller/output.rb', line 135 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.
153 154 155 156 |
# File 'lib/adhearsion/call_controller/output.rb', line 153 def play_audio(file, = {}) player.play_ssml(output_formatter.ssml_for_audio(file, ), ) true end |
#play_audio!(file, options = {}) ⇒ Adhearsion::Rayo::Component::Output
Plays the given audio file and returns as soon as it begins. SSML supports http:// paths and full disk paths.
169 170 171 |
# File 'lib/adhearsion/call_controller/output.rb', line 169 def play_audio!(file, = {}) async_player.play_ssml(output_formatter.ssml_for_audio(file, ), ) end |
#play_document(url, options = {}) ⇒ Object
Plays the given SSML document from a URL.
255 256 257 258 259 |
# File 'lib/adhearsion/call_controller/output.rb', line 255 def play_document(url, = {}) raise ArgumentError unless url =~ URI::regexp player.play_url url, true end |
#play_document!(url, options = {}) ⇒ Adhearsion::Rayo::Component::Output
Plays the given SSML document from a URL and returns as soon as it begins.
270 271 272 273 |
# File 'lib/adhearsion/call_controller/output.rb', line 270 def play_document!(url, = {}) raise ArgumentError unless url =~ URI::regexp async_player.play_url url, end |
#play_numeric(number, options = {}) ⇒ 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”.
225 226 227 228 229 |
# File 'lib/adhearsion/call_controller/output.rb', line 225 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, options = {}) ⇒ Adhearsion::Rayo::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”.
242 243 244 245 |
# File 'lib/adhearsion/call_controller/output.rb', line 242 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.
188 189 190 191 192 |
# File 'lib/adhearsion/call_controller/output.rb', line 188 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 = {}) ⇒ Adhearsion::Rayo::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.
210 211 212 213 |
# File 'lib/adhearsion/call_controller/output.rb', line 210 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)
25 26 27 28 |
# File 'lib/adhearsion/call_controller/output.rb', line 25 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
39 40 41 42 |
# File 'lib/adhearsion/call_controller/output.rb', line 39 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)
56 57 58 59 |
# File 'lib/adhearsion/call_controller/output.rb', line 56 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
71 72 73 |
# File 'lib/adhearsion/call_controller/output.rb', line 71 def say_characters!(characters, = {}) async_player.play_ssml output_formatter.ssml_for_characters(characters), end |
#t(key, options = {}) ⇒ Object
275 276 277 |
# File 'lib/adhearsion/call_controller/output.rb', line 275 def t(key, = {}) Adhearsion::I18n.t key, { locale: locale }.merge( || {}) end |