Class: Speechmatics::User::Jobs

Inherits:
API
  • Object
show all
Includes:
Configuration
Defined in:
lib/speechmatics/user/jobs.rb

Constant Summary

Constants included from Configuration

Configuration::DEFAULT_ADAPTER, Configuration::DEFAULT_ENDPOINT, Configuration::DEFAULT_USER_AGENT, Configuration::VALID_OPTIONS_KEYS

Constants included from Connection

Connection::ALLOWED_OPTIONS

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods included from Configuration

#configure, extended, keys, #options, #reset!

Methods inherited from API

#apply_options, #args_to_options, #base_path, #delete, #get, #initialize, #list, #request, #update

Methods included from Connection

#connection, #merge_default_options

Constructor Details

This class inherits a constructor from Speechmatics::API

Instance Method Details

#alignment(params = {}) ⇒ Object



21
22
23
24
# File 'lib/speechmatics/user/jobs.rb', line 21

def alignment(params={})
  self.current_options = current_options.merge(args_to_options(params))
  request(:get, "#{base_path}/alignment", {:options => {:allow_text => true}})
end

#attach_audio(params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/speechmatics/user/jobs.rb', line 33

def attach_audio(params={})
  file_path = params[:data_file]
  raise "No file specified for new job, please provide a :data_file value" unless file_path
  raise "No file exists at path '#{file_path}'" unless File.exists?(file_path)

  content_type = params[:content_type] || MimeMagic.by_path(file_path).to_s
  raise "No content type specified for file, please provide a :content_type value" unless content_type
  raise "Content type for file '#{file_path}' is not audio or video, it is '#{content_type}'." unless (content_type =~ /audio|video/)

  params[:data_file] = Faraday::UploadIO.new(file_path, content_type)
  params
end

#attach_text(params = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/speechmatics/user/jobs.rb', line 46

def attach_text(params={})
  file_path = params[:text_file]
  raise "No file exists at path '#{file_path}'" unless File.exists?(file_path)
  params[:text_file] = Faraday::UploadIO.new(file_path, "text/plain; charset=utf-8",)
  params
end

#create(params = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/speechmatics/user/jobs.rb', line 9

def create(params={})
  attach_audio(params)
  attach_text(params) if params[:text_file]
  set_mode(params)
  super
end

#set_mode(params = {}) ⇒ Object



26
27
28
29
30
31
# File 'lib/speechmatics/user/jobs.rb', line 26

def set_mode(params={})
  unless params[:text_file]
    params[:model] ||= 'en-US'
  end
  params
end

#transcript(params = {}) ⇒ Object



16
17
18
19
# File 'lib/speechmatics/user/jobs.rb', line 16

def transcript(params={})
  self.current_options = current_options.merge(args_to_options(params))
  request(:get, "#{base_path}/transcript")
end