-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental Pocketsphinx::CMNDecoder (relates to #10)
- Loading branch information
Showing
6 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Pocketsphinx | ||
module API | ||
module Sphinxbase | ||
module Cmn | ||
extend FFI::Library | ||
|
||
enum :cmn_type, [:none, 0, :current, :prior] | ||
enum :agc_type, [:none, 0, :max, :emax, :noise] | ||
|
||
class CmnData < FFI::Struct | ||
layout :cmn_mean, :pointer, | ||
:cmn_var, :pointer, | ||
:sum, :pointer, | ||
:nframe, :int32, | ||
:veclen, :int32 | ||
end | ||
|
||
class Feature < FFI::Struct | ||
layout :refcount, :int, | ||
:name, :string, | ||
:cepsize, :int32, | ||
:n_stream, :int32, | ||
:stream_len, :pointer, | ||
:window_size, :int32, | ||
:n_sv, :int32, | ||
:sv_len, :pointer, | ||
:subvecs, :pointer, | ||
:mfcc_t, :pointer, | ||
:sv_dim, :int32, | ||
:cmn, :cmn_type, | ||
:varnorm, :int32, | ||
:agc, :agc_type, | ||
:compute_feat, :pointer, | ||
:cmn_struct, CmnData.ptr, | ||
:agc_struct, :pointer | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Pocketsphinx | ||
class CMNDecoder < Decoder | ||
CMN_TOLERANCE_DEFAULT = 20 | ||
|
||
attr_writer :cmn_tolerance | ||
|
||
def cmn_tolerance | ||
@cmn_tolerance || CMN_TOLERANCE_DEFAULT | ||
end | ||
|
||
def decode_raw(audio_file, max_samples = 2048) | ||
repeat_if_cmn_sum_exceeds { super } | ||
end | ||
|
||
private | ||
|
||
def repeat_if_cmn_sum_exceeds(tolerance = cmn_tolerance) | ||
before = cmn_values | ||
result = yield | ||
after = cmn_values | ||
|
||
cmn_sum(before, after) > tolerance ? yield : result | ||
end | ||
|
||
def cmn_sum(before, after) | ||
before.zip(after).inject(0) { |sum, a| sum + (a.last - a.first).abs } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters