From 187fc88f79e0491ad3486604693feaee79305b56 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Fri, 8 Jul 2022 12:24:08 -0400 Subject: [PATCH] refactor: use types --- js/test_typescript.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/js/test_typescript.ts b/js/test_typescript.ts index 5c3f2a7..9042659 100644 --- a/js/test_typescript.ts +++ b/js/test_typescript.ts @@ -1,32 +1,33 @@ /* -*- javascript -*- */ import soundswallower_factory from "./soundswallower.js"; +import {SoundSwallowerModule, Config, Decoder, Segment, Grammar} from "./soundswallower.js"; import {promises as fs} from "fs"; import * as assert from "assert"; (async () => { - const soundswallower = await soundswallower_factory(); - const config = new soundswallower.Config(); + const soundswallower: SoundSwallowerModule = await soundswallower_factory(); + const config: Config = new soundswallower.Config(); console.log(config.get("samprate")); - let nkeys = 0; + let nkeys: number = 0; for (const key of config) { ++nkeys; } console.log(`Found ${nkeys} keys in config`); /* Basic test */ - const decoder = new soundswallower.Decoder({ + const decoder: Decoder = new soundswallower.Decoder({ fsg: "testdata/goforward.fsg", samprate: 16000, }); await decoder.initialize(); - let pcm = await fs.readFile("testdata/goforward-float32.raw"); + let pcm: Uint8Array = await fs.readFile("testdata/goforward-float32.raw"); await decoder.start(); await decoder.process(pcm, false, true); await decoder.stop(); - let hyp = decoder.get_hyp(); + let hyp: string = decoder.get_hyp(); console.log(`recognized: ${hyp}`); assert.equal("go forward ten meters", hyp); - let hypseg = decoder.get_hypseg(); - let hypseg_words = [] + let hypseg: Array = decoder.get_hypseg(); + let hypseg_words = []; for (const seg of hypseg) { assert.ok(seg.end >= seg.start); if (seg.word != "" && seg.word != "(NULL)") @@ -40,7 +41,7 @@ import * as assert from "assert"; await decoder.add_word("_forward", "F AO R W ER D", false); await decoder.add_word("_ten", "T EH N", false); await decoder.add_word("_meters", "M IY T ER Z", true); - let fsg = decoder.create_fsg("goforward", 0, 4, [ + let fsg: Grammar = decoder.create_fsg("goforward", 0, 4, [ {from: 0, to: 1, prob: 1.0, word: "_go"}, {from: 1, to: 2, prob: 1.0, word: "_forward"}, {from: 2, to: 3, prob: 1.0, word: "_ten"},