pocketsphinx-ruby 0.3.0 → 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/.travis.yml +3 -4
- data/CHANGELOG.md +5 -0
- data/README.md +5 -0
- data/lib/pocketsphinx/api/pocketsphinx.rb +5 -0
- data/lib/pocketsphinx/api/sphinxbase.rb +0 -1
- data/lib/pocketsphinx/configuration/grammar.rb +0 -1
- data/lib/pocketsphinx/decoder.rb +13 -2
- data/lib/pocketsphinx/speech_recognizer.rb +7 -4
- data/lib/pocketsphinx/version.rb +1 -1
- data/pocketsphinx-ruby.gemspec +1 -1
- data/spec/configuration_spec.rb +4 -4
- data/spec/decoder_spec.rb +9 -2
- data/spec/integration/decoder_spec.rb +8 -5
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1299af5883e11346cca23dff74ba7015670384d0
|
4
|
+
data.tar.gz: 504770d54160fcf2bbcfc80e9910dd4283063e9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dfaec5b4603b38344646fa77e41d941d70ac0455fb3932eecb8949f7e463d2f08c7f64d033df14067dd5e51e227f7b2aa180aa25eeec365e6603b55b03ea2fa
|
7
|
+
data.tar.gz: 0fa93e6bd7b2a37b3a0775c0ce045cb9666a13d97a0ef740798732268eea250e59d0cde41c3a1da7ce37afc0072c85917d31665defe7c9e46dec16be0dafc1f1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -224,3 +224,8 @@ An error like this probably means that you have an old version of the Pocketsphi
|
|
224
224
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
225
225
|
4. Push to the branch (`git push origin my-new-feature`)
|
226
226
|
5. Create a new Pull Request
|
227
|
+
|
228
|
+
### Projects Using pocketsphinx-ruby
|
229
|
+
|
230
|
+
* [Isabella](https://github.com/chrisvfritz/isabella) - A voice-computing assistant built in Ruby.
|
231
|
+
* [sphinxtrain-ruby](https://github.com/watsonbox/sphinxtrain-ruby) - A Toolkit for training/adapting CMU Sphinx acoustic models.
|
@@ -6,12 +6,16 @@ module Pocketsphinx
|
|
6
6
|
|
7
7
|
typedef :pointer, :decoder
|
8
8
|
typedef :pointer, :configuration
|
9
|
+
typedef :pointer, :logmath
|
9
10
|
|
10
11
|
# Allows expect(API::Pocketsphinx).to receive(:ps_init) in JRuby specs
|
11
12
|
def self.ps_init(*args)
|
12
13
|
ps_init_private(*args)
|
13
14
|
end
|
14
15
|
|
16
|
+
attach_function :ps_get_logmath, [:decoder], :logmath
|
17
|
+
attach_function :logmath_exp, [:logmath, :int], :double
|
18
|
+
|
15
19
|
attach_function :ps_init_private, :ps_init, [:configuration], :decoder
|
16
20
|
attach_function :ps_reinit, [:decoder, :configuration], :int
|
17
21
|
attach_function :ps_default_search_args, [:pointer], :void
|
@@ -22,6 +26,7 @@ module Pocketsphinx
|
|
22
26
|
attach_function :ps_end_utt, [:decoder], :int
|
23
27
|
attach_function :ps_get_in_speech, [:decoder], :uint8
|
24
28
|
attach_function :ps_get_hyp, [:decoder, :pointer], :string
|
29
|
+
attach_function :ps_get_prob, [:decoder], :int32
|
25
30
|
attach_function :ps_set_jsgf_string, [:decoder, :string, :string], :int
|
26
31
|
attach_function :ps_unset_search, [:decoder, :string], :int
|
27
32
|
attach_function :ps_get_search, [:decoder], :string
|
@@ -19,7 +19,6 @@ module Pocketsphinx
|
|
19
19
|
attach_function :cmd_ln_set_int_r, [:pointer, :string, :int], :void
|
20
20
|
attach_function :cmd_ln_str_r, [:pointer, :string], :string
|
21
21
|
attach_function :cmd_ln_set_str_r, [:pointer, :string, :string], :void
|
22
|
-
attach_function :err_set_debug_level, [:int], :int
|
23
22
|
attach_function :err_set_logfile, [:string], :int
|
24
23
|
attach_function :err_set_logfp, [:pointer], :void
|
25
24
|
end
|
@@ -12,7 +12,6 @@ module Pocketsphinx
|
|
12
12
|
# Since JSGF strings are not supported in Pocketsphinx configuration (only files),
|
13
13
|
# we use the post_init_decoder hook to configure the JSGF
|
14
14
|
def post_init_decoder(decoder)
|
15
|
-
decoder.unset_search
|
16
15
|
decoder.set_jsgf_string(grammar.raw)
|
17
16
|
decoder.set_search
|
18
17
|
end
|
data/lib/pocketsphinx/decoder.rb
CHANGED
@@ -6,9 +6,12 @@ module Pocketsphinx
|
|
6
6
|
|
7
7
|
class Hypothesis < SimpleDelegator
|
8
8
|
attr_accessor :path_score
|
9
|
+
attr_accessor :posterior_prob
|
9
10
|
|
10
|
-
def initialize(string, path_score)
|
11
|
+
def initialize(string, path_score, posterior_prob = nil)
|
11
12
|
@path_score = path_score
|
13
|
+
@posterior_prob = posterior_prob
|
14
|
+
|
12
15
|
super(string)
|
13
16
|
end
|
14
17
|
end
|
@@ -116,10 +119,12 @@ module Pocketsphinx
|
|
116
119
|
mp_path_score = FFI::MemoryPointer.new(:int32, 1)
|
117
120
|
|
118
121
|
hypothesis = ps_api.ps_get_hyp(ps_decoder, mp_path_score)
|
122
|
+
posterior_prob = ps_api.ps_get_prob(ps_decoder)
|
119
123
|
|
120
124
|
hypothesis.nil? ? nil : Hypothesis.new(
|
121
125
|
hypothesis,
|
122
|
-
mp_path_score.get_int32(0)
|
126
|
+
log_prob_to_linear(mp_path_score.get_int32(0)),
|
127
|
+
log_prob_to_linear(posterior_prob)
|
123
128
|
)
|
124
129
|
end
|
125
130
|
|
@@ -206,5 +211,11 @@ module Pocketsphinx
|
|
206
211
|
configuration.post_init_decoder(self)
|
207
212
|
end
|
208
213
|
end
|
214
|
+
|
215
|
+
# Convert logarithmic probability to linear floating point
|
216
|
+
def log_prob_to_linear(log_prob)
|
217
|
+
logmath = ps_api.ps_get_logmath(ps_decoder)
|
218
|
+
ps_api.logmath_exp(logmath, log_prob)
|
219
|
+
end
|
209
220
|
end
|
210
221
|
end
|
@@ -108,9 +108,10 @@ module Pocketsphinx
|
|
108
108
|
def recognize_continuous(max_samples, buffer)
|
109
109
|
process_audio(buffer, max_samples).tap do
|
110
110
|
if hypothesis = decoder.hypothesis
|
111
|
+
decoder.end_utterance
|
112
|
+
|
111
113
|
yield hypothesis
|
112
114
|
|
113
|
-
decoder.end_utterance
|
114
115
|
decoder.start_utterance
|
115
116
|
end
|
116
117
|
end
|
@@ -126,10 +127,12 @@ module Pocketsphinx
|
|
126
127
|
end
|
127
128
|
|
128
129
|
decoder.end_utterance
|
129
|
-
hypothesis = decoder.hypothesis
|
130
|
-
decoder.start_utterance
|
131
130
|
|
132
|
-
|
131
|
+
if hypothesis = decoder.hypothesis
|
132
|
+
yield hypothesis
|
133
|
+
end
|
134
|
+
|
135
|
+
decoder.start_utterance
|
133
136
|
end
|
134
137
|
|
135
138
|
process_audio(buffer, max_samples)
|
data/lib/pocketsphinx/version.rb
CHANGED
data/pocketsphinx-ruby.gemspec
CHANGED
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
24
|
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.6.0"
|
26
26
|
spec.add_development_dependency "coveralls"
|
27
27
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -65,7 +65,7 @@ describe Pocketsphinx::Configuration do
|
|
65
65
|
|
66
66
|
describe '#setting_names' do
|
67
67
|
it 'contains the names of all possible system settings' do
|
68
|
-
expect(subject.setting_names.count).to eq(
|
68
|
+
expect(subject.setting_names.count).to eq(113)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -74,9 +74,9 @@ describe Pocketsphinx::Configuration do
|
|
74
74
|
expect(subject.details 'vad_threshold').to eq({
|
75
75
|
name: "vad_threshold",
|
76
76
|
type: :float,
|
77
|
-
default:
|
77
|
+
default: 3.0,
|
78
78
|
required: false,
|
79
|
-
value:
|
79
|
+
value: 3.0,
|
80
80
|
info: "Threshold for decision between noise and silence frames. Log-ratio between signal level and noise level."
|
81
81
|
})
|
82
82
|
end
|
@@ -84,7 +84,7 @@ describe Pocketsphinx::Configuration do
|
|
84
84
|
it 'gives details for all settings when no name is specified' do
|
85
85
|
details = subject.details
|
86
86
|
|
87
|
-
expect(details.count).to eq(
|
87
|
+
expect(details.count).to eq(113)
|
88
88
|
expect(details.first).to eq({
|
89
89
|
name: "agc",
|
90
90
|
type: :string,
|
data/spec/decoder_spec.rb
CHANGED
@@ -143,7 +143,7 @@ describe Pocketsphinx::Decoder do
|
|
143
143
|
describe '#hypothesis' do
|
144
144
|
it 'calls libpocketsphinx' do
|
145
145
|
expect(ps_api)
|
146
|
-
.to receive(:ps_get_hyp) do |ps_decoder, mp_path_score|
|
146
|
+
.to receive(:ps_get_hyp).ordered do |ps_decoder, mp_path_score|
|
147
147
|
expect(ps_decoder).to eq(subject.ps_decoder)
|
148
148
|
expect(mp_path_score).to be_a(FFI::MemoryPointer)
|
149
149
|
|
@@ -152,10 +152,17 @@ describe Pocketsphinx::Decoder do
|
|
152
152
|
"Hypothesis"
|
153
153
|
end
|
154
154
|
|
155
|
+
expect(ps_api).to receive(:ps_get_prob).with(subject.ps_decoder).ordered.and_return(1)
|
156
|
+
expect(ps_api).to receive(:ps_get_logmath).with(subject.ps_decoder).ordered.and_return(:logmath)
|
157
|
+
expect(ps_api).to receive(:logmath_exp).with(:logmath, 20).ordered.and_return(0.5)
|
158
|
+
expect(ps_api).to receive(:ps_get_logmath).with(subject.ps_decoder).ordered.and_return(:logmath)
|
159
|
+
expect(ps_api).to receive(:logmath_exp).with(:logmath, 1).ordered.and_return(0.4)
|
160
|
+
|
155
161
|
hypothesis = subject.hypothesis
|
156
162
|
|
157
163
|
expect(hypothesis).to eq("Hypothesis")
|
158
|
-
expect(hypothesis.path_score).to eq(
|
164
|
+
expect(hypothesis.path_score).to eq(0.5)
|
165
|
+
expect(hypothesis.posterior_prob).to eq(0.4)
|
159
166
|
end
|
160
167
|
end
|
161
168
|
|
@@ -11,14 +11,17 @@ describe Pocketsphinx::Decoder do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'reads cmninit configuration values from default acoustic model feat.params' do
|
14
|
-
expect(configuration.details('cmninit')[:default]).to eq("
|
15
|
-
expect(configuration.details('cmninit')[:value]).to eq("
|
14
|
+
expect(configuration.details('cmninit')[:default]).to eq("40,3,-1")
|
15
|
+
expect(configuration.details('cmninit')[:value]).to eq("41.00,-5.29,-0.12,5.09,2.48,-4.07,-1.37,-1.78,-5.08,-2.05,-6.45,-1.42,1.17")
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '#decode' do
|
19
19
|
it 'correctly decodes the speech in goforward.raw' do
|
20
20
|
subject.decode File.open('spec/assets/audio/goforward.raw', 'rb')
|
21
21
|
expect(subject.hypothesis).to eq("go forward ten meters")
|
22
|
+
|
23
|
+
expect(subject.hypothesis.path_score).to eq(0.49327822492667395)
|
24
|
+
expect(subject.hypothesis.posterior_prob).to eq(0.037719430745321664)
|
22
25
|
end
|
23
26
|
|
24
27
|
# FIXME: This test illustrates a current issue discussed in:
|
@@ -40,9 +43,9 @@ describe Pocketsphinx::Decoder do
|
|
40
43
|
it 'reports words with start/end frame values' do
|
41
44
|
subject.decode File.open('spec/assets/audio/goforward.raw', 'rb')
|
42
45
|
|
43
|
-
expect(subject.words.map(&:word)).to eq(["<s>", "go", "forward", "ten", "meters", "</s>"])
|
44
|
-
expect(subject.words.map(&:start_frame)).to eq([0, 46, 64, 117, 153, 212])
|
45
|
-
expect(subject.words.map(&:end_frame)).to eq([45, 63, 116, 152, 211, 260])
|
46
|
+
expect(subject.words.map(&:word)).to eq(["<s>", "<sil>", "go", "forward", "ten", "meters", "</s>"])
|
47
|
+
expect(subject.words.map(&:start_frame)).to eq([0, 25, 46, 64, 117, 153, 212])
|
48
|
+
expect(subject.words.map(&:end_frame)).to eq([24, 45, 63, 116, 152, 211, 260])
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pocketsphinx-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Howard Wilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.6.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.6.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: coveralls
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.5.1
|
161
161
|
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: Ruby speech recognition with Pocketsphinx
|