Sha256: 54935e6516e6d66b8156f4dc573ea6c6ceea1dceea133f77954902164103ca75

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 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.ssml.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'
              success_reason
            else
              Punchblock::Event::Complete::Error.new(:details => "Engine error: #{event[:application_response]}")
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
punchblock-1.9.4 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-1.9.3 lib/punchblock/translator/freeswitch/component/output.rb
punchblock-1.9.2 lib/punchblock/translator/freeswitch/component/output.rb