From bc6741cd4175209fa2fb0a3ea4394ca668d3170b Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Mon, 9 Sep 2019 11:46:18 +0200 Subject: [PATCH] Update JS bindings and client --- native_client/javascript/client.js | 17 +++-------------- native_client/javascript/deepspeech.i | 2 +- native_client/javascript/index.js | 13 +++++++------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/native_client/javascript/client.js b/native_client/javascript/client.js index c831f058..8e274fe7 100644 --- a/native_client/javascript/client.js +++ b/native_client/javascript/client.js @@ -22,16 +22,6 @@ const LM_ALPHA = 0.75; const LM_BETA = 1.85; -// These constants are tied to the shape of the graph used (changing them changes -// the geometry of the first layer), so make sure you use the same constants that -// were used during training - -// Number of MFCC features to use -const N_FEATURES = 26; - -// Size of the context window used for producing timesteps in the input vector -const N_CONTEXT = 9; - var VersionAction = function VersionAction(options) { options = options || {}; options.nargs = 0; @@ -109,15 +99,14 @@ audioStream.on('finish', () => { console.error('Loading model from file %s', args['model']); const model_load_start = process.hrtime(); - var model = new Ds.Model(args['model'], N_FEATURES, N_CONTEXT, args['alphabet'], BEAM_WIDTH); + var model = new Ds.Model(args['model'], args['alphabet'], BEAM_WIDTH); const model_load_end = process.hrtime(model_load_start); console.error('Loaded model in %ds.', totalTime(model_load_end)); if (args['lm'] && args['trie']) { console.error('Loading language model from files %s %s', args['lm'], args['trie']); const lm_load_start = process.hrtime(); - model.enableDecoderWithLM(args['alphabet'], args['lm'], args['trie'], - LM_ALPHA, LM_BETA); + model.enableDecoderWithLM(args['lm'], args['trie'], LM_ALPHA, LM_BETA); const lm_load_end = process.hrtime(lm_load_start); console.error('Loaded language model in %ds.', totalTime(lm_load_end)); } @@ -135,6 +124,6 @@ audioStream.on('finish', () => { } const inference_stop = process.hrtime(inference_start); console.error('Inference took %ds for %ds audio file.', totalTime(inference_stop), audioLength.toPrecision(4)); - Ds.DestroyModel(model); + Ds.FreeModel(model); process.exit(0); }); diff --git a/native_client/javascript/deepspeech.i b/native_client/javascript/deepspeech.i index 02d274c0..80b00a27 100644 --- a/native_client/javascript/deepspeech.i +++ b/native_client/javascript/deepspeech.i @@ -47,7 +47,7 @@ using namespace node; } -// convert double pointer retval in SetupStream to an output +// convert double pointer retval in CreateStream to an output %typemap(in, numinputs=0) StreamingState **retval (StreamingState *ret) { ret = NULL; $1 = &ret; diff --git a/native_client/javascript/index.js b/native_client/javascript/index.js index 4eb693f0..254611bf 100644 --- a/native_client/javascript/index.js +++ b/native_client/javascript/index.js @@ -48,13 +48,13 @@ Model.prototype.sttWithMetadata = function() { return binding.SpeechToTextWithMetadata.apply(null, args); } -Model.prototype.setupStream = function() { +Model.prototype.createStream = function() { const args = [this._impl].concat(Array.prototype.slice.call(arguments)); - const rets = binding.SetupStream.apply(null, args); + const rets = binding.CreateStream.apply(null, args); const status = rets[0]; const ctx = rets[1]; if (status !== 0) { - throw "SetupStream failed with error code " + status; + throw "CreateStream failed with error code " + status; } return ctx; } @@ -75,13 +75,14 @@ Model.prototype.finishStreamWithMetadata = function() { return binding.FinishStreamWithMetadata.apply(null, arguments); } -function DestroyModel(model) { - return binding.DestroyModel(model._impl); +function FreeModel(model) { + return binding.FreeModel(model._impl); } module.exports = { Model: Model, printVersions: binding.PrintVersions, - DestroyModel: DestroyModel, + FreeModel: FreeModel, + FreeStream: binding.FreeStream, FreeMetadata: binding.FreeMetadata };