Sha256: 79febfca89ac78f0bc80e0c8929368db2f4c1e084fc1e7b1a04187f372fbefe0

Contents?: true

Size: 1.57 KB

Versions: 17

Compression:

Stored size: 1.57 KB

Contents

# encoding: utf-8

module Punchblock
  module Translator
    class Freeswitch
      module Component
        class Output < AbstractOutput
          private

          def validate
            super
            filenames
          end

          def do_output
            playback "file_string://#{filenames.join('!')}"
          end

          def filenames
            @filenames ||= @component_node.render_documents.map do |doc|
              doc.value.children.map do |node|
                case node
                when RubySpeech::SSML::Audio
                  node.src
                when String
                  raise if node.include?(' ')
                  node
                else
                  raise
                end
              end
            end.compact.flatten
          rescue
            raise UnrenderableDocError, 'The provided document could not be rendered. See http://adhearsion.com/docs/common_problems#unrenderable-document-error for details.'
          end

          def playback(path)
            register_handler :es, :event_name => 'CHANNEL_EXECUTE_COMPLETE' do |event|
              send_complete_event complete_reason_for_event(event)
            end
            application 'playback', path
          end

          def complete_reason_for_event(event)
            case event[:application_response]
            when 'FILE PLAYED'
              finish_reason
            else
              Punchblock::Event::Complete::Error.new(:details => "Engine error: #{event[:application_response]}")
            end
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
punchblock-2.7.5 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.7.3 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.7.2 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.7.1 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.7.0 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.6.0 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.5.3 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.5.2 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.5.1 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.5.0 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.4.2 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.4.0 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.3.1 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.3.0 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.2.2 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.2.1 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.2.0 lib/punchblock/translator/freeswitch/component/output.rb