module SpeechToText::SpeechmaticsS2T
Public Class Methods
check_job(userID, jobID, authKey)
click to toggle source
check status of specific jobid rubocop:disable Naming/UncommunicativeMethodParamName rubocop:disable Naming/VariableName
# File lib/speech_to_text/speechmatics.rb, line 52 def self.check_job(userID, jobID, authKey) # rubocop:enable Naming/VariableName uri = URI.parse("https://api.speechmatics.com/v1.0/user/#{userID}/jobs/#{jobID}/?auth_token=#{authKey}") response = Net::HTTP.get_response(uri) job_data = JSON.load response.body wait_time = job_data['job']['check_wait'] # job_status = job_data["job"]["job_status"] wait_time end
create_array_speechmatic(data)
click to toggle source
rubocop:enable Naming/UncommunicativeMethodParamName
# File lib/speech_to_text/speechmatics.rb, line 74 def self.create_array_speechmatic(data) # rubocop:disable Metrics/AbcSize myarray = [] i = 0 while i != data['words'].length myarray.push(data['words'][i]['time'].to_f) myarray.push(data['words'][i]['time'].to_f + data['words'][i]['duration'].to_f) myarray.push(data['words'][i]['name']) i += 1 end myarray end
create_job(audio_file_path, audio_name, audio_content_type, userID, authKey, model, jobID_json_file)
click to toggle source
rubocop:disable Naming/UncommunicativeMethodParamName rubocop:disable Naming/VariableName rubocop:disable Metrics/ParameterLists
# File lib/speech_to_text/speechmatics.rb, line 24 def self.create_job(audio_file_path, audio_name, audio_content_type, userID, authKey, model, jobID_json_file) # rubocop:enable Metrics/ParameterLists # rubocop:enable Naming/VariableName upload_audio = "curl -F data_file=@#{audio_file_path}/#{audio_name}.#{audio_content_type} -F model=#{model} \"https://api.speechmatics.com/v1.0/user/#{userID}/jobs/?auth_token=#{authKey}\" > #{jobID_json_file}" Open3.popen2e(upload_audio) do |stdin, stdout_err, wait_thr| while line = stdout_err.gets puts "#{line}" end exit_status = wait_thr.value unless exit_status.success? puts '---------------------' puts "FAILED to execute --> #{upload_audio}" puts '---------------------' end end file = File.open(jobID_json_file) data = JSON.load file jobID = data['id'] # rubocop:disable Naming/VariableName jobID end
get_transcription(userID, jobID, authKey)
click to toggle source
rubocop:disable Naming/UncommunicativeMethodParamName rubocop:disable Naming/VariableName
# File lib/speech_to_text/speechmatics.rb, line 65 def self.get_transcription(userID, jobID, authKey) # rubocop:enable Naming/VariableName uri = URI.parse("https://api.speechmatics.com/v1.0/user/#{userID}/jobs/#{jobID}/transcript?auth_token=#{authKey}") response = Net::HTTP.get_response(uri) data = JSON.load response.body data end