Module: SpeechToText::SpeechmaticsS2T

Includes:
Util
Defined in:
lib/speech_to_text/speechmatics.rb

Overview

rubocop:disable Style/Documentation

Class Method Summary collapse

Methods included from Util

captions_json, recording_json, seconds_to_timestamp, video_to_audio, write_to_webvtt

Class Method Details

.check_job(userID, jobID, authKey) ⇒ Object

check status of specific jobid rubocop:disable Naming/UncommunicativeMethodParamName rubocop:disable Naming/VariableName



52
53
54
55
56
57
58
59
60
# 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) ⇒ Object

rubocop:enable Naming/UncommunicativeMethodParamName



74
75
76
77
78
79
80
81
82
83
84
# 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) ⇒ Object

rubocop:disable Naming/UncommunicativeMethodParamName rubocop:disable Naming/VariableName rubocop:disable Metrics/ParameterLists



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object

rubocop:disable Naming/UncommunicativeMethodParamName rubocop:disable Naming/VariableName



65
66
67
68
69
70
71
# 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