pihsi 0.1.0 → 0.2.0

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: d949dd5f7e6d5f382c6c74a44f3678fbfe0a8fa8
4
- data.tar.gz: ed8b316d1c8ffb11f954a57a0389d787079acd70
3
+ metadata.gz: 39a878f44496fcecc39a526f4452d31df5dc2fdf
4
+ data.tar.gz: 64e75af38da0c529812822f718efaed69c6e4db5
5
5
  SHA512:
6
- metadata.gz: 5b09454ee9df43e8aac32714dcaf0a9c11fa7a56f5ace89730cd817fdba4115a4cbca1199ce4ef04e30f3f82ae6727bb7ebf037be84a0d02a6fb3c8ec0a2c7b9
7
- data.tar.gz: 31ccc59f39331163b8fbeb290e7ee2db0e2ded8e40f9b77a5046610cbbdb5f79d34d40b5cf3fdc660aca5842699896d6e43a2b7ba48db23cb9db293b6174a694
6
+ metadata.gz: 6b7c9e706f8130b30cae6cb064fd7ab0ad019371a781867c05499412f09a5718b8a41512839d807f9e86c69a78f9382d2b9c901d4dbca6ef431cfaf93658d8ca
7
+ data.tar.gz: 5d53020195f0b5e8791ae2c60aef44e4be810f8141c0cbb0ec5a4220025b8b16568d41b237f45025e4ebc83ca33a663ed42f1d56b99a83ed384b31c38bdf1e52
data/README.md CHANGED
@@ -32,7 +32,7 @@ Initialize Pihsi::SpeechRecognizer with proper [hmm, lm and dict](http://cmusphi
32
32
  recognizer = Pihsi::SpeechRecognizer.new hmm: 'xxx', lm: 'yyy', dict: 'zzz'
33
33
  ```
34
34
 
35
- Recognize a string read from your audio file:
35
+ Recognize a string read from your audio file or an object respond to #read (IO object):
36
36
 
37
37
  ```ruby
38
38
  recognizer.recognize data
@@ -7,20 +7,10 @@ typedef struct ps {
7
7
 
8
8
  static VALUE rb_eUtteranceError;
9
9
 
10
- /* Converts raw audio data into text.
11
- *
12
- * @param data [String] the raw audio data
13
- * @return [String, nil] the transcribed text or nil
14
- */
15
- VALUE recognize(VALUE self, VALUE data) {
10
+ static VALUE decode(ps_decoder_t *ps, VALUE data) {
16
11
  char const *hyp, *uttid;
17
12
  int rv;
18
13
  int32 score;
19
- ps_decoder_t *ps;
20
- PocketSphinx *pocketSphinx;
21
-
22
- Data_Get_Struct(self, PocketSphinx, pocketSphinx);
23
- ps = pocketSphinx -> decoder;
24
14
 
25
15
  rv = ps_start_utt(ps, "goforward");
26
16
 
@@ -42,6 +32,26 @@ VALUE recognize(VALUE self, VALUE data) {
42
32
  }
43
33
  }
44
34
 
35
+ /* Converts raw audio data into text.
36
+ *
37
+ * @param data [String, #read] the raw audio data or its io object
38
+ * @return [String, nil] the transcribed text or nil
39
+ */
40
+ VALUE recognize(VALUE self, VALUE data) {
41
+ VALUE string;
42
+ PocketSphinx *pocketSphinx;
43
+
44
+ Data_Get_Struct(self, PocketSphinx, pocketSphinx);
45
+ if (rb_funcall(data, rb_intern("respond_to?"), 1, rb_str_new2("read")) == Qtrue) {
46
+ string = rb_funcall(data, rb_intern("read"), 0);
47
+ } else if (rb_obj_is_kind_of(data, rb_cString)) {
48
+ string = data;
49
+ } else {
50
+ rb_raise(rb_eArgError, "data can only be a string or an IO object");
51
+ }
52
+ return decode(pocketSphinx -> decoder, string);
53
+ }
54
+
45
55
  static void deallocate(void *ps) {
46
56
  PocketSphinx *pocketSphinx = ps;
47
57
  ps_free(pocketSphinx -> decoder);
data/lib/pihsi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pihsi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -9,5 +9,17 @@ RSpec.describe Pihsi::SpeechRecognizer do
9
9
 
10
10
  it { should eq "go forward ten meters" }
11
11
  end
12
+
13
+ context 'when data is an IO object of goforward.raw' do
14
+ let(:data) { File.open('spec/fixtures/goforward.raw') }
15
+
16
+ it { should eq "go forward ten meters" }
17
+ end
18
+
19
+ context 'when data is invalid' do
20
+ let(:data) { 1 }
21
+
22
+ specify { expect { subject }.to raise_error(ArgumentError) }
23
+ end
12
24
  end
13
25
  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.1.0
4
+ version: 0.2.0
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-07 00:00:00.000000000 Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler