JavaScript API Usage example¶
Examples are from native_client/javascript/client.ts.
Creating a model instance and loading model¶
50 51 52 53 54 55 56 57 58 | 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¶
127 128 129 130 131 132 133 | 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
.