Initial snowboy commit

This commit is contained in:
Dolan 2017-08-27 17:54:54 +01:00
parent f20324243d
commit 98e28fa9b0
4 changed files with 83 additions and 0 deletions

20
types/snowboy/index.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
// Type definitions for snowboy 1.2
// Project: https://github.com/Kitt-AI/snowboy
// Definitions by: Dolan Miu <https://github.com/dolanmiu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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;
}

View File

@ -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) => {
// <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) => {
// <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 <buffer> 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');

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }