From 98e28fa9b0398d3b76cd11404d90b20cd119eb62 Mon Sep 17 00:00:00 2001 From: Dolan Date: Sun, 27 Aug 2017 17:54:54 +0100 Subject: [PATCH] Initial snowboy commit --- types/snowboy/index.d.ts | 20 +++++++++++++++++ types/snowboy/snowboy-tests.ts | 40 ++++++++++++++++++++++++++++++++++ types/snowboy/tsconfig.json | 22 +++++++++++++++++++ types/snowboy/tslint.json | 1 + 4 files changed, 83 insertions(+) create mode 100644 types/snowboy/index.d.ts create mode 100644 types/snowboy/snowboy-tests.ts create mode 100644 types/snowboy/tsconfig.json create mode 100644 types/snowboy/tslint.json diff --git a/types/snowboy/index.d.ts b/types/snowboy/index.d.ts new file mode 100644 index 0000000000..df8ab04515 --- /dev/null +++ b/types/snowboy/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for snowboy 1.2 +// Project: https://github.com/Kitt-AI/snowboy +// Definitions by: Dolan Miu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Stream } from "stream"; + +export type State = "sound" | "silence" | "hotword" | "error"; + +export class Detector extends Stream { + constructor(params: any); + + on(event: State | symbol, callback: (index: any, hotword?: any, buffer?: Buffer) => void): this; +} + +export class Models { + add(params: any): void; +} diff --git a/types/snowboy/snowboy-tests.ts b/types/snowboy/snowboy-tests.ts new file mode 100644 index 0000000000..f574475fbc --- /dev/null +++ b/types/snowboy/snowboy-tests.ts @@ -0,0 +1,40 @@ +import { Detector, Models } from "snowboy"; +import * as fs from "fs"; + +const models = new Models(); + +models.add({ + file: 'resources/snowboy.umdl', + sensitivity: '0.5', + hotwords: 'snowboy' +}); + +const detector = new Detector({ + resource: "resources/common.res", + models, + audioGain: 1.0 +}); + +detector.on('silence', () => { + console.log('silence'); +}); + +detector.on('sound', (buffer) => { + // contains the last chunk of the audio that triggers the "sound" + // event. It could be written to a wav stream. + console.log('sound'); +}); + +detector.on('error', () => { + console.log('error'); +}); + +detector.on('hotword', (index, hotword, buffer) => { + // contains the last chunk of the audio that triggers the "hotword" + // event. It could be written to a wav stream. You will have to use it + // together with the in the "sound" event if you want to get audio + // data after the hotword. + console.log('hotword', index, hotword); +}); + +const file = fs.createReadStream('resources/snowboy.wav'); diff --git a/types/snowboy/tsconfig.json b/types/snowboy/tsconfig.json new file mode 100644 index 0000000000..f52d6b8c21 --- /dev/null +++ b/types/snowboy/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "snowboy-tests.ts" + ] +} diff --git a/types/snowboy/tslint.json b/types/snowboy/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/snowboy/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }