Module: SpeechToText::IbmWatsonS2T
- Includes:
- Util
- Defined in:
- lib/speech_to_text/ibm.rb
Overview
rubocop:disable Style/Documentation
Class Method Summary collapse
- .check_job(job_id, apikey) ⇒ Object
-
.create_array_watson(data) ⇒ Object
create array from json file rubocop:disable Metrics/MethodLength.
-
.create_job(audio_file_path:, apikey:, audio:, content_type:, language_code: 'en-US') ⇒ Object
create new job on watson server by uploading audio function returns 2 variables IBMWatson::SpeechToTextV1 object and jobid.
Methods included from Util
captions_json, recording_json, seconds_to_timestamp, video_to_audio, write_to_webvtt
Class Method Details
.check_job(job_id, apikey) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# 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) ⇒ Object
create array from json file rubocop:disable Metrics/MethodLength
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# 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') ⇒ Object
create new job on watson server by uploading audio function returns 2 variables IBMWatson::SpeechToTextV1 object and jobid
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |