@euirim/microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 15.2 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/SpeechRecognizer.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,eAAe,EACf,kBAAkB,EAGlB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EAEtB,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EACH,WAAW,EACX,uBAAuB,EACvB,YAAY,EACZ,kBAAkB,EAElB,UAAU,EACV,kCAAkC,EAClC,0BAA0B,EAC1B,uBAAuB,EAC1B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAEhE;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;IAC5C,OAAO,CAAC,4BAA4B,CAAU;IAE9C;;;;;OAKG;gBACgB,YAAY,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,WAAW;IAYxE;;;;;OAKG;IACI,WAAW,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAEpF;;;;;OAKG;IACI,UAAU,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAEnF;;;;;OAKG;IACI,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAEzF;;;;;;OAMG;aACQ,UAAU,EAAI,MAAM;IAM/B;;;;;;OAMG;;;;;;;;IACQ,kBAAkB,EAAI,MAAM;IAgBvC;;;;;;OAMG;aACQ,yBAAyB,EAAI,MAAM;IAM9C;;;;;;OAMG;aACQ,YAAY,EAAI,YAAY;IAUvC;;;;;;OAMG;aACQ,UAAU,EAAI,kBAAkB;IAI3C;;;;;;;;;;;OAWG;IACI,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAgCrG;;;;;;;;OAQG;IACI,+BAA+B,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAkCxF;;;;;;;OAOG;IACI,8BAA8B,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IA8BvF;;;;;;;;;;;;;OAaG;IACI,4BAA4B,CAAC,KAAK,EAAE,uBAAuB,EAAE,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAQrH;;;;;;;;;OASG;IACI,2BAA2B,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAMpF;;;;;OAKG;IACI,KAAK,IAAI,IAAI;IAMpB;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAa3C,SAAS,CAAC,sBAAsB,CAAC,YAAY,EAAE,mBAAmB,GAAG,gBAAgB;IAMrF,SAAS,CAAC,uBAAuB,CAC7B,cAAc,EAAE,eAAe,EAC/B,iBAAiB,EAAE,kBAAkB,EACrC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,GAAG,qBAAqB;CAIjE","file":"SpeechRecognizer.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n IAuthentication,\n IConnectionFactory,\n OutputFormatPropertyName,\n RecognitionMode,\n RecognizerConfig,\n ServiceRecognizerBase,\n SpeechServiceConfig,\n SpeechServiceRecognizer,\n} from \"../common.speech/Exports\";\nimport { SpeechConnectionFactory } from \"../common.speech/SpeechConnectionFactory\";\nimport { AudioConfigImpl } from \"./Audio/AudioConfig\";\nimport { Contracts } from \"./Contracts\";\nimport {\n AudioConfig,\n KeywordRecognitionModel,\n OutputFormat,\n PropertyCollection,\n PropertyId,\n Recognizer,\n SpeechRecognitionCanceledEventArgs,\n SpeechRecognitionEventArgs,\n SpeechRecognitionResult,\n} from \"./Exports\";\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig\";\n\n/**\n * Performs speech recognition from microphone, file, or other audio input streams, and gets transcribed text as result.\n * @class SpeechRecognizer\n */\nexport class SpeechRecognizer extends Recognizer {\n private privDisposedSpeechRecognizer: boolean;\n\n /**\n * SpeechRecognizer constructor.\n * @constructor\n * @param {SpeechConfig} speechConfig - An set of initial properties for this recognizer\n * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\n */\n public constructor(speechConfig: SpeechConfig, audioConfig?: AudioConfig) {\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\n Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\n\n Contracts.throwIfNullOrWhitespace(\n speechConfigImpl.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage),\n PropertyId[PropertyId.SpeechServiceConnection_RecoLanguage]);\n\n super(audioConfig, speechConfigImpl.properties, new SpeechConnectionFactory());\n this.privDisposedSpeechRecognizer = false;\n }\n\n /**\n * The event recognizing signals that an intermediate recognition result is received.\n * @member SpeechRecognizer.prototype.recognizing\n * @function\n * @public\n */\n public recognizing: (sender: Recognizer, event: SpeechRecognitionEventArgs) => void;\n\n /**\n * The event recognized signals that a final recognition result is received.\n * @member SpeechRecognizer.prototype.recognized\n * @function\n * @public\n */\n public recognized: (sender: Recognizer, event: SpeechRecognitionEventArgs) => void;\n\n /**\n * The event canceled signals that an error occurred during recognition.\n * @member SpeechRecognizer.prototype.canceled\n * @function\n * @public\n */\n public canceled: (sender: Recognizer, event: SpeechRecognitionCanceledEventArgs) => void;\n\n /**\n * Gets the endpoint id of a customized speech model that is used for speech recognition.\n * @member SpeechRecognizer.prototype.endpointId\n * @function\n * @public\n * @returns {string} the endpoint id of a customized speech model that is used for speech recognition.\n */\n public get endpointId(): string {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_EndpointId, \"00000000-0000-0000-0000-000000000000\");\n }\n\n /**\n * Gets the authorization token used to communicate with the service.\n * @member SpeechRecognizer.prototype.authorizationToken\n * @function\n * @public\n * @returns {string} Authorization token.\n */\n public get authorizationToken(): string {\n return this.properties.getProperty(PropertyId.SpeechServiceAuthorization_Token);\n }\n\n /**\n * Gets/Sets the authorization token used to communicate with the service.\n * @member SpeechRecognizer.prototype.authorizationToken\n * @function\n * @public\n * @param {string} token - Authorization token.\n */\n public set authorizationToken(token: string) {\n Contracts.throwIfNullOrWhitespace(token, \"token\");\n this.properties.setProperty(PropertyId.SpeechServiceAuthorization_Token, token);\n }\n\n /**\n * Gets the spoken language of recognition.\n * @member SpeechRecognizer.prototype.speechRecognitionLanguage\n * @function\n * @public\n * @returns {string} The spoken language of recognition.\n */\n public get speechRecognitionLanguage(): string {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);\n }\n\n /**\n * Gets the output format of recognition.\n * @member SpeechRecognizer.prototype.outputFormat\n * @function\n * @public\n * @returns {OutputFormat} The output format of recognition.\n */\n public get outputFormat(): OutputFormat {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n if (this.properties.getProperty(OutputFormatPropertyName, OutputFormat[OutputFormat.Simple]) === OutputFormat[OutputFormat.Simple]) {\n return OutputFormat.Simple;\n } else {\n return OutputFormat.Detailed;\n }\n }\n\n /**\n * The collection of properties and their values defined for this SpeechRecognizer.\n * @member SpeechRecognizer.prototype.properties\n * @function\n * @public\n * @returns {PropertyCollection} The collection of properties and their values defined for this SpeechRecognizer.\n */\n public get properties(): PropertyCollection {\n return this.privProperties;\n }\n\n /**\n * Starts speech recognition, and stops after the first utterance is recognized.\n * The task returns the recognition text as result.\n * Note: RecognizeOnceAsync() returns when the first utterance has been recognized,\n * so it is suitable only for single shot recognition\n * like command or query. For long-running recognition, use StartContinuousRecognitionAsync() instead.\n * @member SpeechRecognizer.prototype.recognizeOnceAsync\n * @function\n * @public\n * @param cb - Callback that received the SpeechRecognitionResult.\n * @param err - Callback invoked in case of an error.\n */\n public recognizeOnceAsync(cb?: (e: SpeechRecognitionResult) => void, err?: (e: string) => void): void {\n try {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n this.implRecognizerStop();\n\n this.implRecognizerStart(RecognitionMode.Interactive, (e: SpeechRecognitionResult) => {\n this.implRecognizerStop();\n if (!!cb) {\n cb(e);\n }\n }, (e: string) => {\n this.implRecognizerStop();\n if (!!err) {\n err(e);\n }\n });\n } catch (error) {\n if (!!err) {\n if (error instanceof Error) {\n const typedError: Error = error as Error;\n err(typedError.name + \": \" + typedError.message);\n } else {\n err(error);\n }\n }\n\n // Destroy the recognizer.\n this.dispose(true);\n }\n }\n\n /**\n * Starts speech recognition, until stopContinuousRecognitionAsync() is called.\n * User must subscribe to events to receive recognition results.\n * @member SpeechRecognizer.prototype.startContinuousRecognitionAsync\n * @function\n * @public\n * @param cb - Callback invoked once the recognition has started.\n * @param err - Callback invoked in case of an error.\n */\n public startContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\n try {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n this.implRecognizerStop();\n\n this.implRecognizerStart(RecognitionMode.Conversation, undefined, undefined);\n\n // report result to promise.\n if (!!cb) {\n try {\n cb();\n } catch (e) {\n if (!!err) {\n err(e);\n }\n }\n cb = undefined;\n }\n } catch (error) {\n if (!!err) {\n if (error instanceof Error) {\n const typedError: Error = error as Error;\n err(typedError.name + \": \" + typedError.message);\n } else {\n err(error);\n }\n }\n\n // Destroy the recognizer.\n this.dispose(true);\n }\n }\n\n /**\n * Stops continuous speech recognition.\n * @member SpeechRecognizer.prototype.stopContinuousRecognitionAsync\n * @function\n * @public\n * @param cb - Callback invoked once the recognition has stopped.\n * @param err - Callback invoked in case of an error.\n */\n public stopContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\n try {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n this.implRecognizerStop();\n\n if (!!cb) {\n try {\n cb();\n } catch (e) {\n if (!!err) {\n err(e);\n }\n }\n }\n } catch (error) {\n if (!!err) {\n if (error instanceof Error) {\n const typedError: Error = error as Error;\n err(typedError.name + \": \" + typedError.message);\n } else {\n err(error);\n }\n }\n\n // Destroy the recognizer.\n this.dispose(true);\n }\n }\n\n /**\n * Starts speech recognition with keyword spotting, until\n * stopKeywordRecognitionAsync() is called.\n * User must subscribe to events to receive recognition results.\n * Note: Key word spotting functionality is only available on the\n * Speech Devices SDK. This functionality is currently not included in the SDK itself.\n * @member SpeechRecognizer.prototype.startKeywordRecognitionAsync\n * @function\n * @public\n * @param {KeywordRecognitionModel} model The keyword recognition model that\n * specifies the keyword to be recognized.\n * @param cb - Callback invoked once the recognition has started.\n * @param err - Callback invoked in case of an error.\n */\n public startKeywordRecognitionAsync(model: KeywordRecognitionModel, cb?: () => void, err?: (e: string) => void): void {\n Contracts.throwIfNull(model, \"model\");\n\n if (!!err) {\n err(\"Not yet implemented.\");\n }\n }\n\n /**\n * Stops continuous speech recognition.\n * Note: Key word spotting functionality is only available on the\n * Speech Devices SDK. This functionality is currently not included in the SDK itself.\n * @member SpeechRecognizer.prototype.stopKeywordRecognitionAsync\n * @function\n * @public\n * @param cb - Callback invoked once the recognition has stopped.\n * @param err - Callback invoked in case of an error.\n */\n public stopKeywordRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\n if (!!cb) {\n cb();\n }\n }\n\n /**\n * closes all external resources held by an instance of this class.\n * @member SpeechRecognizer.prototype.close\n * @function\n * @public\n */\n public close(): void {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n this.dispose(true);\n }\n\n /**\n * Disposes any resources held by the object.\n * @member SpeechRecognizer.prototype.dispose\n * @function\n * @public\n * @param {boolean} disposing - true if disposing the object.\n */\n protected dispose(disposing: boolean): void {\n if (this.privDisposedSpeechRecognizer) {\n return;\n }\n\n if (disposing) {\n this.implRecognizerStop();\n this.privDisposedSpeechRecognizer = true;\n }\n\n super.dispose(disposing);\n }\n\n protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\n return new RecognizerConfig(\n speechConfig,\n this.properties);\n }\n\n protected createServiceRecognizer(\n authentication: IAuthentication,\n connectionFactory: IConnectionFactory,\n audioConfig: AudioConfig,\n recognizerConfig: RecognizerConfig): ServiceRecognizerBase {\n const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\n return new SpeechServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);\n }\n}\n"]}