From 09750b0dddc8835ad29c9b96ac1cd1f9d56a1374 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Fri, 7 Feb 2014 08:02:17 -0500 Subject: [PATCH 1/2] explicitly specify binary mode reading audio file Old Ruby (1.8) assumes binary mode; newer Ruby does not. Explicitly specify binary mode so the code works with newer Ruby. --- lib/att/codekit/service/speech.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/att/codekit/service/speech.rb b/lib/att/codekit/service/speech.rb index 1b8b73a..43b6457 100644 --- a/lib/att/codekit/service/speech.rb +++ b/lib/att/codekit/service/speech.rb @@ -51,7 +51,7 @@ def stdSpeechToText(file, opts={}) x_arg_val = URI.escape(xArgs) - filecontents = File.read(file) + filecontents = File.read(file, :mode => "rb") filetype = CloudService.getMimeType file @@ -124,7 +124,7 @@ def customSpeechToText(audio_file, dictionary, grammar, opts={}) } file_part = { :headers => fheaders, - :data => File.read(audio_file) + :data => File.read(audio_file, :mode => "rb") } multipart = [dict_part, grammar_part, file_part] From ab67f20bf9a6855e06d5ad6c0a200461e7e3984f Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Fri, 7 Feb 2014 15:03:43 -0500 Subject: [PATCH 2/2] Allow access to the unaltered server json --- lib/att/codekit/model/speech.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/att/codekit/model/speech.rb b/lib/att/codekit/model/speech.rb index 943a185..6f10c6f 100644 --- a/lib/att/codekit/model/speech.rb +++ b/lib/att/codekit/model/speech.rb @@ -7,6 +7,9 @@ module Model # Response of a speech request class SpeechResponse < ImmutableStruct.new(:id, :status, :nbest) + + attr_accessor :original_json + # @!attribute [r] id # @return [String] the id of the request made # @!attribute [r] status @@ -20,7 +23,9 @@ class SpeechResponse < ImmutableStruct.new(:id, :status, :nbest) # # @return [SpeechResponse] a parsed object def self.createFromJson(json) - self.createFromParsedJson(JSON.parse(json)) + newobj = self.createFromParsedJson(JSON.parse(json)) + newobj.original_json = json + newobj end # Factory method to create an object from a json string