pihsi 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/ext/pocket_sphinx/pocket_sphinx.c +60 -17
- data/lib/pihsi/speech_recognizer.rb +10 -5
- data/lib/pihsi/version.rb +1 -1
- data/spec/factories/speech_recognizer.rb +4 -1
- 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: 59186bbdfc0d6a8209230283e39111f2dea70f67
|
4
|
+
data.tar.gz: 798220a80b22f1a512aa9685db6897f6145719b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94ffd1f8da9d88e6d230ec824e2c0e945061d4bbca532960806c6f8913e992ed37c40df0e26adcc82422b25455bc20c13312b558cd11d418efa8b441412a8a2b
|
7
|
+
data.tar.gz: 834d2901bdf0addffde57f43757197b19ab1f327ee315b76bc9d814407536b3d17f85fe03535b27543b87772f7d300f65018c1023755093d3dab0dc938c74c62
|
data/.travis.yml
CHANGED
@@ -5,8 +5,6 @@ rvm:
|
|
5
5
|
- 1.9.3
|
6
6
|
- rbx-2.2.7
|
7
7
|
before_install:
|
8
|
-
- sudo apt-get update
|
9
|
-
- sudo apt-get install build-essential bison
|
10
8
|
- wget http://downloads.sourceforge.net/project/cmusphinx/sphinxbase/0.8/sphinxbase-0.8.tar.gz
|
11
9
|
- tar -zxf sphinxbase-0.8.tar.gz
|
12
10
|
- cd sphinxbase-0.8
|
@@ -21,3 +19,4 @@ before_install:
|
|
21
19
|
- make
|
22
20
|
- sudo make install
|
23
21
|
- cd ..
|
22
|
+
- sudo ldconfig
|
@@ -1,33 +1,29 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <pocketsphinx.h>
|
3
3
|
|
4
|
-
|
4
|
+
typedef struct ps {
|
5
|
+
ps_decoder_t *decoder;
|
6
|
+
} PocketSphinx;
|
7
|
+
|
8
|
+
VALUE decode(VALUE self, VALUE data) {
|
5
9
|
char const *hyp, *uttid;
|
6
10
|
int rv;
|
7
11
|
int32 score;
|
8
12
|
ps_decoder_t *ps;
|
9
|
-
|
13
|
+
PocketSphinx *pocketSphinx;
|
14
|
+
VALUE result = rb_hash_new();
|
15
|
+
|
16
|
+
Data_Get_Struct(self, PocketSphinx, pocketSphinx);
|
17
|
+
ps = pocketSphinx -> decoder;
|
10
18
|
|
11
19
|
int data_length = RARRAY_LEN(data);
|
12
20
|
int16 *c_data = malloc(sizeof(int16) * data_length);
|
13
21
|
|
14
|
-
char *hmm = RSTRING_PTR(rb_funcall(self, rb_intern("hmm"), 0));
|
15
|
-
char *lm = RSTRING_PTR(rb_funcall(self, rb_intern("lm"), 0));
|
16
|
-
char *dict = RSTRING_PTR(rb_funcall(self, rb_intern("dict"), 0));
|
17
|
-
|
18
22
|
int i;
|
19
23
|
for(i = 0; i < data_length; i++) {
|
20
|
-
c_data[i] =
|
21
|
-
}
|
22
|
-
|
23
|
-
config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", hmm, "-lm", lm, "-dict", dict, "-logfn", "/dev/null", NULL);
|
24
|
-
|
25
|
-
if (config == NULL) {
|
26
|
-
free(c_data);
|
27
|
-
rb_raise(rb_eStandardError, "configuration might be wrong");
|
24
|
+
c_data[i] = NUM2INT(rb_ary_entry(data, i)); // Rubinius does not support NUM2SHORT();
|
28
25
|
}
|
29
26
|
|
30
|
-
ps = ps_init(config);
|
31
27
|
rv = ps_start_utt(ps, "goforward");
|
32
28
|
|
33
29
|
if (rv < 0) {
|
@@ -50,12 +46,59 @@ VALUE recognize(VALUE self, VALUE data) {
|
|
50
46
|
if (hyp == NULL) {
|
51
47
|
return Qnil;
|
52
48
|
} else {
|
53
|
-
|
49
|
+
rb_hash_aset(result, rb_str_new2("score"), INT2NUM(hyp));
|
50
|
+
rb_hash_aset(result, rb_str_new2("hypothesis"), rb_str_new2(hyp));
|
51
|
+
return result;
|
54
52
|
}
|
55
53
|
}
|
56
54
|
|
55
|
+
static void deallocate(void *ps) {
|
56
|
+
PocketSphinx *pocketSphinx = ps;
|
57
|
+
ps_free(pocketSphinx -> decoder);
|
58
|
+
free(pocketSphinx);
|
59
|
+
}
|
60
|
+
|
61
|
+
static VALUE allocate(VALUE self) {
|
62
|
+
PocketSphinx *ps;
|
63
|
+
return Data_Make_Struct(self, PocketSphinx, 0, deallocate, ps);
|
64
|
+
}
|
65
|
+
|
66
|
+
VALUE initialize(VALUE self, VALUE options) {
|
67
|
+
int i;
|
68
|
+
PocketSphinx *ps;
|
69
|
+
VALUE option, key, value, klass;
|
70
|
+
char *c_key;
|
71
|
+
cmd_ln_t *config = cmd_ln_init(NULL, ps_args(), TRUE, "-logfn", "/dev/null", NULL);
|
72
|
+
|
73
|
+
for (i = 0; i < RARRAY_LEN(options); i++) {
|
74
|
+
option = rb_ary_entry(options, i);
|
75
|
+
key = rb_ary_entry(option, 0);
|
76
|
+
c_key = RSTRING_PTR(key);
|
77
|
+
value = rb_ary_entry(option, 1);
|
78
|
+
klass = rb_funcall(value, rb_intern("class"), 0);
|
79
|
+
|
80
|
+
if (klass == rb_cString) {
|
81
|
+
cmd_ln_set_str_r(config, c_key, RSTRING_PTR(value));
|
82
|
+
} else if (klass == rb_cFixnum) {
|
83
|
+
cmd_ln_set_int_r(config, c_key, NUM2LONG(value));
|
84
|
+
} else if (klass == rb_cFloat) {
|
85
|
+
cmd_ln_set_float_r(config, c_key, NUM2DBL(value));
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
if (config == NULL)
|
90
|
+
rb_raise(rb_eStandardError, "bad configuration");
|
91
|
+
|
92
|
+
Data_Get_Struct(self, PocketSphinx, ps);
|
93
|
+
ps -> decoder = ps_init(config);
|
94
|
+
return self;
|
95
|
+
}
|
96
|
+
|
57
97
|
void Init_pocket_sphinx() {
|
58
98
|
VALUE rb_mPihsi = rb_define_module("Pihsi");
|
59
99
|
VALUE rb_mPocketSphinx = rb_define_module_under(rb_mPihsi, "PocketSphinx");
|
60
|
-
|
100
|
+
VALUE rb_cDecoder = rb_define_class_under(rb_mPocketSphinx, "Decoder", rb_cObject);
|
101
|
+
rb_define_alloc_func(rb_cDecoder, allocate);
|
102
|
+
rb_define_method(rb_cDecoder, "initialize", initialize, 1);
|
103
|
+
rb_define_method(rb_cDecoder, "decode", decode, 1);
|
61
104
|
}
|
@@ -2,15 +2,20 @@ require "pocket_sphinx/pocket_sphinx"
|
|
2
2
|
|
3
3
|
module Pihsi
|
4
4
|
class SpeechRecognizer
|
5
|
-
|
6
|
-
attr_reader :hmm, :lm, :dict
|
5
|
+
attr_reader :decoder
|
7
6
|
|
8
|
-
def initialize(
|
9
|
-
|
7
|
+
def initialize(options = {})
|
8
|
+
_options = options.inject({}) do |result, (key, value)|
|
9
|
+
result["-#{key}"] = value unless value.nil?
|
10
|
+
result
|
11
|
+
end.to_a
|
12
|
+
@decoder = PocketSphinx::Decoder.new(_options)
|
10
13
|
end
|
11
14
|
|
12
15
|
def recognize(data)
|
13
|
-
|
16
|
+
if result = decoder.decode(data.unpack('s*'))
|
17
|
+
result["hypothesis"]
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
data/lib/pihsi/version.rb
CHANGED
@@ -3,7 +3,10 @@ FactoryGirl.define do
|
|
3
3
|
hmm 'spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k'
|
4
4
|
lm 'spec/fixtures/model/lm/en/turtle.DMP'
|
5
5
|
dict 'spec/fixtures/model/lm/en/turtle.dic'
|
6
|
+
pip 1.0
|
7
|
+
samprate 16000.0
|
8
|
+
maxhmmpf -1
|
6
9
|
|
7
|
-
initialize_with { new(
|
10
|
+
initialize_with { new(attributes) }
|
8
11
|
end
|
9
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pihsi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zhi-Qiang Lei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|