pihsi 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/ext/pocket_sphinx/pocket_sphinx.c +83 -84
- data/lib/pihsi/version.rb +1 -1
- data/pihsi.gemspec +1 -0
- data/spec/support/coveralls.rb +2 -0
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22b3b365012c105fea0820185dce021c02c28b3e
|
4
|
+
data.tar.gz: 820d34da1e6bdee5cfb395ea8b6dd836a727e049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ae1e4eddf7e564e3d4e28509c1e7d7b7f1d7280db543d59fa15095481159463866095c3d85e6b85549c39b95eb38268ecc986933922112fdec92d895bb115f
|
7
|
+
data.tar.gz: 7362822983580aa600b4f23408c3c7e68fd7a3bc40c11997d8f32f5d588d7a910a675bf463af7e38e68bf0319da02a68d7ed1bf3d5cad30bbcde8f477f0ea4f8
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Pihsi
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/pihsi.svg)](http://badge.fury.io/rb/pihsi)
|
4
|
+
[![Dependency Status](https://gemnasium.com/siegfried/pihsi.svg)](https://gemnasium.com/siegfried/pihsi)
|
3
5
|
[![Build Status](https://travis-ci.org/siegfried/pihsi.svg?branch=master)](https://travis-ci.org/siegfried/pihsi)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/siegfried/pihsi/badge.png)](https://coveralls.io/r/siegfried/pihsi)
|
7
|
+
[![Inline docs](http://inch-ci.org/github/siegfried/pihsi.svg?branch=master)](http://inch-ci.org/github/siegfried/pihsi)
|
4
8
|
|
5
9
|
Pihsi is a Ruby Speech Recognition toolkit based on [PocketSphinx](http://cmusphinx.sourceforge.net).
|
6
10
|
|
@@ -25,13 +29,13 @@ Or install it yourself as:
|
|
25
29
|
Initialize Pihsi::SpeechRecognizer with proper [hmm, lm and dict](http://cmusphinx.sourceforge.net/wiki/tutorialpocketsphinx#initialization):
|
26
30
|
|
27
31
|
```ruby
|
28
|
-
recognizer = Pihsi::SpeechRecognizer.new
|
32
|
+
recognizer = Pihsi::SpeechRecognizer.new
|
29
33
|
```
|
30
34
|
|
31
35
|
Recognize a string read from your audio file:
|
32
36
|
|
33
37
|
```ruby
|
34
|
-
recognizer.recognize
|
38
|
+
recognizer.recognize data
|
35
39
|
```
|
36
40
|
|
37
41
|
## Contributing
|
@@ -2,103 +2,102 @@
|
|
2
2
|
#include <pocketsphinx.h>
|
3
3
|
|
4
4
|
typedef struct ps {
|
5
|
-
|
5
|
+
ps_decoder_t *decoder;
|
6
6
|
} PocketSphinx;
|
7
7
|
|
8
8
|
VALUE decode(VALUE self, VALUE data) {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
9
|
+
char const *hyp, *uttid;
|
10
|
+
int rv;
|
11
|
+
int32 score;
|
12
|
+
ps_decoder_t *ps;
|
13
|
+
PocketSphinx *pocketSphinx;
|
14
|
+
VALUE result = rb_hash_new();
|
15
|
+
|
16
|
+
Data_Get_Struct(self, PocketSphinx, pocketSphinx);
|
17
|
+
ps = pocketSphinx -> decoder;
|
18
|
+
|
19
|
+
int data_length = RARRAY_LEN(data);
|
20
|
+
int16 *c_data = malloc(sizeof(int16) * data_length);
|
21
|
+
|
22
|
+
int i;
|
23
|
+
for(i = 0; i < data_length; i++) {
|
24
|
+
c_data[i] = NUM2INT(rb_ary_entry(data, i)); // Rubinius does not support NUM2SHORT();
|
25
|
+
}
|
26
|
+
|
27
|
+
rv = ps_start_utt(ps, "goforward");
|
28
|
+
|
29
|
+
if (rv < 0) {
|
30
|
+
free(c_data);
|
31
|
+
rb_raise(rb_eStandardError, "cannot start utterance");
|
32
|
+
}
|
33
|
+
|
34
|
+
rv = ps_process_raw(ps, c_data, data_length, FALSE, FALSE);
|
35
|
+
rv = ps_end_utt(ps);
|
36
|
+
|
37
|
+
if (rv < 0) {
|
38
|
+
free(c_data);
|
39
|
+
rb_raise(rb_eStandardError, "cannot end utterance");
|
40
|
+
}
|
41
|
+
|
42
|
+
hyp = ps_get_hyp(ps, &score, &uttid);
|
43
|
+
|
44
|
+
free(c_data);
|
45
|
+
|
46
|
+
if (hyp == NULL) {
|
47
|
+
return Qnil;
|
48
|
+
} else {
|
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;
|
52
|
+
}
|
53
53
|
}
|
54
54
|
|
55
55
|
static void deallocate(void *ps) {
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
PocketSphinx *pocketSphinx = ps;
|
57
|
+
ps_free(pocketSphinx -> decoder);
|
58
|
+
free(pocketSphinx);
|
59
59
|
}
|
60
60
|
|
61
61
|
static VALUE allocate(VALUE self) {
|
62
|
-
|
63
|
-
|
62
|
+
PocketSphinx *ps;
|
63
|
+
return Data_Make_Struct(self, PocketSphinx, 0, deallocate, ps);
|
64
64
|
}
|
65
65
|
|
66
66
|
VALUE initialize(VALUE self, VALUE options) {
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
return self;
|
67
|
+
int i;
|
68
|
+
PocketSphinx *ps;
|
69
|
+
VALUE option, key, value;
|
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
|
+
|
79
|
+
if (rb_obj_is_kind_of(value, rb_cString)) {
|
80
|
+
cmd_ln_set_str_r(config, c_key, RSTRING_PTR(value));
|
81
|
+
} else if (rb_obj_is_kind_of(value, rb_cFixnum)) {
|
82
|
+
cmd_ln_set_int_r(config, c_key, NUM2LONG(value));
|
83
|
+
} else if (rb_obj_is_kind_of(value, rb_cFloat)) {
|
84
|
+
cmd_ln_set_float_r(config, c_key, NUM2DBL(value));
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
if (config == NULL)
|
89
|
+
rb_raise(rb_eStandardError, "bad configuration");
|
90
|
+
|
91
|
+
Data_Get_Struct(self, PocketSphinx, ps);
|
92
|
+
ps -> decoder = ps_init(config);
|
93
|
+
return self;
|
95
94
|
}
|
96
95
|
|
97
96
|
void Init_pocket_sphinx() {
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
VALUE rb_mPihsi = rb_define_module("Pihsi");
|
98
|
+
VALUE rb_mPocketSphinx = rb_define_module_under(rb_mPihsi, "PocketSphinx");
|
99
|
+
VALUE rb_cDecoder = rb_define_class_under(rb_mPocketSphinx, "Decoder", rb_cObject);
|
100
|
+
rb_define_alloc_func(rb_cDecoder, allocate);
|
101
|
+
rb_define_method(rb_cDecoder, "initialize", initialize, 1);
|
102
|
+
rb_define_method(rb_cDecoder, "decode", decode, 1);
|
104
103
|
}
|
data/lib/pihsi/version.rb
CHANGED
data/pihsi.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zhi-Qiang Lei
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Pihsi is a open source toolkit for Speech Recognition based on PocketSphinx.
|
84
98
|
email:
|
85
99
|
- zhiqiang.lei@gmail.com
|
@@ -114,6 +128,7 @@ files:
|
|
114
128
|
- spec/fixtures/model/lm/en/turtle.dic
|
115
129
|
- spec/spec_helper.rb
|
116
130
|
- spec/speech_recognizer_spec.rb
|
131
|
+
- spec/support/coveralls.rb
|
117
132
|
- spec/support/factory_girl.rb
|
118
133
|
homepage: ''
|
119
134
|
licenses:
|
@@ -153,4 +168,5 @@ test_files:
|
|
153
168
|
- spec/fixtures/model/lm/en/turtle.dic
|
154
169
|
- spec/spec_helper.rb
|
155
170
|
- spec/speech_recognizer_spec.rb
|
171
|
+
- spec/support/coveralls.rb
|
156
172
|
- spec/support/factory_girl.rb
|