module SpeechToText::IbmWatsonS2T
Public Class Methods
check_job(job_id, apikey)
click to toggle source
# File lib/speech_to_text/ibm.rb, line 47 def self.check_job(job_id, apikey) if job_id.nil? || job_id == 'Error! job not created' puts 'job not created' else speech_to_text = IBMWatson::SpeechToTextV1.new(iam_apikey: apikey) service_response = speech_to_text.check_job(id: job_id) return service_response.result end 'job not found..' # To create watson array pass service_response.result["results"][0] # myarray = create_array_watson service_response.result["results"][0] end
create_array_watson(data)
click to toggle source
create array from json file rubocop:disable Metrics/MethodLength
# File lib/speech_to_text/ibm.rb, line 62 def self.create_array_watson(data) # rubocop:disable Metrics/AbcSize if data != 'can not make request' k = 0 myarray = [] while k != data['results'].length j = 0 while j != data['results'][k]['alternatives'].length i = 0 # rubocop:disable Metrics/BlockNesting while i != data['results'][k]['alternatives'][j]['timestamps'].length first = data['results'][k]['alternatives'][j]['timestamps'][i][1] last = data['results'][k]['alternatives'][j]['timestamps'][i][2] transcript = data['results'][k]['alternatives'][j]['timestamps'][i][0] if transcript.include? '%HESITATION' transcript['%HESITATION'] = '' end myarray.push(first) myarray.push(last) myarray.push(transcript) i += 1 end # rubocop:enable Metrics/BlockNesting confidence = data['results'][k]['alternatives'][j]['confidence'] myarray[myarray.length - 2] = myarray[myarray.length - 2] + confidence j += 1 end k += 1 end myarray else 'array not created' end end
create_job( audio_file_path:, apikey:, audio:, content_type:, language_code: 'en-US' )
click to toggle source
create new job on watson server by uploading audio function returns 2 variables IBMWatson::SpeechToTextV1 object and jobid
# File lib/speech_to_text/ibm.rb, line 21 def self.create_job( # rubocop:disable Metrics/MethodLength audio_file_path:, apikey:, audio:, content_type:, language_code: 'en-US' ) job_id = 'Error! job not created' unless apikey.nil? speech_to_text = IBMWatson::SpeechToTextV1.new(iam_apikey: apikey) end if audio_file_path.nil? || audio.nil? || content_type.nil? puts 'audio file not found..' puts 'try again and be careful with file path, audio name and content type' else audio_file = File.open("#{audio_file_path}/#{audio}.#{content_type}") service_response = speech_to_text.create_job(audio: audio_file, content_type: "audio/#{content_type}", timestamps: true, model: "#{language_code}_BroadbandModel") job_id = service_response.result['id'] end job_id end