Sha256: d7722714d4c86221a2560e24adfea127347d3bf4f5fa86206c6ba987831a7a48

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

module WatsonTtsAsrClient
  class ClientFactory
    def initialize(data, websocket_client)
      @data = data
      @websocket_client = websocket_client
    end

    def process
      the_result = nil
      @websocket_client.callout(format_msg, @data) do |result|
        STDERR.puts "My result is: #{result.get_json}"
        STDERR.puts "REsult data: #{result.data}"
        the_result = result
      end
      return the_result
    end

    def format_msg
      #sending audio data or sending text
      if @data.encoding.name == "ASCII-8BIT"
        return ({ action: "start", :"content-type"=>"audio/l16;rate=22050" }.to_json)
      elsif @data.encoding.name == "UTF-8"
        return ({ text: @data, accept: "audio/wav "}.to_json ) 
      else
        raise ArgumentError, "Invalid encoding for #{@data} with encoding: #{@data.encoding}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
watson_tts_asr_client-0.1.0 lib/websocket/client_factory.rb