JavaScript API Usage example

Examples are from native_client/javascript/client.ts.

Creating a model instance and loading model

49
50
51
52
53
54
55
56
57
console.error('Loading model from file %s', args['model']);
const model_load_start = process.hrtime();
let model = new Ds.Model(args['model']);
const model_load_end = process.hrtime(model_load_start);
console.error('Loaded model in %ds.', totalTime(model_load_end));

if (args['beam_width']) {
  model.setBeamWidth(args['beam_width']);
}

Performing inference

118
119
120
121
122
123
124
    if (args['extended']) {
      let metadata = model.sttWithMetadata(audioBuffer, 1);
      console.log(candidateTranscriptToString(metadata.transcripts[0]));
      Ds.FreeMetadata(metadata);
    } else {
      console.log(model.stt(audioBuffer));
    }

Full source code

See Full source code.