diff options
Diffstat (limited to 'src/client/cognitive_services')
| -rw-r--r-- | src/client/cognitive_services/CognitiveServices.ts | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts index 076907f09..720892b61 100644 --- a/src/client/cognitive_services/CognitiveServices.ts +++ b/src/client/cognitive_services/CognitiveServices.ts @@ -1,15 +1,13 @@ import * as request from "request-promise"; import { Doc, Field, Opt } from "../../new_fields/Doc"; import { Cast } from "../../new_fields/Types"; -import { ImageField } from "../../new_fields/URLField"; -import { List } from "../../new_fields/List"; import { Docs } from "../documents/Documents"; import { RouteStore } from "../../server/RouteStore"; import { Utils } from "../../Utils"; -import { CompileScript } from "../util/Scripting"; -import { ComputedField } from "../../new_fields/ScriptField"; import { InkData } from "../../new_fields/InkField"; -import { undoBatch, UndoManager } from "../util/UndoManager"; +import "microsoft-cognitiveservices-speech-sdk"; +import "fs"; +import { UndoManager } from "../util/UndoManager"; type APIManager<D> = { converter: BodyConverter<D>, requester: RequestExecutor, analyzer: AnalysisApplier }; type RequestExecutor = (apiKey: string, body: string, service: Service) => Promise<string>; @@ -17,13 +15,19 @@ type AnalysisApplier = (target: Doc, relevantKeys: string[], ...args: any) => an type BodyConverter<D> = (data: D) => string; type Converter = (results: any) => Field; +namespace CORE { + export interface IWindow extends Window { + webkitSpeechRecognition: any; + } +} + export type Tag = { name: string, confidence: number }; export type Rectangle = { top: number, left: number, width: number, height: number }; export enum Service { ComputerVision = "vision", Face = "face", - Handwriting = "handwriting" + Handwriting = "handwriting", } export enum Confidence { @@ -215,4 +219,22 @@ export namespace CognitiveServices { } + export namespace Transcription { + + export const analyzer = (doc: Doc, keys: string[]) => { + let { webkitSpeechRecognition }: CORE.IWindow = window as CORE.IWindow; + let recognizer = new webkitSpeechRecognition(); + recognizer.interimResults = true; + recognizer.continuous = true; + + recognizer.onresult = (e: any) => { + let result = e.results[0][0]; + doc[keys[0]] = result.transcript; + }; + + recognizer.start(); + }; + + } + }
\ No newline at end of file |
