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IjE","file":"SpeechRecognizer.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n    ForceDictationPropertyName,\n    IAuthentication,\n    IConnectionFactory,\n    OutputFormatPropertyName,\n    RecognizerConfig,\n    ServiceRecognizerBase,\n    SpeechConnectionFactory,\n    SpeechServiceConfig,\n    SpeechServiceRecognizer,\n} from \"../common.speech/Exports.js\";\nimport { RecognitionMode } from \"../common.speech/ServiceMessages/PhraseDetection/PhraseDetectionContext.js\";\nimport { marshalPromiseToCallbacks } from \"../common/Exports.js\";\nimport { AudioConfigImpl } from \"./Audio/AudioConfig.js\";\nimport { Contracts } from \"./Contracts.js\";\nimport {\n    AudioConfig,\n    AutoDetectSourceLanguageConfig,\n    KeywordRecognitionModel,\n    OutputFormat,\n    PropertyCollection,\n    PropertyId,\n    Recognizer,\n    SpeechRecognitionCanceledEventArgs,\n    SpeechRecognitionEventArgs,\n    SpeechRecognitionResult,\n} from \"./Exports.js\";\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig.js\";\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 privDisposedRecognizer: 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(), speechConfig.tokenCredential);\n        this.privDisposedRecognizer = false;\n    }\n\n    /**\n     * SpeechRecognizer constructor.\n     * @constructor\n     * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer\n     * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the recognizer\n     * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\n     */\n    public static FromConfig(speechConfig: SpeechConfig, autoDetectSourceLanguageConfig: AutoDetectSourceLanguageConfig, audioConfig?: AudioConfig): SpeechRecognizer {\n        const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\n        autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);\n        const recognizer = new SpeechRecognizer(speechConfig, audioConfig);\n        return recognizer;\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.privDisposedRecognizer);\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.privDisposedRecognizer);\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.privDisposedRecognizer);\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        marshalPromiseToCallbacks(this.recognizeOnceAsyncImpl(RecognitionMode.Interactive), cb, err);\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        marshalPromiseToCallbacks(this.startContinuousRecognitionAsyncImpl(this.properties.getProperty(ForceDictationPropertyName, undefined) === undefined ? RecognitionMode.Conversation : RecognitionMode.Dictation), cb, err);\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        marshalPromiseToCallbacks(this.stopContinuousRecognitionAsyncImpl(), cb, err);\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): 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(cb?: () => void, errorCb?: (error: string) => void): void {\n        Contracts.throwIfDisposed(this.privDisposedRecognizer);\n        marshalPromiseToCallbacks(this.dispose(true), cb, errorCb);\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 async dispose(disposing: boolean): Promise<void> {\n        if (this.privDisposedRecognizer) {\n            return;\n        }\n\n        if (disposing) {\n            this.privDisposedRecognizer = true;\n            await this.implRecognizerStop();\n        }\n\n        await super.dispose(disposing);\n    }\n\n    protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\n        return new RecognizerConfig(speechConfig, this.privProperties);\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"]}