From e990e9e11e6cd12aa501af7b06801a8f2de84b9b Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Fri, 23 Dec 2016 20:39:15 +0000 Subject: [PATCH 1/5] added python-shell typings --- python-shell/index.d.ts | 42 ++++++++++++++++++++++++++++++ python-shell/python-shell-tests.ts | 38 +++++++++++++++++++++++++++ python-shell/tsconfig.json | 19 ++++++++++++++ python-shell/tslint.json | 1 + 4 files changed, 100 insertions(+) create mode 100644 python-shell/index.d.ts create mode 100644 python-shell/python-shell-tests.ts create mode 100644 python-shell/tsconfig.json create mode 100644 python-shell/tslint.json diff --git a/python-shell/index.d.ts b/python-shell/index.d.ts new file mode 100644 index 0000000000..cd61953dd7 --- /dev/null +++ b/python-shell/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for python-shell 0.4 +// Project: https://github.com/extrabacon/python-shell +// Definitions by: Dolan Miu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "python-shell" { + export class PythonShell { + on(message: string, callback: (message: string) => void): void; + end(callback: (message: string) => void): void; + send(message: string): void; + send(message: any): void; + + constructor(scriptName: string, options?: InstanceOptions); + defaultOptions: RunOptions; + } + + export interface RunOptions { + mode?: string; + formatter?: string; + parser?: string; + encoding?: string; + pythonPath?: string; + pythonOptions?: Array; + scriptPath?: string; + args?: Array; + } + + export interface InstanceOptions { + script?: string; + command?: string; + stdin?: any; + stdout?: any; + stderr?: any; + childProcess?: string; + terminated?: any; + exitCode?: any; + args?: Array; + } + + export function run(scriptName: string, RunOptions: RunOptions, callback: (err: Error, results?: any) => void): void; + export function run(scriptName: string, callback: (err: Error, results?: any) => void): void; +} \ No newline at end of file diff --git a/python-shell/python-shell-tests.ts b/python-shell/python-shell-tests.ts new file mode 100644 index 0000000000..83bca24b6e --- /dev/null +++ b/python-shell/python-shell-tests.ts @@ -0,0 +1,38 @@ +import * as ps from 'python-shell'; + +let PythonShell = ps.PythonShell; + +ps.run('my_script.py', function (err) { + if (err) throw err; + console.log('finished'); +}); + +var options = { + mode: 'text', + pythonPath: 'path/to/python', + pythonOptions: ['-u'], + scriptPath: 'path/to/my/scripts', + args: ['value1', 'value2', 'value3'] +}; + +ps.run('my_script.py', options, function (err, results) { + if (err) throw err; + // results is an array consisting of messages collected during execution + console.log('results: %j', results); +}); + +var pyshell = new PythonShell('my_script.py'); + +// sends a message to the Python script via stdin +pyshell.send('hello'); + +pyshell.on('message', function (message) { + // received a message sent from the Python script (a simple "print" statement) + console.log(message); +}); + +// end the input stream and allow the process to exit +pyshell.end(function (err) { + if (err) throw err; + console.log('finished'); +}); \ No newline at end of file diff --git a/python-shell/tsconfig.json b/python-shell/tsconfig.json new file mode 100644 index 0000000000..1eb29c744b --- /dev/null +++ b/python-shell/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "python-shell-tests.ts" + ] +} \ No newline at end of file diff --git a/python-shell/tslint.json b/python-shell/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/python-shell/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file From 3b4d72a3c494c2d5157af83a281b4119db04982e Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Fri, 23 Dec 2016 20:43:59 +0000 Subject: [PATCH 2/5] added no implicit this to true --- python-shell/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/python-shell/tsconfig.json b/python-shell/tsconfig.json index 1eb29c744b..27748977a6 100644 --- a/python-shell/tsconfig.json +++ b/python-shell/tsconfig.json @@ -3,6 +3,7 @@ "module": "commonjs", "target": "es6", "noImplicitAny": true, + "noImplicitThis": true, "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ From 5b8190be499676218352d9b473d4e2ce6ff4d131 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Fri, 23 Dec 2016 20:51:53 +0000 Subject: [PATCH 3/5] added tslint fixes --- python-shell/index.d.ts | 63 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/python-shell/index.d.ts b/python-shell/index.d.ts index cd61953dd7..f28cf45693 100644 --- a/python-shell/index.d.ts +++ b/python-shell/index.d.ts @@ -3,40 +3,37 @@ // Definitions by: Dolan Miu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module "python-shell" { - export class PythonShell { - on(message: string, callback: (message: string) => void): void; - end(callback: (message: string) => void): void; - send(message: string): void; - send(message: any): void; +export class PythonShell { + on(message: string, callback: (message: string) => void): void; + end(callback: (message: string) => void): void; + send(message: any | string): void; - constructor(scriptName: string, options?: InstanceOptions); - defaultOptions: RunOptions; - } + constructor(scriptName: string, options?: InstanceOptions); + defaultOptions: RunOptions; +} - export interface RunOptions { - mode?: string; - formatter?: string; - parser?: string; - encoding?: string; - pythonPath?: string; - pythonOptions?: Array; - scriptPath?: string; - args?: Array; - } +export interface RunOptions { + mode?: string; + formatter?: string; + parser?: string; + encoding?: string; + pythonPath?: string; + pythonOptions?: string[]; + scriptPath?: string; + args?: string[]; +} - export interface InstanceOptions { - script?: string; - command?: string; - stdin?: any; - stdout?: any; - stderr?: any; - childProcess?: string; - terminated?: any; - exitCode?: any; - args?: Array; - } +export interface InstanceOptions { + script?: string; + command?: string; + stdin?: any; + stdout?: any; + stderr?: any; + childProcess?: string; + terminated?: any; + exitCode?: any; + args?: any[]; +} - export function run(scriptName: string, RunOptions: RunOptions, callback: (err: Error, results?: any) => void): void; - export function run(scriptName: string, callback: (err: Error, results?: any) => void): void; -} \ No newline at end of file +export function run(scriptName: string, RunOptions: RunOptions, callback: (err: Error, results?: any) => void): void; +export function run(scriptName: string, callback: (err: Error, results?: any) => void): void; From f20324243d2e2a4652e0835741674729ad18da62 Mon Sep 17 00:00:00 2001 From: Dolan Date: Sun, 27 Aug 2017 17:53:38 +0100 Subject: [PATCH 4/5] Remove python shell from root --- python-shell/index.d.ts | 39 ------------------------------ python-shell/python-shell-tests.ts | 38 ----------------------------- python-shell/tsconfig.json | 20 --------------- python-shell/tslint.json | 1 - 4 files changed, 98 deletions(-) delete mode 100644 python-shell/index.d.ts delete mode 100644 python-shell/python-shell-tests.ts delete mode 100644 python-shell/tsconfig.json delete mode 100644 python-shell/tslint.json diff --git a/python-shell/index.d.ts b/python-shell/index.d.ts deleted file mode 100644 index f28cf45693..0000000000 --- a/python-shell/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -// Type definitions for python-shell 0.4 -// Project: https://github.com/extrabacon/python-shell -// Definitions by: Dolan Miu -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -export class PythonShell { - on(message: string, callback: (message: string) => void): void; - end(callback: (message: string) => void): void; - send(message: any | string): void; - - constructor(scriptName: string, options?: InstanceOptions); - defaultOptions: RunOptions; -} - -export interface RunOptions { - mode?: string; - formatter?: string; - parser?: string; - encoding?: string; - pythonPath?: string; - pythonOptions?: string[]; - scriptPath?: string; - args?: string[]; -} - -export interface InstanceOptions { - script?: string; - command?: string; - stdin?: any; - stdout?: any; - stderr?: any; - childProcess?: string; - terminated?: any; - exitCode?: any; - args?: any[]; -} - -export function run(scriptName: string, RunOptions: RunOptions, callback: (err: Error, results?: any) => void): void; -export function run(scriptName: string, callback: (err: Error, results?: any) => void): void; diff --git a/python-shell/python-shell-tests.ts b/python-shell/python-shell-tests.ts deleted file mode 100644 index 83bca24b6e..0000000000 --- a/python-shell/python-shell-tests.ts +++ /dev/null @@ -1,38 +0,0 @@ -import * as ps from 'python-shell'; - -let PythonShell = ps.PythonShell; - -ps.run('my_script.py', function (err) { - if (err) throw err; - console.log('finished'); -}); - -var options = { - mode: 'text', - pythonPath: 'path/to/python', - pythonOptions: ['-u'], - scriptPath: 'path/to/my/scripts', - args: ['value1', 'value2', 'value3'] -}; - -ps.run('my_script.py', options, function (err, results) { - if (err) throw err; - // results is an array consisting of messages collected during execution - console.log('results: %j', results); -}); - -var pyshell = new PythonShell('my_script.py'); - -// sends a message to the Python script via stdin -pyshell.send('hello'); - -pyshell.on('message', function (message) { - // received a message sent from the Python script (a simple "print" statement) - console.log(message); -}); - -// end the input stream and allow the process to exit -pyshell.end(function (err) { - if (err) throw err; - console.log('finished'); -}); \ No newline at end of file diff --git a/python-shell/tsconfig.json b/python-shell/tsconfig.json deleted file mode 100644 index 27748977a6..0000000000 --- a/python-shell/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "python-shell-tests.ts" - ] -} \ No newline at end of file diff --git a/python-shell/tslint.json b/python-shell/tslint.json deleted file mode 100644 index 2221e40e4a..0000000000 --- a/python-shell/tslint.json +++ /dev/null @@ -1 +0,0 @@ -{ "extends": "../tslint.json" } \ No newline at end of file From 98e28fa9b0398d3b76cd11404d90b20cd119eb62 Mon Sep 17 00:00:00 2001 From: Dolan Date: Sun, 27 Aug 2017 17:54:54 +0100 Subject: [PATCH 5/5] 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" }