This repository was archived by the owner on Aug 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (34 loc) · 1.22 KB
/
index.js
File metadata and controls
46 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
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
var binding = require("./build/Debug/binding");
var util = require("util");
var stream = require("stream");
var spawn = require('child_process').spawn;
var PocketSphinx = function(options) {
var callback = function(result) {
if (result.error) {
this.emit("error", result.error);
return;
}
this.emit('utterance', result.hyp, result.utterance, result.score);
}
var self = this;
var pkgconfig = spawn('pkg-config', ['--variable=modeldir', 'pocketsphinx']);
pkgconfig.stdout.on('data', function(path) {
options = options || {};
path = ('' + path).trim();
console.log(path + '/hmm/en_US/hub4wsj_sc_8k');
options.hmm = options.hmm || (path + '/hmm/en_US/hub4wsj_sc_8k');
options.lm = options.lm || (path + '/lm/en_US/hub4.5000.DMP');
options.dict = options.dict || (path + '/lm/en_US/cmu07a.dic');
options.samprate = '' + (options.samprate || 44100);
options.nfft = '' + (options.nfft || 2048);
// TODO: provide additional defaults
self._binding = new binding.pocketSphinxBinding(options, callback);
});
}
util.inherits(PocketSphinx, stream.Writable);
PocketSphinx.prototype.write = function(chunk) {
if (this._binding) {
this._binding.writeData(chunk);
}
};
module.exports = PocketSphinx;