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AAW,EACxB,gBAAgB,EAAE,gBAAgB,GAAG,qBAAqB;CAIjE","file":"SpeechRecognizer.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n IAuthentication,\r\n IConnectionFactory,\r\n OutputFormatPropertyName,\r\n RecognitionMode,\r\n RecognizerConfig,\r\n ServiceRecognizerBase,\r\n SpeechConnectionFactory,\r\n SpeechServiceConfig,\r\n SpeechServiceRecognizer,\r\n} from \"../common.speech/Exports.js\";\r\nimport { marshalPromiseToCallbacks } from \"../common/Exports.js\";\r\nimport { AudioConfigImpl } from \"./Audio/AudioConfig.js\";\r\nimport { Contracts } from \"./Contracts.js\";\r\nimport {\r\n AudioConfig,\r\n AutoDetectSourceLanguageConfig,\r\n KeywordRecognitionModel,\r\n OutputFormat,\r\n PropertyCollection,\r\n PropertyId,\r\n Recognizer,\r\n SpeechRecognitionCanceledEventArgs,\r\n SpeechRecognitionEventArgs,\r\n SpeechRecognitionResult,\r\n} from \"./Exports.js\";\r\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig.js\";\r\n\r\n/**\r\n * Performs speech recognition from microphone, file, or other audio input streams, and gets transcribed text as result.\r\n * @class SpeechRecognizer\r\n */\r\nexport class SpeechRecognizer extends Recognizer {\r\n private privDisposedRecognizer: boolean;\r\n\r\n /**\r\n * SpeechRecognizer constructor.\r\n * @constructor\r\n * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer\r\n * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\r\n */\r\n public constructor(speechConfig: SpeechConfig, audioConfig?: AudioConfig) {\r\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\r\n Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\r\n\r\n Contracts.throwIfNullOrWhitespace(\r\n speechConfigImpl.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage),\r\n PropertyId[PropertyId.SpeechServiceConnection_RecoLanguage]);\r\n\r\n super(audioConfig, speechConfigImpl.properties, new SpeechConnectionFactory());\r\n this.privDisposedRecognizer = false;\r\n }\r\n\r\n /**\r\n * SpeechRecognizer constructor.\r\n * @constructor\r\n * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer\r\n * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the recognizer\r\n * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\r\n */\r\n public static FromConfig(speechConfig: SpeechConfig, autoDetectSourceLanguageConfig: AutoDetectSourceLanguageConfig, audioConfig?: AudioConfig): SpeechRecognizer {\r\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\r\n autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);\r\n const recognizer = new SpeechRecognizer(speechConfig, audioConfig);\r\n return recognizer;\r\n }\r\n\r\n /**\r\n * The event recognizing signals that an intermediate recognition result is received.\r\n * @member SpeechRecognizer.prototype.recognizing\r\n * @function\r\n * @public\r\n */\r\n public recognizing: (sender: Recognizer, event: SpeechRecognitionEventArgs) => void;\r\n\r\n /**\r\n * The event recognized signals that a final recognition result is received.\r\n * @member SpeechRecognizer.prototype.recognized\r\n * @function\r\n * @public\r\n */\r\n public recognized: (sender: Recognizer, event: SpeechRecognitionEventArgs) => void;\r\n\r\n /**\r\n * The event canceled signals that an error occurred during recognition.\r\n * @member SpeechRecognizer.prototype.canceled\r\n * @function\r\n * @public\r\n */\r\n public canceled: (sender: Recognizer, event: SpeechRecognitionCanceledEventArgs) => void;\r\n\r\n /**\r\n * Gets the endpoint id of a customized speech model that is used for speech recognition.\r\n * @member SpeechRecognizer.prototype.endpointId\r\n * @function\r\n * @public\r\n * @returns {string} the endpoint id of a customized speech model that is used for speech recognition.\r\n */\r\n public get endpointId(): string {\r\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\r\n\r\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_EndpointId, \"00000000-0000-0000-0000-000000000000\");\r\n }\r\n\r\n /**\r\n * Gets the authorization token used to communicate with the service.\r\n * @member SpeechRecognizer.prototype.authorizationToken\r\n * @function\r\n * @public\r\n * @returns {string} Authorization token.\r\n */\r\n public get authorizationToken(): string {\r\n return this.properties.getProperty(PropertyId.SpeechServiceAuthorization_Token);\r\n }\r\n\r\n /**\r\n * Gets/Sets the authorization token used to communicate with the service.\r\n * @member SpeechRecognizer.prototype.authorizationToken\r\n * @function\r\n * @public\r\n * @param {string} token - Authorization token.\r\n */\r\n public set authorizationToken(token: string) {\r\n Contracts.throwIfNullOrWhitespace(token, \"token\");\r\n this.properties.setProperty(PropertyId.SpeechServiceAuthorization_Token, token);\r\n }\r\n\r\n /**\r\n * Gets the spoken language of recognition.\r\n * @member SpeechRecognizer.prototype.speechRecognitionLanguage\r\n * @function\r\n * @public\r\n * @returns {string} The spoken language of recognition.\r\n */\r\n public get speechRecognitionLanguage(): string {\r\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\r\n\r\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);\r\n }\r\n\r\n /**\r\n * Gets the output format of recognition.\r\n * @member SpeechRecognizer.prototype.outputFormat\r\n * @function\r\n * @public\r\n * @returns {OutputFormat} The output format of recognition.\r\n */\r\n public get outputFormat(): OutputFormat {\r\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\r\n\r\n if (this.properties.getProperty(OutputFormatPropertyName, OutputFormat[OutputFormat.Simple]) === OutputFormat[OutputFormat.Simple]) {\r\n return OutputFormat.Simple;\r\n } else {\r\n return OutputFormat.Detailed;\r\n }\r\n }\r\n\r\n /**\r\n * The collection of properties and their values defined for this SpeechRecognizer.\r\n * @member SpeechRecognizer.prototype.properties\r\n * @function\r\n * @public\r\n * @returns {PropertyCollection} The collection of properties and their values defined for this SpeechRecognizer.\r\n */\r\n public get properties(): PropertyCollection {\r\n return this.privProperties;\r\n }\r\n\r\n /**\r\n * Starts speech recognition, and stops after the first utterance is recognized.\r\n * The task returns the recognition text as result.\r\n * Note: RecognizeOnceAsync() returns when the first utterance has been recognized,\r\n * so it is suitable only for single shot recognition\r\n * like command or query. For long-running recognition, use StartContinuousRecognitionAsync() instead.\r\n * @member SpeechRecognizer.prototype.recognizeOnceAsync\r\n * @function\r\n * @public\r\n * @param cb - Callback that received the SpeechRecognitionResult.\r\n * @param err - Callback invoked in case of an error.\r\n */\r\n public recognizeOnceAsync(cb?: (e: SpeechRecognitionResult) => void, err?: (e: string) => void): void {\r\n marshalPromiseToCallbacks(this.recognizeOnceAsyncImpl(RecognitionMode.Interactive), cb, err);\r\n }\r\n\r\n /**\r\n * Starts speech recognition, until stopContinuousRecognitionAsync() is called.\r\n * User must subscribe to events to receive recognition results.\r\n * @member SpeechRecognizer.prototype.startContinuousRecognitionAsync\r\n * @function\r\n * @public\r\n * @param cb - Callback invoked once the recognition has started.\r\n * @param err - Callback invoked in case of an error.\r\n */\r\n public startContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\r\n marshalPromiseToCallbacks(this.startContinuousRecognitionAsyncImpl(RecognitionMode.Conversation), cb, err);\r\n }\r\n\r\n /**\r\n * Stops continuous speech recognition.\r\n * @member SpeechRecognizer.prototype.stopContinuousRecognitionAsync\r\n * @function\r\n * @public\r\n * @param cb - Callback invoked once the recognition has stopped.\r\n * @param err - Callback invoked in case of an error.\r\n */\r\n public stopContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\r\n marshalPromiseToCallbacks(this.stopContinuousRecognitionAsyncImpl(), cb, err);\r\n }\r\n\r\n /**\r\n * Starts speech recognition with keyword spotting, until\r\n * stopKeywordRecognitionAsync() is called.\r\n * User must subscribe to events to receive recognition results.\r\n * Note: Key word spotting functionality is only available on the\r\n * Speech Devices SDK. This functionality is currently not included in the SDK itself.\r\n * @member SpeechRecognizer.prototype.startKeywordRecognitionAsync\r\n * @function\r\n * @public\r\n * @param {KeywordRecognitionModel} model The keyword recognition model that\r\n * specifies the keyword to be recognized.\r\n * @param cb - Callback invoked once the recognition has started.\r\n * @param err - Callback invoked in case of an error.\r\n */\r\n public startKeywordRecognitionAsync(model: KeywordRecognitionModel, cb?: () => void, err?: (e: string) => void): void {\r\n Contracts.throwIfNull(model, \"model\");\r\n\r\n if (!!err) {\r\n err(\"Not yet implemented.\");\r\n }\r\n }\r\n\r\n /**\r\n * Stops continuous speech recognition.\r\n * Note: Key word spotting functionality is only available on the\r\n * Speech Devices SDK. This functionality is currently not included in the SDK itself.\r\n * @member SpeechRecognizer.prototype.stopKeywordRecognitionAsync\r\n * @function\r\n * @public\r\n * @param cb - Callback invoked once the recognition has stopped.\r\n * @param err - Callback invoked in case of an error.\r\n */\r\n public stopKeywordRecognitionAsync(cb?: () => void): void {\r\n if (!!cb) {\r\n cb();\r\n }\r\n }\r\n\r\n /**\r\n * closes all external resources held by an instance of this class.\r\n * @member SpeechRecognizer.prototype.close\r\n * @function\r\n * @public\r\n */\r\n public close(cb?: () => void, errorCb?: (error: string) => void): void {\r\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\r\n marshalPromiseToCallbacks(this.dispose(true), cb, errorCb);\r\n }\r\n\r\n /**\r\n * Disposes any resources held by the object.\r\n * @member SpeechRecognizer.prototype.dispose\r\n * @function\r\n * @public\r\n * @param {boolean} disposing - true if disposing the object.\r\n */\r\n protected async dispose(disposing: boolean): Promise<void> {\r\n if (this.privDisposedRecognizer) {\r\n return;\r\n }\r\n\r\n if (disposing) {\r\n this.privDisposedRecognizer = true;\r\n await this.implRecognizerStop();\r\n }\r\n\r\n await super.dispose(disposing);\r\n }\r\n\r\n protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\r\n return new RecognizerConfig(speechConfig, this.privProperties);\r\n }\r\n\r\n protected createServiceRecognizer(\r\n authentication: IAuthentication,\r\n connectionFactory: IConnectionFactory,\r\n audioConfig: AudioConfig,\r\n recognizerConfig: RecognizerConfig): ServiceRecognizerBase {\r\n const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\r\n return new SpeechServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);\r\n }\r\n}\r\n"]}