JavaScript API Usage example

Creating a model instance and loading model

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  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['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));
  }

Performing inference

1
2
3
4
5
  if (args['extended']) {
    console.log(metadataToString(model.sttWithMetadata(audioBuffer.slice(0, audioBuffer.length / 2), 16000)));
  } else {
    console.log(model.stt(audioBuffer.slice(0, audioBuffer.length / 2), 16000));
  }

Full source code

See Full source code.