speechmatics 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/README.md +2 -0
- data/lib/speechmatics/api.rb +2 -2
- data/lib/speechmatics/configuration.rb +1 -1
- data/lib/speechmatics/connection.rb +1 -11
- data/lib/speechmatics/user/jobs.rb +7 -3
- data/lib/speechmatics/version.rb +1 -1
- data/test/test_helper.rb +2 -0
- data/test/user/jobs_test.rb +37 -4
- data/test/user_test.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 697e88c1f9ebedcd924258f0332ae03a9706614a
|
4
|
+
data.tar.gz: 1af5416ff390993bf5fa5f7764987523a629c30b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b30b8bb3f74917f546a137e4714733a153370efc2fa21d9a892d386f129a63356f11fb7f5e478369d128fdab966f8e5232091f5e6d3fb0926b9350803f13b74e
|
7
|
+
data.tar.gz: cf3fef36e28878fe53475ca88914b7fb77252d1f67db8d9f866f580464c1e6b2a25578470020ca7a926db65932962a1364521409fe9b4882dba6cdad534d62ef
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -72,6 +72,8 @@ trans = c.user.jobs.transcript(5678)
|
|
72
72
|
```
|
73
73
|
|
74
74
|
## Changes
|
75
|
+
* 0.2.2 - 9 July 2018
|
76
|
+
- Permit requesting transcriptions in text/plain, or mixed requests. Thanks @benlangfeld
|
75
77
|
|
76
78
|
* 0.2.1 - 13 Sept 2017
|
77
79
|
- Updated error handling with a class for each error type. Thanks @mziwisky
|
data/lib/speechmatics/api.rb
CHANGED
@@ -5,7 +5,7 @@ module Speechmatics
|
|
5
5
|
|
6
6
|
include Connection
|
7
7
|
|
8
|
-
attr_reader
|
8
|
+
attr_reader(*Speechmatics::Configuration.keys)
|
9
9
|
|
10
10
|
attr_accessor :current_options
|
11
11
|
|
@@ -89,7 +89,7 @@ module Speechmatics
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def args_to_options(args)
|
92
|
-
|
92
|
+
if args.is_a?(String) || args.is_a?(Symbol) || args.is_a?(Numeric)
|
93
93
|
{"#{self.class.name.demodulize.downcase.singularize}_id" => args.to_s}
|
94
94
|
elsif args.is_a?(Hash)
|
95
95
|
args
|
@@ -20,7 +20,7 @@ module Speechmatics
|
|
20
20
|
# The value sent in the http header for 'User-Agent' if none is set
|
21
21
|
DEFAULT_USER_AGENT = "Speechmatics Ruby Gem #{Speechmatics::VERSION}".freeze
|
22
22
|
|
23
|
-
attr_accessor
|
23
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
24
24
|
|
25
25
|
# Convenience method to allow for global setting of configuration options
|
26
26
|
def configure
|
@@ -30,12 +30,6 @@ module Speechmatics
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def connection(options={})
|
33
|
-
if options[:allow_text]
|
34
|
-
allow_text = true
|
35
|
-
options.delete(:allow_text)
|
36
|
-
else
|
37
|
-
allow_text =false
|
38
|
-
end
|
39
33
|
opts = merge_default_options(options)
|
40
34
|
|
41
35
|
@conn ||= Faraday::Connection.new(opts) do |connection|
|
@@ -55,11 +49,7 @@ module Speechmatics
|
|
55
49
|
|
56
50
|
connection.response :mashify
|
57
51
|
connection.response :logger if ENV['DEBUG']
|
58
|
-
|
59
|
-
connection.response :json, :content_type => /\bjson$/
|
60
|
-
else
|
61
|
-
connection.response :json
|
62
|
-
end
|
52
|
+
connection.response :json, :content_type => /\bjson$/
|
63
53
|
connection.adapter(*adapter)
|
64
54
|
end
|
65
55
|
end
|
@@ -15,12 +15,16 @@ module Speechmatics
|
|
15
15
|
|
16
16
|
def transcript(params={})
|
17
17
|
self.current_options = current_options.merge(args_to_options(params))
|
18
|
-
|
18
|
+
if params[:format] == "txt"
|
19
|
+
request(:get, "#{base_path}/transcript?format=txt")
|
20
|
+
else
|
21
|
+
request(:get, "#{base_path}/transcript")
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
def alignment(params={})
|
22
26
|
self.current_options = current_options.merge(args_to_options(params))
|
23
|
-
request(:get, "#{base_path}/alignment"
|
27
|
+
request(:get, "#{base_path}/alignment")
|
24
28
|
end
|
25
29
|
|
26
30
|
def set_mode(params={})
|
@@ -33,7 +37,7 @@ module Speechmatics
|
|
33
37
|
def attach_audio(params={})
|
34
38
|
file_path = params[:data_file]
|
35
39
|
raise "No file specified for new job, please provide a :data_file value" unless file_path
|
36
|
-
raise "No file exists at path '#{file_path}'" unless File.
|
40
|
+
raise "No file exists at path '#{file_path}'" unless File.exist?(file_path)
|
37
41
|
|
38
42
|
content_type = params[:content_type] || MimeMagic.by_path(file_path).to_s
|
39
43
|
raise "No content type specified for file, please provide a :content_type value" unless content_type
|
data/lib/speechmatics/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/user/jobs_test.rb
CHANGED
@@ -72,11 +72,17 @@ describe Speechmatics::Client do
|
|
72
72
|
}
|
73
73
|
}
|
74
74
|
|
75
|
+
let(:alignment) {
|
76
|
+
"[00:00:00.1] Hello world how are you?"
|
77
|
+
}
|
78
|
+
|
75
79
|
let(:stubs) {
|
76
80
|
Faraday::Adapter::Test::Stubs.new do |stub|
|
77
|
-
stub.get('/v1.0/user/1/jobs/?auth_token=token') { [200, {}, list_jobs.to_json] }
|
78
|
-
stub.post('/v1.0/user/1/jobs/?auth_token=token') { [200, {}, new_job.to_json] }
|
79
|
-
stub.get('/v1.0/user/1/jobs/1/transcript?auth_token=token') { [200, {},
|
81
|
+
stub.get('/v1.0/user/1/jobs/?auth_token=token') { [200, {"Content-Type" => "application/json"}, list_jobs.to_json] }
|
82
|
+
stub.post('/v1.0/user/1/jobs/?auth_token=token') { [200, {"Content-Type" => "application/json"}, new_job.to_json] }
|
83
|
+
stub.get('/v1.0/user/1/jobs/1/transcript?format=txt&auth_token=token') { [200, {"Content-Type" => "text/plain"}, "Hello World."] }
|
84
|
+
stub.get('/v1.0/user/1/jobs/1/transcript?auth_token=token') { [200, {"Content-Type" => "application/json"}, transcript.to_json] }
|
85
|
+
stub.get('/v1.0/user/1/jobs/1/alignment?auth_token=token') { [200, {"Content-Type" => "text/plain"}, alignment] }
|
80
86
|
end
|
81
87
|
}
|
82
88
|
|
@@ -99,7 +105,7 @@ describe Speechmatics::Client do
|
|
99
105
|
r.cost.must_equal 0.50
|
100
106
|
r.balance.must_equal 90
|
101
107
|
end
|
102
|
-
|
108
|
+
|
103
109
|
it "creates job for a video file" do
|
104
110
|
r = jobs.create(data_file: File.expand_path(File.dirname(__FILE__) + '/../zero.mp4'))
|
105
111
|
r.id.must_equal 2
|
@@ -113,4 +119,31 @@ describe Speechmatics::Client do
|
|
113
119
|
t.words.count.must_equal 3
|
114
120
|
end
|
115
121
|
|
122
|
+
it "gets transcript as text" do
|
123
|
+
t = jobs.transcript(job_id: 1, format: "txt")
|
124
|
+
t.object.must_equal "Hello World."
|
125
|
+
end
|
126
|
+
|
127
|
+
it "can align a text representation of the audio" do
|
128
|
+
a = jobs.alignment(job_id: 1)
|
129
|
+
a.object.must_equal alignment
|
130
|
+
end
|
131
|
+
|
132
|
+
it "can fetch txt transcription after fetching full" do
|
133
|
+
t1 = jobs.transcript(job_id: 1)
|
134
|
+
t1.speakers.count.must_equal 1
|
135
|
+
t1.words.count.must_equal 3
|
136
|
+
|
137
|
+
t2 = jobs.transcript(job_id: 1, format: "txt")
|
138
|
+
t2.object.must_equal "Hello World."
|
139
|
+
end
|
140
|
+
|
141
|
+
it "can fetch alignment after fetching transcription" do
|
142
|
+
t = jobs.transcript(job_id: 1)
|
143
|
+
t.speakers.count.must_equal 1
|
144
|
+
t.words.count.must_equal 3
|
145
|
+
|
146
|
+
a = jobs.alignment(job_id: 1)
|
147
|
+
a.object.must_equal alignment
|
148
|
+
end
|
116
149
|
end
|
data/test/user_test.rb
CHANGED
@@ -7,8 +7,8 @@ describe Speechmatics::Client do
|
|
7
7
|
let(:response) {
|
8
8
|
{
|
9
9
|
user: {
|
10
|
-
balance: 90,
|
11
|
-
email: "demo@speechmatics.com",
|
10
|
+
balance: 90,
|
11
|
+
email: "demo@speechmatics.com",
|
12
12
|
id: 1
|
13
13
|
}
|
14
14
|
}
|
@@ -16,7 +16,7 @@ describe Speechmatics::Client do
|
|
16
16
|
|
17
17
|
let(:stubs) {
|
18
18
|
Faraday::Adapter::Test::Stubs.new do |stub|
|
19
|
-
stub.get('/v1.0/user/1/?auth_token=token') { [200, {}, response.to_json] }
|
19
|
+
stub.get('/v1.0/user/1/?auth_token=token') { [200, {"Content-Type" => "application/json"}, response.to_json] }
|
20
20
|
end
|
21
21
|
}
|
22
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: speechmatics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kuklewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|