Skip to content

Commit

Permalink
refactor: use types
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Jul 8, 2022
1 parent f57c6a7 commit 187fc88
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions js/test_typescript.ts
Original file line number Diff line number Diff line change
@@ -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<Segment> = decoder.get_hypseg();
let hypseg_words = [];
for (const seg of hypseg) {
assert.ok(seg.end >= seg.start);
if (seg.word != "<sil>" && seg.word != "(NULL)")
Expand All @@ -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"},
Expand Down

0 comments on commit 187fc88

Please sign in to comment.