speechmatics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +80 -0
- data/Rakefile +11 -0
- data/lib/speechmatics.rb +18 -0
- data/lib/speechmatics/api.rb +99 -0
- data/lib/speechmatics/api_factory.rb +13 -0
- data/lib/speechmatics/client.rb +11 -0
- data/lib/speechmatics/configuration.rb +57 -0
- data/lib/speechmatics/connection.rb +52 -0
- data/lib/speechmatics/resource.rb +5 -0
- data/lib/speechmatics/response.rb +69 -0
- data/lib/speechmatics/user.rb +12 -0
- data/lib/speechmatics/user/jobs.rb +44 -0
- data/lib/speechmatics/version.rb +5 -0
- data/speechmatics.gemspec +35 -0
- data/test/api_test.rb +35 -0
- data/test/client_test.rb +12 -0
- data/test/test_helper.rb +12 -0
- data/test/user/jobs_test.rb +111 -0
- data/test/user_test.rb +37 -0
- data/test/zero.wav +0 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8210e8986392a652fa4ea9d32323d4291deccdc8
|
4
|
+
data.tar.gz: de715dde74d262783322600f20a111f84fa5f178
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52379bcdd89a082000f6fe8b5a966139eceabc5376ed30868ff216d71ebc5b5739192b54e41f06f06a1816ba1eb6f3a38ae49f24c9e97de2004b85e9e5382330
|
7
|
+
data.tar.gz: 6be9eb916d965a78239f4f59ee8e4203b6ea153123f0ee9dfa695b2909ff3f1faca2b867ea52db0570e20aea4254a14bbcaf49bd5cd9f2e921b3c0c47da33b9e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Public Radio Exchange
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Speechmatics
|
2
|
+
|
3
|
+
Speechmatics (https://speechmatics.com) provides an API for speech to text (https://speechmatics.com/api-details. This gem implements the API making it easier to integrate into Ruby and/or Rails projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### libmagic
|
8
|
+
|
9
|
+
This gem will attempt to derive the content type of uploaded audio files using the 'ruby-filemagic' gem (https://github.com/blackwinter/ruby-filemagic), which requires the 'libmagic' native library to be installed.
|
10
|
+
|
11
|
+
You can explicitly specify the `content_type` for the `data_file`, and libmagic will not be called.
|
12
|
+
|
13
|
+
### gem
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'speechmatics'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install speechmatics
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
See the tests, or here is basic usage:
|
30
|
+
```ruby
|
31
|
+
|
32
|
+
# configure with api key and user id to use for all requsts
|
33
|
+
Speechmatics.configure do |sm|
|
34
|
+
sm.auth_token = '<your api key here>'
|
35
|
+
sm.user_id = 1234
|
36
|
+
|
37
|
+
# these are defaults
|
38
|
+
sm.adapter = :excon
|
39
|
+
sm.endpoint = 'http://api.speechmatics.com/v1.0/'
|
40
|
+
sm.user_agent = "Speechmatics Ruby Gem #{Speechmatics::VERSION}"
|
41
|
+
end
|
42
|
+
|
43
|
+
# create a new client
|
44
|
+
c = Speechmatics::Client.new
|
45
|
+
|
46
|
+
# retrieve user
|
47
|
+
j = c.user.get
|
48
|
+
|
49
|
+
# list jobs
|
50
|
+
jobs = c.user.jobs.list
|
51
|
+
|
52
|
+
# create job
|
53
|
+
info = c.user.jobs.create(data_file: '/Users/nobody/dev/speechmatics/test/zero.wav')
|
54
|
+
|
55
|
+
# create job with more options
|
56
|
+
info = c.user.jobs.create(
|
57
|
+
data_file: '/Users/nobody/dev/speechmatics/test/zero.wav',
|
58
|
+
content_type: 'audio/x-wav; charset=binary',
|
59
|
+
notification: '<email | none | callback>',
|
60
|
+
callback: 'http://www.example.com/transcript_callback'
|
61
|
+
)
|
62
|
+
|
63
|
+
# retrieve job
|
64
|
+
job = c.user.jobs.find(5678)
|
65
|
+
|
66
|
+
# retrieve audio for a job
|
67
|
+
audio = c.user.jobs(5678).audio
|
68
|
+
|
69
|
+
# retrieve trancript for a job
|
70
|
+
trans = c.user.jobs(5678).transcript
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/speechmatics.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
require "speechmatics/version"
|
7
|
+
require 'speechmatics/configuration'
|
8
|
+
require 'speechmatics/connection'
|
9
|
+
require 'speechmatics/response'
|
10
|
+
require 'speechmatics/api'
|
11
|
+
require 'speechmatics/api_factory'
|
12
|
+
require 'speechmatics/client'
|
13
|
+
require 'speechmatics/user'
|
14
|
+
require 'speechmatics/user/jobs'
|
15
|
+
|
16
|
+
module Speechmatics
|
17
|
+
extend Configuration
|
18
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Speechmatics
|
4
|
+
class API
|
5
|
+
|
6
|
+
include Connection
|
7
|
+
|
8
|
+
attr_reader *Speechmatics::Configuration.keys
|
9
|
+
|
10
|
+
attr_accessor :current_options
|
11
|
+
|
12
|
+
class_eval do
|
13
|
+
Speechmatics::Configuration.keys.each do |key|
|
14
|
+
define_method "#{key}=" do |arg|
|
15
|
+
self.instance_variable_set("@#{key}", arg)
|
16
|
+
self.current_options.merge!({:"#{key}" => arg})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(options={}, &block)
|
22
|
+
apply_options(options)
|
23
|
+
yield(self) if block_given?
|
24
|
+
end
|
25
|
+
|
26
|
+
def apply_options(options={})
|
27
|
+
self.current_options ||= ActiveSupport::HashWithIndifferentAccess.new(Speechmatics.options)
|
28
|
+
self.current_options = current_options.merge(args_to_options(options))
|
29
|
+
Configuration.keys.each do |key|
|
30
|
+
send("#{key}=", current_options[key])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def request(method, path, params={}) # :nodoc:
|
35
|
+
unless (method && [:get, :post, :put, :patch, :delete].include?(method))
|
36
|
+
raise ArgumentError, "whoops, that isn't a valid http method: #{method}"
|
37
|
+
end
|
38
|
+
|
39
|
+
conn = connection((params[:options] || {}).merge(current_options))
|
40
|
+
request_path = (conn.path_prefix + '/' + path).gsub(/\/+/, '/')
|
41
|
+
|
42
|
+
response = conn.send(method) do |request|
|
43
|
+
case method.to_sym
|
44
|
+
when :get, :delete
|
45
|
+
request.url(request_path, params)
|
46
|
+
when :post, :put
|
47
|
+
request.path = request_path
|
48
|
+
request.body = params[:data]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
Speechmatics::Response.new(response, {api: self, method: method, path: path, params: params})
|
52
|
+
end
|
53
|
+
|
54
|
+
def base_path
|
55
|
+
parts = self.class.name.split("::").inject([]){|a, c|
|
56
|
+
if c != 'Speechmatics'
|
57
|
+
base = c.underscore
|
58
|
+
a << base.tr('_','-')
|
59
|
+
a << current_options["#{base.singularize}_id"] if current_options["#{base.singularize}_id"]
|
60
|
+
end
|
61
|
+
a
|
62
|
+
}
|
63
|
+
parts.join('/') + '/'
|
64
|
+
end
|
65
|
+
|
66
|
+
def list(params={})
|
67
|
+
self.current_options = current_options.merge(args_to_options(params))
|
68
|
+
request(:get, base_path)
|
69
|
+
end
|
70
|
+
|
71
|
+
def get(params={})
|
72
|
+
self.current_options = current_options.merge(args_to_options(params))
|
73
|
+
request(:get, base_path)
|
74
|
+
end
|
75
|
+
|
76
|
+
def create(params={})
|
77
|
+
self.current_options = current_options.merge(args_to_options(params))
|
78
|
+
request(:post, base_path, {data: params})
|
79
|
+
end
|
80
|
+
|
81
|
+
def update(params={})
|
82
|
+
self.current_options = current_options.merge(args_to_options(params))
|
83
|
+
request(:put, base_path, {data: params})
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete(params={})
|
87
|
+
self.current_options = current_options.merge(args_to_options(params))
|
88
|
+
request(:delete, base_path)
|
89
|
+
end
|
90
|
+
|
91
|
+
def args_to_options(args)
|
92
|
+
params = if args.is_a?(String) || args.is_a?(Symbol)
|
93
|
+
{"#{self.class.name.demodulize.downcase.singularize}_id" => args}
|
94
|
+
elsif args.is_a?(Hash)
|
95
|
+
args
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Speechmatics
|
4
|
+
class ApiFactory
|
5
|
+
|
6
|
+
def self.api(name, parent, options={}, &block)
|
7
|
+
api = name.constantize.new(parent.current_options)
|
8
|
+
api.apply_options(options)
|
9
|
+
yield(api) if block_given?
|
10
|
+
api
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Speechmatics
|
4
|
+
module Configuration
|
5
|
+
|
6
|
+
VALID_OPTIONS_KEYS = [
|
7
|
+
:user_id,
|
8
|
+
:auth_token,
|
9
|
+
:adapter,
|
10
|
+
:endpoint,
|
11
|
+
:user_agent
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
# Adapters are whatever Faraday supports - I like excon alot, so I'm defaulting it
|
15
|
+
DEFAULT_ADAPTER = :excon
|
16
|
+
|
17
|
+
# The api endpoint to get REST
|
18
|
+
DEFAULT_ENDPOINT = 'http://api.speechmatics.com/v1.0/'.freeze
|
19
|
+
|
20
|
+
# The value sent in the http header for 'User-Agent' if none is set
|
21
|
+
DEFAULT_USER_AGENT = "Speechmatics Ruby Gem #{Speechmatics::VERSION}".freeze
|
22
|
+
|
23
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
24
|
+
|
25
|
+
# Convenience method to allow for global setting of configuration options
|
26
|
+
def configure
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.extended(base)
|
31
|
+
base.reset!
|
32
|
+
end
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def keys
|
36
|
+
VALID_OPTIONS_KEYS
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def options
|
41
|
+
options = {}
|
42
|
+
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
|
43
|
+
options
|
44
|
+
end
|
45
|
+
|
46
|
+
# Reset configuration options to their defaults
|
47
|
+
def reset!
|
48
|
+
self.user_id = nil
|
49
|
+
self.auth_token = nil
|
50
|
+
self.adapter = DEFAULT_ADAPTER
|
51
|
+
self.endpoint = DEFAULT_ENDPOINT
|
52
|
+
self.user_agent = DEFAULT_USER_AGENT
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'faraday_middleware'
|
4
|
+
|
5
|
+
module Speechmatics
|
6
|
+
module Connection
|
7
|
+
|
8
|
+
ALLOWED_OPTIONS = [
|
9
|
+
:headers,
|
10
|
+
:url,
|
11
|
+
:params,
|
12
|
+
:request,
|
13
|
+
:ssl
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
def merge_default_options(opts={})
|
17
|
+
opts = opts.slice(*ALLOWED_OPTIONS)
|
18
|
+
headers = opts.delete(:headers) || {}
|
19
|
+
params = opts.delete(:params) || {}
|
20
|
+
options = HashWithIndifferentAccess.new(
|
21
|
+
{
|
22
|
+
headers: {
|
23
|
+
'User-Agent' => user_agent,
|
24
|
+
'Accept' => "application/json"
|
25
|
+
},
|
26
|
+
ssl: { verify: false },
|
27
|
+
url: endpoint,
|
28
|
+
params: { auth_token: auth_token }
|
29
|
+
}
|
30
|
+
).merge(opts)
|
31
|
+
options[:headers] = options[:headers].merge(headers)
|
32
|
+
options[:params] = options[:params].merge(params)
|
33
|
+
options
|
34
|
+
end
|
35
|
+
|
36
|
+
def connection(options={})
|
37
|
+
opts = merge_default_options(options)
|
38
|
+
|
39
|
+
@conn ||= Faraday::Connection.new(opts) do |connection|
|
40
|
+
connection.request :multipart
|
41
|
+
connection.request :url_encoded
|
42
|
+
|
43
|
+
connection.response :mashify
|
44
|
+
connection.response :logger if ENV['DEBUG']
|
45
|
+
connection.response :json
|
46
|
+
|
47
|
+
connection.adapter(*adapter)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Speechmatics
|
4
|
+
class Response
|
5
|
+
attr_accessor :raw, :request
|
6
|
+
|
7
|
+
def initialize(response, request={})
|
8
|
+
@raw = response
|
9
|
+
@request = request
|
10
|
+
|
11
|
+
check_for_error(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_for_error(response)
|
15
|
+
status_code_type = response.status.to_s[0]
|
16
|
+
case status_code_type
|
17
|
+
when "2"
|
18
|
+
# puts "all is well, status: #{response.status}"
|
19
|
+
when "4", "5"
|
20
|
+
raise "Whoops, error back from Speechmatics: #{response.status}"
|
21
|
+
else
|
22
|
+
raise "Unrecongized status code: #{response.status}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def body
|
27
|
+
self.raw.body
|
28
|
+
end
|
29
|
+
|
30
|
+
def object_name
|
31
|
+
self.request[:api].class.name.split("::").last.underscore
|
32
|
+
end
|
33
|
+
|
34
|
+
def object
|
35
|
+
body[object_name].nil? ? body : body[object_name]
|
36
|
+
end
|
37
|
+
|
38
|
+
def objects
|
39
|
+
Array(self.object)
|
40
|
+
end
|
41
|
+
|
42
|
+
def [](key)
|
43
|
+
if self.object.is_a?(Array) || self.object.is_a?(Hash)
|
44
|
+
self.object[key]
|
45
|
+
else
|
46
|
+
self.object.send(:"#{key}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_key?(key)
|
51
|
+
self.object.is_a?(Hash) && self.object.has_key?(key)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Coerce any method calls for body attributes
|
55
|
+
#
|
56
|
+
def method_missing(method_name, *args, &block)
|
57
|
+
if self.has_key?(method_name.to_s)
|
58
|
+
self.[](method_name, &block)
|
59
|
+
elsif self.body.respond_to?(method_name)
|
60
|
+
self.body.send(method_name, *args, &block)
|
61
|
+
elsif self.request[:api].respond_to?(method_name)
|
62
|
+
self.request[:api].send(method_name, *args, &block)
|
63
|
+
else
|
64
|
+
super
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'filemagic'
|
4
|
+
|
5
|
+
module Speechmatics
|
6
|
+
class User::Jobs < API
|
7
|
+
include Configuration
|
8
|
+
|
9
|
+
def create(params={})
|
10
|
+
attach_audio(params)
|
11
|
+
set_mode(params)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def transcript(params={})
|
16
|
+
self.current_options = current_options.merge(args_to_options(params))
|
17
|
+
request(:get, "#{base_path}/transcript")
|
18
|
+
end
|
19
|
+
|
20
|
+
def audio(params={})
|
21
|
+
self.current_options = current_options.merge(args_to_options(params))
|
22
|
+
request(:get, "#{base_path}/audio")
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_mode(params={})
|
26
|
+
params[:mode] ||= 'en-US'
|
27
|
+
params
|
28
|
+
end
|
29
|
+
|
30
|
+
def attach_audio(params={})
|
31
|
+
file_path = params[:data_file]
|
32
|
+
raise "No file specified for new job, please provide a :data_file value" unless file_path
|
33
|
+
raise "No file exists at path '#{file_path}'" unless File.exists?(file_path)
|
34
|
+
|
35
|
+
content_type = params[:content_type] || FileMagic.mime.file(file_path)
|
36
|
+
raise "No content type specified for file, please provide a :content_type value" unless content_type
|
37
|
+
raise "Content type for file '#{file_path}' is not audio, it is '#{content_type}'." unless (content_type =~ /audio/)
|
38
|
+
|
39
|
+
params[:data_file] = Faraday::UploadIO.new(file_path, content_type)
|
40
|
+
params
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'speechmatics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "speechmatics"
|
8
|
+
spec.version = Speechmatics::VERSION
|
9
|
+
spec.authors = ["Andrew Kuklewicz"]
|
10
|
+
spec.email = ["andrew@beginsinwonder.com"]
|
11
|
+
spec.description = %q{Ruby client for Speechmatics API: https://speechmatics.com/api-details}
|
12
|
+
spec.summary = %q{Ruby client for Speechmatics API: https://speechmatics.com/api-details}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency('faraday')
|
22
|
+
spec.add_runtime_dependency('faraday_middleware')
|
23
|
+
spec.add_runtime_dependency('multi_json')
|
24
|
+
spec.add_runtime_dependency('excon')
|
25
|
+
spec.add_runtime_dependency('hashie')
|
26
|
+
spec.add_runtime_dependency('activesupport')
|
27
|
+
spec.add_runtime_dependency('ruby-filemagic', '~> 0.6.0')
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
|
32
|
+
spec.add_development_dependency('minitest')
|
33
|
+
spec.add_development_dependency('simplecov')
|
34
|
+
spec.add_development_dependency('webmock')
|
35
|
+
end
|
data/test/api_test.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
4
|
+
|
5
|
+
# create dummy class based on the API
|
6
|
+
class TestApi < ::Speechmatics::API
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Speechmatics::API do
|
10
|
+
|
11
|
+
before {
|
12
|
+
@speechmatics_user_id = ENV['SPEECHMATICS_USER_ID'] || 1
|
13
|
+
@speechmatics_auth_token = ENV['SPEECHMATICS_API_KEY'] || "thisisatestkeyonly"
|
14
|
+
}
|
15
|
+
|
16
|
+
it "is initialized with defaults" do
|
17
|
+
oc = TestApi.new
|
18
|
+
oc.current_options.wont_be_nil
|
19
|
+
oc.current_options.must_equal HashWithIndifferentAccess.new(Speechmatics.options)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is initialized with specific values" do
|
23
|
+
oc = TestApi.new(auth_token: @speechmatics_auth_token, user_id: @speechmatics_user_id)
|
24
|
+
oc.current_options.wont_be_nil
|
25
|
+
oc.current_options.wont_equal Speechmatics.options
|
26
|
+
|
27
|
+
oc.current_options[:auth_token].must_equal @speechmatics_auth_token
|
28
|
+
oc.auth_token.must_equal @speechmatics_auth_token
|
29
|
+
|
30
|
+
oc.current_options[:user_id].must_equal @speechmatics_user_id
|
31
|
+
oc.user_id.must_equal @speechmatics_user_id
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
data/test/client_test.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
4
|
+
|
5
|
+
describe Speechmatics::Client do
|
6
|
+
|
7
|
+
let(:new_job) {
|
8
|
+
{
|
9
|
+
balance: 90,
|
10
|
+
cost: 0.50,
|
11
|
+
id: 2
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:list_jobs) {
|
16
|
+
{
|
17
|
+
"jobs" => [
|
18
|
+
{
|
19
|
+
"created_at" => "Wed, 04 Dec 2013 16:00:47 GMT",
|
20
|
+
"duration" => 244,
|
21
|
+
"id" => 2,
|
22
|
+
"lang" => "en-US",
|
23
|
+
"name" => "test.mp3",
|
24
|
+
"next_check" => 0,
|
25
|
+
"notification" => "email",
|
26
|
+
"size" => 1955132,
|
27
|
+
"transcription" => "test.json",
|
28
|
+
"job_status" => "done",
|
29
|
+
"url" => "/user/1/jobs/2/audio"
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"created_at" => "Wed, 04 Dec 2013 16:08:33 GMT",
|
33
|
+
"duration" => 244,
|
34
|
+
"id" => 12,
|
35
|
+
"lang" => "en-GB",
|
36
|
+
"name" => "second-test.mp3",
|
37
|
+
"next_check" => 1389966796,
|
38
|
+
"notification" => "email",
|
39
|
+
"size" => 6475938,
|
40
|
+
"transcription" => nil,
|
41
|
+
"job_status" => "transcribing",
|
42
|
+
"url" => "/user/1/jobs/12/audio"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
let(:transcript) {
|
49
|
+
{
|
50
|
+
"speakers" => [
|
51
|
+
{
|
52
|
+
"duration" => "1.270",
|
53
|
+
"name" => "M1",
|
54
|
+
"time" => "0.590"
|
55
|
+
}
|
56
|
+
],
|
57
|
+
"words" => [
|
58
|
+
{
|
59
|
+
"duration" => "0.230",
|
60
|
+
"name" => "Hello",
|
61
|
+
"time" => "0.590"
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"duration" => "0.070",
|
65
|
+
"name" => "World",
|
66
|
+
"time" => "0.960"
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"duration" => "0.000",
|
70
|
+
"name" => ".",
|
71
|
+
"time" => "1.270"
|
72
|
+
}
|
73
|
+
]
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
let(:stubs) {
|
78
|
+
Faraday::Adapter::Test::Stubs.new do |stub|
|
79
|
+
stub.get('/v1.0/user/1/jobs/?auth_token=token') { [200, {}, list_jobs.to_json] }
|
80
|
+
stub.post('/v1.0/user/1/jobs/?auth_token=token') { [200, {}, new_job.to_json] }
|
81
|
+
stub.get('/v1.0/user/1/jobs/1/transcript?auth_token=token') { [200, {}, transcript.to_json] }
|
82
|
+
end
|
83
|
+
}
|
84
|
+
|
85
|
+
let(:jobs) {
|
86
|
+
Speechmatics::User::Jobs.new(
|
87
|
+
user_id: 1,
|
88
|
+
auth_token: 'token',
|
89
|
+
adapter: [:test, stubs])
|
90
|
+
}
|
91
|
+
|
92
|
+
it "lists jobs" do
|
93
|
+
jl = jobs.list
|
94
|
+
jl.objects.count.must_equal 2
|
95
|
+
jl.jobs.count.must_equal 2
|
96
|
+
end
|
97
|
+
|
98
|
+
it "creates job" do
|
99
|
+
r = jobs.create(data_file: File.expand_path(File.dirname(__FILE__) + '/../zero.wav'))
|
100
|
+
r.id.must_equal 2
|
101
|
+
r.cost.must_equal 0.50
|
102
|
+
r.balance.must_equal 90
|
103
|
+
end
|
104
|
+
|
105
|
+
it "gets transcript" do
|
106
|
+
t = jobs.transcript(job_id: 1)
|
107
|
+
t.speakers.count.must_equal 1
|
108
|
+
t.words.count.must_equal 3
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
data/test/user_test.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
4
|
+
|
5
|
+
describe Speechmatics::Client do
|
6
|
+
|
7
|
+
let(:response) {
|
8
|
+
{
|
9
|
+
user: {
|
10
|
+
balance: 90,
|
11
|
+
email: "demo@speechmatics.com",
|
12
|
+
id: 1
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:stubs) {
|
18
|
+
Faraday::Adapter::Test::Stubs.new do |stub|
|
19
|
+
stub.get('/v1.0/user/1/?auth_token=token') { [200, {}, response.to_json] }
|
20
|
+
end
|
21
|
+
}
|
22
|
+
|
23
|
+
let(:user) {
|
24
|
+
Speechmatics::User.new(
|
25
|
+
user_id: 1,
|
26
|
+
auth_token: 'token',
|
27
|
+
adapter: [:test, stubs])
|
28
|
+
}
|
29
|
+
|
30
|
+
it "user can request profile" do
|
31
|
+
u = user.get
|
32
|
+
u.balance.must_equal 90
|
33
|
+
u.email.must_equal "demo@speechmatics.com"
|
34
|
+
u.id.must_equal 1
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/test/zero.wav
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: speechmatics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kuklewicz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: excon
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ruby-filemagic
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.6.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.6.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bundler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: minitest
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: 'Ruby client for Speechmatics API: https://speechmatics.com/api-details'
|
182
|
+
email:
|
183
|
+
- andrew@beginsinwonder.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- .gitignore
|
189
|
+
- Gemfile
|
190
|
+
- LICENSE
|
191
|
+
- README.md
|
192
|
+
- Rakefile
|
193
|
+
- lib/speechmatics.rb
|
194
|
+
- lib/speechmatics/api.rb
|
195
|
+
- lib/speechmatics/api_factory.rb
|
196
|
+
- lib/speechmatics/client.rb
|
197
|
+
- lib/speechmatics/configuration.rb
|
198
|
+
- lib/speechmatics/connection.rb
|
199
|
+
- lib/speechmatics/resource.rb
|
200
|
+
- lib/speechmatics/response.rb
|
201
|
+
- lib/speechmatics/user.rb
|
202
|
+
- lib/speechmatics/user/jobs.rb
|
203
|
+
- lib/speechmatics/version.rb
|
204
|
+
- speechmatics.gemspec
|
205
|
+
- test/api_test.rb
|
206
|
+
- test/client_test.rb
|
207
|
+
- test/test_helper.rb
|
208
|
+
- test/user/jobs_test.rb
|
209
|
+
- test/user_test.rb
|
210
|
+
- test/zero.wav
|
211
|
+
homepage: ''
|
212
|
+
licenses:
|
213
|
+
- MIT
|
214
|
+
metadata: {}
|
215
|
+
post_install_message:
|
216
|
+
rdoc_options: []
|
217
|
+
require_paths:
|
218
|
+
- lib
|
219
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - '>='
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0'
|
224
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - '>='
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
requirements: []
|
230
|
+
rubyforge_project:
|
231
|
+
rubygems_version: 2.1.11
|
232
|
+
signing_key:
|
233
|
+
specification_version: 4
|
234
|
+
summary: 'Ruby client for Speechmatics API: https://speechmatics.com/api-details'
|
235
|
+
test_files:
|
236
|
+
- test/api_test.rb
|
237
|
+
- test/client_test.rb
|
238
|
+
- test/test_helper.rb
|
239
|
+
- test/user/jobs_test.rb
|
240
|
+
- test/user_test.rb
|
241
|
+
- test/zero.wav
|