pihsi 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/pocket_sphinx/pocket_sphinx.c +21 -11
- data/lib/pihsi/version.rb +1 -1
- data/spec/speech_recognizer_spec.rb +12 -0
- 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: 39a878f44496fcecc39a526f4452d31df5dc2fdf
|
4
|
+
data.tar.gz: 64e75af38da0c529812822f718efaed69c6e4db5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
@@ -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.
|
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-
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|