JavaScript API Usage example¶
Examples are from native_client/javascript/client.ts.
Creating a model instance and loading model¶
51 52 53 54 55 56 57 58 59 | 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']);
}
|
Transcribing audio with the loaded model¶
137 138 139 140 141 142 143 | 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
.