speech2text 0.0.3 → 0.01
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.
- data/README.rdoc +4 -11
- data/bin/speech2text +0 -5
- data/lib/speech.rb +0 -1
- data/lib/speech/audio_inspector.rb +0 -1
- data/lib/speech/audio_splitter.rb +1 -2
- data/lib/speech/audio_to_text.rb +0 -6
- data/lib/speech/text.rb +11 -0
- data/lib/speech/version.rb +1 -2
- data/speech2text.gemspec +8 -9
- data/test/audio_inspector_test.rb +0 -1
- data/test/audio_splitter_test.rb +1 -2
- data/test/i-like-pickles.wav +0 -0
- metadata +9 -10
- data/test/audio_to_text_test.rb +0 -21
- data/test/samples/i-like-pickles.json +0 -1
data/README.rdoc
CHANGED
@@ -2,16 +2,9 @@
|
|
2
2
|
|
3
3
|
Using the power of ffmpeg/flac/Google and ruby here is a simple interface to play with to convert speech to text.
|
4
4
|
|
5
|
-
|
5
|
+
At this point the API from Google is not documented and seemly free.
|
6
|
+
The Google API will frequently return 500 errors without providing much reason as to why.
|
6
7
|
|
7
|
-
|
8
|
+
It's possible that Google will decide to not open this API up and this effort my completely be for not...
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
It also appears that the API only likes smaller audio files so there is a built in chunker that allows us to split the audio up into smaller chunks.
|
12
|
-
|
13
|
-
== Example
|
14
|
-
|
15
|
-
audio = Speech::AudioToText.new("i-like-pickles.wav")
|
16
|
-
puts audio.to_text.inspect
|
17
|
-
=> {"captured_json"=>[["I like pickles", 0.92731786]], "confidence"=>0.92731786}
|
10
|
+
This was all made possible in short order all thanks to Chrome 11 and http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
|
data/bin/speech2text
CHANGED
data/lib/speech.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: binary -*-
|
2
1
|
module Speech
|
3
2
|
|
4
3
|
class AudioSplitter
|
@@ -9,7 +8,7 @@ module Speech
|
|
9
8
|
|
10
9
|
def initialize(splitter, offset, duration)
|
11
10
|
self.offset = offset
|
12
|
-
self.chunk =
|
11
|
+
self.chunk = "chunk-" + splitter.original_file.gsub(/\.(.*)$/, "-#{offset}" + '.\1')
|
13
12
|
self.duration = duration
|
14
13
|
self.splitter = splitter
|
15
14
|
end
|
data/lib/speech/audio_to_text.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: binary -*-
|
2
1
|
module Speech
|
3
2
|
|
4
3
|
class AudioToText
|
@@ -22,10 +21,6 @@ module Speech
|
|
22
21
|
JSON.parse(File.read(self.captured_file))
|
23
22
|
end
|
24
23
|
|
25
|
-
def clean
|
26
|
-
File.unlink self.captured_file if self.captured_file && File.exist?(self.captured_file)
|
27
|
-
end
|
28
|
-
|
29
24
|
protected
|
30
25
|
|
31
26
|
def convert_chunk(easy, chunk, options={})
|
@@ -34,7 +29,6 @@ module Speech
|
|
34
29
|
while retrying
|
35
30
|
#easy.verbose = true
|
36
31
|
easy.headers['Content-Type'] = "audio/x-flac; rate=#{chunk.flac_rate}"
|
37
|
-
easy.headers['User-Agent'] = "https://github.com/taf2/speech2text"
|
38
32
|
easy.post_body = "Content=#{chunk.to_flac_bytes}"
|
39
33
|
easy.on_progress {|dl_total, dl_now, ul_total, ul_now| printf("%.2f/%.2f\r", ul_now, ul_total); true }
|
40
34
|
easy.on_complete {|easy| puts }
|
data/lib/speech/text.rb
ADDED
data/lib/speech/version.rb
CHANGED
data/speech2text.gemspec
CHANGED
@@ -2,15 +2,14 @@ $:.unshift File.expand_path(File.dirname(__FILE__) + "/lib")
|
|
2
2
|
require "speech/version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.authors
|
7
|
-
s.email
|
8
|
-
s.version
|
9
|
-
s.homepage
|
10
|
-
s.summary
|
11
|
-
s.description
|
12
|
-
s.files
|
13
|
-
s.executables = %w(speech2text)
|
5
|
+
s.name = "speech2text"
|
6
|
+
s.authors = ["Todd A. Fisher"]
|
7
|
+
s.email = "todd.fisher@gmail.com"
|
8
|
+
s.version = Speech::Info::VERSION
|
9
|
+
s.homepage = "https://github.com/taf2/speech2text"
|
10
|
+
s.summary = "Speech to Text Library"
|
11
|
+
s.description = "Super powers of Google wrapped in a nice Ruby interface"
|
12
|
+
s.files = Dir["{lib,bin,test}/**/*", "Rakefile", "README.rdoc", "*.gemspec"]
|
14
13
|
|
15
14
|
s.add_dependency "curb"
|
16
15
|
s.add_dependency "json"
|
data/test/audio_splitter_test.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: binary -*-
|
2
1
|
require 'test/unit'
|
3
2
|
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
3
|
require 'speech'
|
@@ -6,7 +5,7 @@ require 'speech'
|
|
6
5
|
class SpeechAudioSplitterTest < Test::Unit::TestCase
|
7
6
|
|
8
7
|
def test_audio_splitter
|
9
|
-
splitter = Speech::AudioSplitter.new("
|
8
|
+
splitter = Speech::AudioSplitter.new("i-like-pickles.wav", 1)
|
10
9
|
|
11
10
|
assert_equal '00:00:03:52', splitter.duration.to_s
|
12
11
|
assert_equal 3.52, splitter.duration.to_f
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: speech2text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.01'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-03-
|
12
|
+
date: 2011-03-24 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: curb
|
17
|
-
requirement: &
|
17
|
+
requirement: &2157005460 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2157005460
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: json
|
28
|
-
requirement: &
|
28
|
+
requirement: &2157005040 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,25 +33,24 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2157005040
|
37
37
|
description: Super powers of Google wrapped in a nice Ruby interface
|
38
38
|
email: todd.fisher@gmail.com
|
39
|
-
executables:
|
40
|
-
- speech2text
|
39
|
+
executables: []
|
41
40
|
extensions: []
|
42
41
|
extra_rdoc_files: []
|
43
42
|
files:
|
44
43
|
- lib/speech/audio_inspector.rb
|
45
44
|
- lib/speech/audio_splitter.rb
|
46
45
|
- lib/speech/audio_to_text.rb
|
46
|
+
- lib/speech/text.rb
|
47
47
|
- lib/speech/version.rb
|
48
48
|
- lib/speech.rb
|
49
49
|
- bin/speech2text
|
50
50
|
- test/audio_inspector_test.rb
|
51
51
|
- test/audio_splitter_test.rb
|
52
|
-
- test/
|
52
|
+
- test/i-like-pickles.wav
|
53
53
|
- test/SampleAudio.wav
|
54
|
-
- test/samples/i-like-pickles.json
|
55
54
|
- test/samples/i-like-pickles.wav
|
56
55
|
- Rakefile
|
57
56
|
- README.rdoc
|
data/test/audio_to_text_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- encoding: binary -*-
|
2
|
-
require 'test/unit'
|
3
|
-
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
-
require 'speech'
|
5
|
-
|
6
|
-
class SpeechAudioToTextTest < Test::Unit::TestCase
|
7
|
-
def test_audio_to_text
|
8
|
-
audio = Speech::AudioToText.new("samples/i-like-pickles.wav")
|
9
|
-
captured_json = audio.to_text
|
10
|
-
assert captured_json
|
11
|
-
assert captured_json.key?("captured_json")
|
12
|
-
assert !captured_json['captured_json'].empty?
|
13
|
-
assert_equal ['captured_json', 'confidence'], captured_json.keys.sort
|
14
|
-
assert_equal "I like pickles", captured_json['captured_json'].flatten.first
|
15
|
-
assert captured_json['confidence'] > 0.9
|
16
|
-
# {"captured_json"=>[["I like pickles", 0.92731786]], "confidence"=>0.92731786}
|
17
|
-
# puts captured_json.inspect
|
18
|
-
ensure
|
19
|
-
audio.clean
|
20
|
-
end
|
21
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
{"captured_json":[["I like pickles",0.92731786]],"confidence":0.92731786}
|