google_speech 0.3.3 → 0.4.0
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/google_speech.gemspec +1 -0
- data/lib/google_speech.rb +2 -0
- data/lib/google_speech/chunk.rb +6 -0
- data/lib/google_speech/chunk_factory.rb +8 -3
- data/lib/google_speech/transcriber.rb +28 -10
- data/lib/google_speech/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6813210970cbd391fc353833b73cf483fecb35be
|
4
|
+
data.tar.gz: 9800a202fb0bb0a66cf6e74f921021cb1f89f4f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f77c8400be4f09302c472fa3da92679ff557e8f1a44b1bf12830c76d233130e500bba99583e62d2921a7d8d6a5850fe717b716f923cd754f9b9a8e87ba52156b
|
7
|
+
data.tar.gz: c998ca0fee9037f8691ae0c68dd994b555a3c13073afde8f93d58e5e47f179555df5beb4f669356ef8bcff5297c5c7d1db379e98b016a3fc4dd6aef3457fca12
|
data/google_speech.gemspec
CHANGED
data/lib/google_speech.rb
CHANGED
data/lib/google_speech/chunk.rb
CHANGED
@@ -18,9 +18,14 @@ module GoogleSpeech
|
|
18
18
|
def each
|
19
19
|
pos = 0
|
20
20
|
while(pos < @original_duration) do
|
21
|
-
chunk =
|
22
|
-
|
23
|
-
|
21
|
+
chunk = nil
|
22
|
+
begin
|
23
|
+
chunk = Chunk.new(@original_file, @original_duration, pos, (@chunk_duration + @overlap), @rate)
|
24
|
+
yield chunk
|
25
|
+
pos = pos + [chunk.duration, @chunk_duration].min
|
26
|
+
ensure
|
27
|
+
chunk.close_file if chunk
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'excon'
|
4
4
|
require 'json'
|
5
|
+
require 'uuid'
|
5
6
|
|
6
7
|
module GoogleSpeech
|
7
8
|
|
@@ -31,21 +32,38 @@ module GoogleSpeech
|
|
31
32
|
@last_ua = 0
|
32
33
|
end
|
33
34
|
|
35
|
+
def open_working_file
|
36
|
+
Utility.check_local_file(@original_file.path)
|
37
|
+
wf_path = random_file_name(@original_file.path)
|
38
|
+
FileUtils.ln(@original_file.path, wf_path)
|
39
|
+
File.open(wf_path, 'r') {|f|
|
40
|
+
yield f
|
41
|
+
}
|
42
|
+
FileUtils.rm(wf_path, :force=>true)
|
43
|
+
end
|
44
|
+
|
45
|
+
def random_file_name(path)
|
46
|
+
File.join(GoogleSpeech::TMP_FILE_DIR, File.basename(path) + '_' + UUID.generate + '.wav')
|
47
|
+
end
|
48
|
+
|
34
49
|
def transcribe
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
50
|
+
open_working_file do |working_file|
|
51
|
+
chunk_factory = ChunkFactory.new(working_file, options[:chunk_duration], options[:overlap], options[:rate])
|
52
|
+
chunk_factory.each{ |chunk|
|
53
|
+
result = chunk.to_hash
|
54
|
+
transcript = transcribe_data(chunk.data)
|
55
|
+
next unless transcript
|
40
56
|
|
41
|
-
|
57
|
+
result = result.merge(extract_result(transcript))
|
42
58
|
|
43
|
-
|
59
|
+
logger.debug "#{result[:start_time]}: #{(result[:confidence].to_f * 100).to_i}%: #{result[:text]}"
|
44
60
|
|
45
|
-
|
61
|
+
@results << result
|
62
|
+
|
63
|
+
sleep(options[:request_pause].to_i)
|
64
|
+
}
|
65
|
+
end
|
46
66
|
|
47
|
-
sleep(options[:request_pause].to_i)
|
48
|
-
}
|
49
67
|
@results
|
50
68
|
end
|
51
69
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_speech
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kuklewicz
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: uuid
|
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'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|