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B,EAAE,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAEtF;;;;;OAKG;IACI,mBAAmB,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE3F;;;;;OAKG;IACI,mBAAmB,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE3F;;;;;;OAMG;IACH,IAAW,kBAAkB,IAAI,MAAM,CAEtC;IAED;;;;;;OAMG;IACH,IAAW,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAG1C;IAED;;;;;;OAMG;IACH,IAAW,yBAAyB,IAAI,MAAM,CAI7C;IAED;;;;;;OAMG;IACH,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;;;;;;;OAQG;IACI,sBAAsB,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI;IAIlE;;;;;;;;OAQG;IACI,qBAAqB,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI;IAIjE;;OAEG;IACI,sBAAsB,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI;IAKlE;;;;;OAKG;IACI,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAKtE;;;;;;OAMG;cACa,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAY7D","file":"ConversationTranscriber.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport { TranscriberRecognizer } from \"../../common.speech/Exports\";\r\nimport { marshalPromiseToCallbacks } from \"../../common/Exports\";\r\nimport { Contracts } from \"../Contracts\";\r\nimport {\r\n    AudioConfig,\r\n    CancellationEventArgs,\r\n    ConversationTranscriptionEventArgs,\r\n    PropertyCollection,\r\n    PropertyId,\r\n    SessionEventArgs,\r\n} from \"../Exports\";\r\nimport {\r\n    ConversationHandler,\r\n    ConversationImpl,\r\n    ConversationTranscriptionHandler,\r\n} from \"./Exports\";\r\nimport { Callback, IConversation } from \"./IConversation\";\r\n\r\nexport class ConversationTranscriber implements ConversationTranscriptionHandler {\r\n    private privDisposedRecognizer: boolean;\r\n    private privRecognizer: TranscriberRecognizer;\r\n    private privProperties: PropertyCollection;\r\n    protected privAudioConfig: AudioConfig;\r\n\r\n    /**\r\n     * ConversationTranscriber constructor.\r\n     * @constructor\r\n     * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\r\n     */\r\n    public constructor(audioConfig?: AudioConfig) {\r\n        this.privAudioConfig = audioConfig;\r\n        this.privProperties = new PropertyCollection();\r\n        this.privRecognizer = undefined;\r\n        this.privDisposedRecognizer = false;\r\n    }\r\n\r\n    /**\r\n     * The event canceled signals that an error occurred during the conversation.\r\n     * @member ConversationTranscriber.prototype.conversationCanceled\r\n     * @function\r\n     * @public\r\n     */\r\n    public conversationCanceled: (sender: ConversationHandler, event: CancellationEventArgs) => void;\r\n\r\n    /**\r\n     * The event canceled signals that an error occurred during transcription.\r\n     * @member ConversationTranscriber.prototype.canceled\r\n     * @function\r\n     * @public\r\n     */\r\n    public canceled: (sender: ConversationHandler, event: CancellationEventArgs) => void;\r\n\r\n    /**\r\n     * @param {Conversation} converation - conversation to be recognized\r\n     */\r\n    public joinConversationAsync(conversation: IConversation, cb?: Callback, err?: Callback): void {\r\n        const conversationImpl = conversation as ConversationImpl;\r\n        Contracts.throwIfNullOrUndefined(conversationImpl, \"Conversation\");\r\n\r\n        // ref the conversation object\r\n        // create recognizer and subscribe to recognizer events\r\n        this.privRecognizer = new TranscriberRecognizer(conversation.config, this.privAudioConfig);\r\n        Contracts.throwIfNullOrUndefined(this.privRecognizer, \"Recognizer\");\r\n        this.privRecognizer.connectCallbacks(this);\r\n\r\n        marshalPromiseToCallbacks(conversationImpl.connectTranscriberRecognizer(this.privRecognizer), cb, err);\r\n    }\r\n\r\n     /**\r\n      * The event recognized signals that a final conversation transcription result is received.\r\n      * @member ConversationTranscriber.prototype.transcribed\r\n      * @function\r\n      * @public\r\n      */\r\n    public transcribed: (sender: ConversationTranscriptionHandler, event: ConversationTranscriptionEventArgs) => void;\r\n\r\n     /**\r\n      * The event recognizing signals that an intermediate conversation transcription result is received.\r\n      * @member ConversationTranscriber.prototype.transcribing\r\n      * @function\r\n      * @public\r\n      */\r\n    public transcribing: (sender: ConversationTranscriptionHandler, event: ConversationTranscriptionEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for session started events.\r\n     * @member ConversationTranscriber.prototype.sessionStarted\r\n     * @function\r\n     * @public\r\n     */\r\n    public sessionStarted: (sender: ConversationHandler, event: SessionEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for session stopped events.\r\n     * @member ConversationTranscriber.prototype.sessionStopped\r\n     * @function\r\n     * @public\r\n     */\r\n    public sessionStopped: (sender: ConversationHandler, event: SessionEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for conversation started events.\r\n     * @member ConversationTranscriber.prototype.conversationStarted\r\n     * @function\r\n     * @public\r\n     */\r\n    public conversationStarted: (sender: ConversationHandler, event: SessionEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for conversation stopped events.\r\n     * @member ConversationTranscriber.prototype.conversationStopped\r\n     * @function\r\n     * @public\r\n     */\r\n    public conversationStopped: (sender: ConversationHandler, event: SessionEventArgs) => void;\r\n\r\n    /**\r\n     * Gets the authorization token used to communicate with the service.\r\n     * @member ConversationTranscriber.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 ConversationTranscriber.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 ConversationTranscriber.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     * The collection of properties and their values defined for this ConversationTranscriber.\r\n     * @member ConversationTranscriber.prototype.properties\r\n     * @function\r\n     * @public\r\n     * @returns {PropertyCollection} The collection of properties and their values defined for this ConversationTranscriber.\r\n     */\r\n    public get properties(): PropertyCollection {\r\n        return this.privProperties;\r\n    }\r\n\r\n    /**\r\n     * Starts conversation transcription, until stopTranscribingAsync() is called.\r\n     * User must subscribe to events to receive transcription results.\r\n     * @member ConversationTranscriber.prototype.startTranscribingAsync\r\n     * @function\r\n     * @public\r\n     * @param cb - Callback invoked once the transcription has started.\r\n     * @param err - Callback invoked in case of an error.\r\n     */\r\n    public startTranscribingAsync(cb?: Callback, err?: Callback): void {\r\n        this.privRecognizer.startContinuousRecognitionAsync(cb, err);\r\n    }\r\n\r\n    /**\r\n     * Starts conversation transcription, until stopTranscribingAsync() is called.\r\n     * User must subscribe to events to receive transcription results.\r\n     * @member ConversationTranscriber.prototype.stopTranscribingAsync\r\n     * @function\r\n     * @public\r\n     * @param cb - Callback invoked once the transcription has started.\r\n     * @param err - Callback invoked in case of an error.\r\n     */\r\n    public stopTranscribingAsync(cb?: Callback, err?: Callback): void {\r\n        this.privRecognizer.stopContinuousRecognitionAsync(cb, err);\r\n    }\r\n\r\n    /**\r\n     * Leave the current conversation. After this is called, you will no longer receive any events.\r\n     */\r\n    public leaveConversationAsync(cb?: Callback, err?: Callback): void {\r\n        this.privRecognizer.disconnectCallbacks();\r\n        marshalPromiseToCallbacks((async (): Promise<void> => { return; })(), cb, err);\r\n    }\r\n\r\n    /**\r\n     * closes all external resources held by an instance of this class.\r\n     * @member ConversationTranscriber.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 ConversationTranscriber.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        if (!!this.privRecognizer) {\r\n            await this.privRecognizer.close();\r\n            this.privRecognizer = undefined;\r\n        }\r\n        if (disposing) {\r\n            this.privDisposedRecognizer = true;\r\n        }\r\n    }\r\n}\r\n"]}