cmusphinx / node-pocketsphinx

Pocketsphinx bindings for Node.JS
Other
242 stars 47 forks source link

Demo code: config is coming back empty #58

Closed dylanbaxter closed 5 years ago

dylanbaxter commented 5 years ago

Howdy, I've installed and tested the prerequisite software, and put the demo code into my application to try:

var fs = require('fs'),
    ps = require('../../lib/pocketsphinx/PocketSphinx'),
    modeldir = '../../lib/pocketsphinx/model/en-us/'

class SpeechService {

    constructor() {
        var config = new ps.Decoder.defaultConfig();
        console.log("config: " + JSON.stringify(config));
        config.setString("-hmm", modeldir + "en-us");
        config.setString("-dict", modeldir + "cmudict-en-us.dict");
        config.setString("-lm", modeldir + "en-us.lm.bin");
        var decoder = new ps.Decoder(config);

        fs.readFile("../../pocketsphinx/test/data/goforward.raw", function (err, data) {
            if (err) throw err;
            decoder.startUtt();
            decoder.processRaw(data, false, false);
            decoder.endUtt();
            console.log(decoder.hyp())
        });

    }

}

module.exports = SpeechService;

The result:

config: {}
/var/www/server/services/speech-service.js:14
        config.setString("-hmm", modeldir + "en-us");
               ^

TypeError: config.setString is not a function

Any ideas?

nshmyrev commented 5 years ago

ps = require('../../lib/pocketsphinx/PocketSphinx'),

You need to change this to

sb = require('../../lib/pocketsphinx/SphinxBase'),
ps = require('../../lib/pocketsphinx/PocketSphinx')
dylanbaxter commented 5 years ago

Ah, the SphinxBase reference is mandatory. Thank you Nickolay!