Sha256: 5d2da6481861698a32520bd1b833aeff66b70d03e0d9e72f205489ef79974f1d

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 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.first.value.children.map do |node|
              case node
              when RubySpeech::SSML::Audio
                node.src
              when String
                raise if node.include?(' ')
                node
              else
                raise
              end
            end.compact
          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

7 entries across 7 versions & 1 rubygems

Version Path
punchblock-2.1.1 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.1.0 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.0.2 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.0.1 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.0.0 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.0.0.beta2 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-2.0.0.beta1 lib/punchblock/translator/freeswitch/component/output.rb