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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59186bbdfc0d6a8209230283e39111f2dea70f67
4
- data.tar.gz: 798220a80b22f1a512aa9685db6897f6145719b2
3
+ metadata.gz: 22b3b365012c105fea0820185dce021c02c28b3e
4
+ data.tar.gz: 820d34da1e6bdee5cfb395ea8b6dd836a727e049
5
5
  SHA512:
6
- metadata.gz: 94ffd1f8da9d88e6d230ec824e2c0e945061d4bbca532960806c6f8913e992ed37c40df0e26adcc82422b25455bc20c13312b558cd11d418efa8b441412a8a2b
7
- data.tar.gz: 834d2901bdf0addffde57f43757197b19ab1f327ee315b76bc9d814407536b3d17f85fe03535b27543b87772f7d300f65018c1023755093d3dab0dc938c74c62
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 hmm, lm, dict
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 string_buffer
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
- ps_decoder_t *decoder;
5
+ ps_decoder_t *decoder;
6
6
  } PocketSphinx;
7
7
 
8
8
  VALUE decode(VALUE self, VALUE data) {
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
- }
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
- PocketSphinx *pocketSphinx = ps;
57
- ps_free(pocketSphinx -> decoder);
58
- free(pocketSphinx);
56
+ PocketSphinx *pocketSphinx = ps;
57
+ ps_free(pocketSphinx -> decoder);
58
+ free(pocketSphinx);
59
59
  }
60
60
 
61
61
  static VALUE allocate(VALUE self) {
62
- PocketSphinx *ps;
63
- return Data_Make_Struct(self, PocketSphinx, 0, deallocate, ps);
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
- 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;
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
- VALUE rb_mPihsi = rb_define_module("Pihsi");
99
- VALUE rb_mPocketSphinx = rb_define_module_under(rb_mPihsi, "PocketSphinx");
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);
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
@@ -1,3 +1,3 @@
1
1
  module Pihsi
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/pihsi.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec", "~> 3"
25
25
  spec.add_development_dependency "factory_girl", "~> 4.0"
26
26
  spec.add_development_dependency "rake-compiler"
27
+ spec.add_development_dependency "coveralls"
27
28
  end
@@ -0,0 +1,2 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
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.6
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