diff options
| author | bob <bcz@cs.brown.edu> | 2019-08-01 15:05:38 -0400 |
|---|---|---|
| committer | bob <bcz@cs.brown.edu> | 2019-08-01 15:05:38 -0400 |
| commit | ff5fbd1206a065eabab917def7d83337a0442cab (patch) | |
| tree | 07c2f86558f9255b9e5a69e032287b8d0539dbd5 /src/client/util/DictationManager.ts | |
| parent | 49faa4e76f91fed04bb1923d81dd23d57a157a63 (diff) | |
| parent | 6f3d4a7015e15e0523fc194f7f911f6d45259165 (diff) | |
Merge branch 'master' into grouping
Diffstat (limited to 'src/client/util/DictationManager.ts')
| -rw-r--r-- | src/client/util/DictationManager.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/client/util/DictationManager.ts b/src/client/util/DictationManager.ts new file mode 100644 index 000000000..b58bdb6c7 --- /dev/null +++ b/src/client/util/DictationManager.ts @@ -0,0 +1,39 @@ +namespace CORE { + export interface IWindow extends Window { + webkitSpeechRecognition: any; + } +} + +const { webkitSpeechRecognition }: CORE.IWindow = window as CORE.IWindow; + +export default class DictationManager { + public static Instance = new DictationManager(); + private isListening = false; + private recognizer: any; + + constructor() { + this.recognizer = new webkitSpeechRecognition(); + this.recognizer.interimResults = false; + this.recognizer.continuous = true; + } + + finish = (handler: any, data: any) => { + handler(data); + this.isListening = false; + this.recognizer.stop(); + } + + listen = () => { + if (this.isListening) { + return undefined; + } + this.isListening = true; + this.recognizer.start(); + return new Promise<string>((resolve, reject) => { + this.recognizer.onresult = (e: any) => this.finish(resolve, e.results[0][0].transcript); + this.recognizer.onerror = (e: any) => this.finish(reject, e); + }); + + } + +}
\ No newline at end of file |
