pihsi 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 476ee4a5c97cca36a91e30b9ab3b4e5b821ad63f
4
+ data.tar.gz: 40195a7c1873796cb245e6511b76842cfa4c279e
5
+ SHA512:
6
+ metadata.gz: 4a9e8409bf6bc3d6a68a6a78029413f3f3f3836734b3c94ff05db046c3b17f06861a37bf460c73a6c7e0ac1c2b31244843b038ef788fd108455c72263a8a5393
7
+ data.tar.gz: f66b6ac970d69479f38d4b945a56e7af5d4d40b232974bd7660e7098723febacbb1c5b189d522269120691a5211bf8fdd9e3eaaef33aaa155822f26117208b8c
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pihsi.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Zhi-Qiang Lei
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Pihsi
2
+
3
+ Pihsi is a Ruby Speech Recognition toolkit based on [PocketSphinx](http://cmusphinx.sourceforge.net).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pihsi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pihsi
20
+
21
+ ## Usage
22
+
23
+ Initialize Pihsi::SpeechRecognizer with proper [hmm, lm and dict](http://cmusphinx.sourceforge.net/wiki/tutorialpocketsphinx#initialization):
24
+
25
+ ```ruby
26
+ recognizer = Pihsi::SpeechRecognizer.new hmm, lm, dict
27
+ ```
28
+
29
+ Recognize a string read from your audio file:
30
+
31
+ ```ruby
32
+ recognizer.recognize string_buffer
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/pihsi/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/extensiontask'
3
+ require 'rspec/core/rake_task'
4
+
5
+ Rake::ExtensionTask.new('pocket_sphinx')
6
+
7
+ desc "Run the specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ t.rspec_opts = "-c"
10
+ t.fail_on_error = false
11
+ t.verbose = false
12
+ end
13
+
14
+ task :spec => :compile
@@ -0,0 +1,10 @@
1
+ require 'mkmf'
2
+
3
+ unless find_header 'pocketsphinx_export.h', '/usr/local/include/pocketsphinx'
4
+ abort 'cannot find pocketsphinx, please install it.'
5
+ end
6
+ find_header 'cmd_ln.h', '/usr/local/include/sphinxbase'
7
+ find_library 'pocketsphinx', 'ps_init'
8
+ find_library 'sphinxbase', 'cmd_ln_init'
9
+
10
+ create_makefile 'pocket_sphinx/pocket_sphinx'
@@ -0,0 +1,37 @@
1
+ #include <ruby.h>
2
+ #include <pocketsphinx.h>
3
+
4
+ VALUE recognize(VALUE self, VALUE string_buffer) {
5
+ char const *hyp, *uttid;
6
+ int rv;
7
+ int32 score;
8
+ ps_decoder_t *ps;
9
+ cmd_ln_t *config;
10
+
11
+ char *hmm = RSTRING_PTR(rb_funcall(self, rb_intern("hmm"), 0));
12
+ char *lm = RSTRING_PTR(rb_funcall(self, rb_intern("lm"), 0));
13
+ char *dict = RSTRING_PTR(rb_funcall(self, rb_intern("dict"), 0));
14
+ config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", hmm, "-lm", lm, "-dict", dict, "-logfn", "/dev/null", NULL);
15
+ if (config == NULL)
16
+ rb_raise(rb_eStandardError, "configuration might be wrong");
17
+
18
+ ps = ps_init(config);
19
+ rv = ps_start_utt(ps, "goforward");
20
+ if (rv < 0)
21
+ rb_raise(rb_eStandardError, "cannot start utterance");
22
+
23
+ rv = ps_process_raw(ps, (const int16 *) RSTRING_PTR(string_buffer), RSTRING_LEN(string_buffer) / 2, FALSE, FALSE);
24
+ rv = ps_end_utt(ps);
25
+ if (rv < 0)
26
+ rb_raise(rb_eStandardError, "cannot end utterance");
27
+ hyp = ps_get_hyp(ps, &score, &uttid);
28
+ if (hyp == NULL)
29
+ rb_raise(rb_eStandardError, "no hypothesis string");
30
+ return rb_str_new2(hyp);
31
+ }
32
+
33
+ void Init_pocket_sphinx() {
34
+ VALUE rb_mPihsi = rb_define_module("Pihsi");
35
+ VALUE rb_mPocketSphinx = rb_define_module_under(rb_mPihsi, "PocketSphinx");
36
+ rb_define_method(rb_mPocketSphinx, "recognize", recognize, 1);
37
+ }
@@ -0,0 +1,12 @@
1
+ require "pocket_sphinx"
2
+
3
+ module Pihsi
4
+ class SpeechRecognizer
5
+ include PocketSphinx
6
+ attr_reader :hmm, :lm, :dict
7
+
8
+ def initialize(hmm, lm, dict)
9
+ @hmm, @lm, @dict = hmm, lm, dict
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Pihsi
2
+ VERSION = "0.0.2"
3
+ end
data/lib/pihsi.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require "pihsi/version"
4
+ require "pihsi/speech_recognizer"
5
+
6
+ module Pihsi
7
+ # Your code goes here...
8
+ end
data/pihsi.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pihsi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pihsi"
8
+ spec.version = Pihsi::VERSION
9
+ spec.authors = ["Zhi-Qiang Lei"]
10
+ spec.email = ["zhiqiang.lei@gmail.com"]
11
+ spec.summary = %q{Toolkit for Speech Recognition.}
12
+ spec.description = %q{Pihsi is a open source toolkit for Speech Recognition based on PocketSphinx.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.extensions = %w[ext/pocket_sphinx/extconf.rb]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3"
25
+ spec.add_development_dependency "factory_girl", "~> 4.0"
26
+ spec.add_development_dependency "rake-compiler"
27
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :speech_recognizer, class: Pihsi::SpeechRecognizer do
3
+ hmm 'spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k'
4
+ lm 'spec/fixtures/model/lm/en/turtle.DMP'
5
+ dict 'spec/fixtures/model/lm/en/turtle.dic'
6
+
7
+ initialize_with { new(hmm, lm, dict) }
8
+ end
9
+ end
Binary file
@@ -0,0 +1,13 @@
1
+ -nfilt 20
2
+ -lowerf 1
3
+ -upperf 4000
4
+ -wlen 0.025
5
+ -transform dct
6
+ -round_filters no
7
+ -remove_dc yes
8
+ -svspec 0-12/13-25/26-38
9
+ -feat 1s_c_d_dd
10
+ -agc none
11
+ -cmn current
12
+ -cmninit 56,-3,1
13
+ -varnorm no
@@ -0,0 +1,11 @@
1
+ ++NOISE++ +NOISE+
2
+ ++BREATH++ +BREATH+
3
+ ++SMACK++ +SMACK+
4
+ ++COUGH++ +COUGH+
5
+ ++LAUGH++ +LAUGH+
6
+ ++TONE++ +TONE+
7
+ ++UH++ +UH+
8
+ ++UM++ +UM+
9
+ </s> SIL
10
+ <s> SIL
11
+ <sil> SIL
@@ -0,0 +1,110 @@
1
+ a AH
2
+ a(2) EY
3
+ and AE N T
4
+ and(2) AH N T
5
+ are AA R
6
+ are(2) ER
7
+ around ER AW N
8
+ around(2) ER AW N T
9
+ backward B AE K W ER T
10
+ backwards B AE K W ER D Z
11
+ bye B AY
12
+ centimeter S EH N T AH M IY T ER
13
+ centimeters S EH N T AH M IY T ER Z
14
+ chase CH EY S
15
+ color K AH L ER
16
+ color(2) K AO L ER
17
+ degrees D IH G R IY Z
18
+ display D IH S P L EY
19
+ do D UW
20
+ doing D UW IH NG
21
+ eight EY T
22
+ eighteen EY T IY N
23
+ eighty EY T IY
24
+ eleven AH L EH V AH N
25
+ eleven(2) IY L EH V AH N
26
+ exit EH G Z AH T
27
+ exit(2) EH K S AH T
28
+ explore IH K S P L AO R
29
+ fifteen F IH F T IY N
30
+ fifty F IH F T IY
31
+ find F AY N T
32
+ finish F IH N IH SH
33
+ five F AY V
34
+ forty F AO R T IY
35
+ forward F AO R W ER T
36
+ four F AO R
37
+ fourteen F AO R T IY N
38
+ go G OW
39
+ grey G R EY
40
+ guard G AA R T
41
+ half HH AE F
42
+ hall HH AO L
43
+ hallway HH AO L W EY
44
+ halt HH AO L T
45
+ hello HH AH L OW
46
+ hello(2) HH EH L OW
47
+ home HH OW M
48
+ hundred HH AH N ER T
49
+ hundred(2) HH AH N D ER T
50
+ hundred(3) HH AH N D R AH T
51
+ kevin K EH V IH N
52
+ lab L AE T
53
+ left L EH F T
54
+ listening L IH S AH N IH NG
55
+ listening(2) L IH S N IH NG
56
+ lost L AO S T
57
+ meter M IY T ER
58
+ meters M IY T ER Z
59
+ minus M AY N AH S
60
+ nine N AY N
61
+ nineteen N AY N T IY N
62
+ ninety N AY N T IY
63
+ office AO F AH S
64
+ one HH W AH N
65
+ one(2) W AH N
66
+ person P ER S AH N
67
+ quarter K AO R T ER
68
+ quarter(2) K W AO R T ER
69
+ quarters K W AO R T ER Z
70
+ quit K W IH T
71
+ ready R EH D IY
72
+ reid R IY T
73
+ right R AY T
74
+ roboman R AA B AH M AH N
75
+ room R UW M
76
+ rotate R OW T EY T
77
+ say S EY
78
+ sebastian S AH B AE S CH AH N
79
+ seven S EH V AH N
80
+ seventeen S EH V AH N T IY N
81
+ seventy S EH V AH N IY
82
+ seventy(2) S EH V AH N T IY
83
+ six S IH K S
84
+ sixteen S IH K S T IY N
85
+ sixteen(2) S IH K S T IY N
86
+ sixty S IH K S T IY
87
+ stop S T AA T
88
+ ten T EH N
89
+ the DH AH
90
+ the(2) DH AH
91
+ the(3) DH IY
92
+ then DH EH N
93
+ thirteen TH ER T IY N
94
+ thirty TH ER T IY
95
+ three TH R IY
96
+ to T AH
97
+ to(2) T IH
98
+ to(3) T UW
99
+ tom T AA M
100
+ turn T ER N
101
+ twelve T W EH L V
102
+ twenty T W EH N IY
103
+ twenty(2) T W EH N T IY
104
+ two T UW
105
+ understand AH N D ER S T AE N T
106
+ wander W AA N D ER
107
+ what HH W AH T
108
+ what(2) W AH T
109
+ window W IH N D OW
110
+ you Y UW
@@ -0,0 +1,7 @@
1
+ require 'pihsi'
2
+ Bundler.require(:development)
3
+
4
+ Dir[File.absolute_path("spec/support/**/*.rb")].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ end
@@ -0,0 +1,13 @@
1
+ RSpec.describe Pihsi::SpeechRecognizer do
2
+ let(:instance) { build :speech_recognizer }
3
+
4
+ describe '#recognize(string_buffer)' do
5
+ subject { instance.recognize(string_buffer) }
6
+
7
+ context 'when string_buffer is the content of goforward.raw' do
8
+ let(:string_buffer) { File.read 'spec/fixtures/goforward.raw' }
9
+
10
+ it { should eq "go forward ten meters" }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ Dir[File.absolute_path("spec/factories/**/*.rb")].each { |f| require f }
2
+
3
+ RSpec.configure do |config|
4
+ config.include FactoryGirl::Syntax::Methods
5
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pihsi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Zhi-Qiang Lei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake-compiler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Pihsi is a open source toolkit for Speech Recognition based on PocketSphinx.
84
+ email:
85
+ - zhiqiang.lei@gmail.com
86
+ executables: []
87
+ extensions:
88
+ - ext/pocket_sphinx/extconf.rb
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - ext/pocket_sphinx/extconf.rb
98
+ - ext/pocket_sphinx/pocket_sphinx.c
99
+ - lib/pihsi.rb
100
+ - lib/pihsi/speech_recognizer.rb
101
+ - lib/pihsi/version.rb
102
+ - pihsi.gemspec
103
+ - spec/factories/speech_recognizer.rb
104
+ - spec/fixtures/goforward.raw
105
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/feat.params
106
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/mdef
107
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/means
108
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/noisedict
109
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/sendump
110
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/transition_matrices
111
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/variances
112
+ - spec/fixtures/model/lm/en/turtle.DMP
113
+ - spec/fixtures/model/lm/en/turtle.dic
114
+ - spec/spec_helper.rb
115
+ - spec/speech_recognizer_spec.rb
116
+ - spec/support/factory_girl.rb
117
+ homepage: ''
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Toolkit for Speech Recognition.
141
+ test_files:
142
+ - spec/factories/speech_recognizer.rb
143
+ - spec/fixtures/goforward.raw
144
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/feat.params
145
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/mdef
146
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/means
147
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/noisedict
148
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/sendump
149
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/transition_matrices
150
+ - spec/fixtures/model/hmm/en_US/hub4wsj_sc_8k/variances
151
+ - spec/fixtures/model/lm/en/turtle.DMP
152
+ - spec/fixtures/model/lm/en/turtle.dic
153
+ - spec/spec_helper.rb
154
+ - spec/speech_recognizer_spec.rb
155
+ - spec/support/factory_girl.rb