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AAiB,CAAC;gBAEzB,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,EAAE,UAAU,CAAC,EAAE,iBAAiB;CAQnK","file":"SpeechSynthesizer.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport { PathLike } from \"fs\";\r\nimport {\r\n    AutoDetectSourceLanguagesOpenRangeOptionName,\r\n    CognitiveSubscriptionKeyAuthentication,\r\n    CognitiveTokenAuthentication,\r\n    Context,\r\n    IAuthentication,\r\n    ISynthesisConnectionFactory,\r\n    OS,\r\n    SpeechServiceConfig,\r\n    SpeechSynthesisConnectionFactory,\r\n    SynthesisAdapterBase,\r\n    SynthesizerConfig,\r\n} from \"../common.speech/Exports\";\r\nimport {\r\n    createNoDashGuid,\r\n    IAudioDestination,\r\n    IStringDictionary,\r\n    marshalPromiseToCallbacks,\r\n    Queue\r\n} from \"../common/Exports\";\r\nimport { AudioOutputConfigImpl } from \"./Audio/AudioConfig\";\r\nimport { AudioFileWriter } from \"./Audio/AudioFileWriter\";\r\nimport { AudioOutputFormatImpl } from \"./Audio/AudioOutputFormat\";\r\nimport {\r\n    PullAudioOutputStreamImpl,\r\n    PushAudioOutputStreamImpl\r\n} from \"./Audio/AudioOutputStream\";\r\nimport { Contracts } from \"./Contracts\";\r\nimport {\r\n    AudioConfig,\r\n    AudioOutputStream,\r\n    AutoDetectSourceLanguageConfig,\r\n    PropertyCollection,\r\n    PropertyId,\r\n    PullAudioOutputStream,\r\n    PushAudioOutputStreamCallback,\r\n    SpeechConfig,\r\n    SpeechSynthesisBookmarkEventArgs,\r\n    SpeechSynthesisEventArgs,\r\n    SpeechSynthesisOutputFormat,\r\n    SpeechSynthesisResult,\r\n    SpeechSynthesisVisemeEventArgs,\r\n    SpeechSynthesisWordBoundaryEventArgs,\r\n} from \"./Exports\";\r\nimport { SpeechConfigImpl } from \"./SpeechConfig\";\r\n\r\n/**\r\n * Defines the class SpeechSynthesizer for text to speech.\r\n * Updated in version 1.16.0\r\n * @class SpeechSynthesizer\r\n */\r\nexport class SpeechSynthesizer {\r\n    protected audioConfig: AudioConfig;\r\n    protected privAdapter: SynthesisAdapterBase;\r\n    protected privProperties: PropertyCollection;\r\n    protected synthesisRequestQueue: Queue<SynthesisRequest>;\r\n\r\n    /**\r\n     * Defines event handler for synthesis start events.\r\n     * @member SpeechSynthesizer.prototype.synthesisStarted\r\n     * @function\r\n     * @public\r\n     */\r\n    public synthesisStarted: (sender: SpeechSynthesizer, event: SpeechSynthesisEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for synthesizing events.\r\n     * @member SpeechSynthesizer.prototype.synthesizing\r\n     * @function\r\n     * @public\r\n     */\r\n    public synthesizing: (sender: SpeechSynthesizer, event: SpeechSynthesisEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for synthesis completed events.\r\n     * @member SpeechSynthesizer.prototype.synthesisCompleted\r\n     * @function\r\n     * @public\r\n     */\r\n    public synthesisCompleted: (sender: SpeechSynthesizer, event: SpeechSynthesisEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for synthesis cancelled events.\r\n     * @member SpeechSynthesizer.prototype.SynthesisCanceled\r\n     * @function\r\n     * @public\r\n     */\r\n    public SynthesisCanceled: (sender: SpeechSynthesizer, event: SpeechSynthesisEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for word boundary events\r\n     * @member SpeechSynthesizer.prototype.wordBoundary\r\n     * @function\r\n     * @public\r\n     */\r\n    public wordBoundary: (sender: SpeechSynthesizer, event: SpeechSynthesisWordBoundaryEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for bookmark reached events\r\n     * Added in version 1.16.0\r\n     * @member SpeechSynthesizer.prototype.bookmarkReached\r\n     * @function\r\n     * @public\r\n     */\r\n    public bookmarkReached: (sender: SpeechSynthesizer, event: SpeechSynthesisBookmarkEventArgs) => void;\r\n\r\n    /**\r\n     * Defines event handler for viseme received event\r\n     * Added in version 1.16.0\r\n     * @member SpeechSynthesizer.prototype.visemeReceived\r\n     * @function\r\n     * @public\r\n     */\r\n    public visemeReceived: (sender: SpeechSynthesizer, event: SpeechSynthesisVisemeEventArgs) => void;\r\n\r\n    /**\r\n     * Gets the authorization token used to communicate with the service.\r\n     * @member SpeechSynthesizer.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 SpeechSynthesizer.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     * The collection of properties and their values defined for this SpeechSynthesizer.\r\n     * @member SpeechSynthesizer.prototype.properties\r\n     * @function\r\n     * @public\r\n     * @returns {PropertyCollection} The collection of properties and their values defined for this SpeechSynthesizer.\r\n     */\r\n    public get properties(): PropertyCollection {\r\n        return this.privProperties;\r\n    }\r\n\r\n    /**\r\n     * Indicates if auto detect source language is enabled\r\n     * @member SpeechSynthesizer.prototype.properties\r\n     * @function\r\n     * @public\r\n     * @returns {boolean} if auto detect source language is enabled\r\n     */\r\n    public get autoDetectSourceLanguage(): boolean {\r\n        return this.properties.getProperty(PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages) === AutoDetectSourceLanguagesOpenRangeOptionName;\r\n    }\r\n\r\n    private privDisposed: boolean;\r\n    private privConnectionFactory: ISynthesisConnectionFactory;\r\n    private privSynthesizing: boolean;\r\n\r\n    /**\r\n     * SpeechSynthesizer constructor.\r\n     * @constructor\r\n     * @param {SpeechConfig} speechConfig - An set of initial properties for this synthesizer.\r\n     * @param {AudioConfig} audioConfig - An optional audio configuration associated with the synthesizer.\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        if (audioConfig !== null) {\r\n            if (audioConfig === undefined) {\r\n                this.audioConfig = (typeof window === \"undefined\") ? undefined : AudioConfig.fromDefaultSpeakerOutput();\r\n            } else {\r\n                this.audioConfig = audioConfig;\r\n            }\r\n        }\r\n\r\n        this.privProperties = speechConfigImpl.properties.clone();\r\n        this.privDisposed = false;\r\n        this.privSynthesizing = false;\r\n        this.privConnectionFactory = new SpeechSynthesisConnectionFactory();\r\n        this.synthesisRequestQueue = new Queue<SynthesisRequest>();\r\n        this.implCommonSynthesizeSetup();\r\n    }\r\n\r\n    /**\r\n     * SpeechSynthesizer constructor.\r\n     * @constructor\r\n     * @param {SpeechConfig} speechConfig - an set of initial properties for this synthesizer\r\n     * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the synthesizer\r\n     * @param {AudioConfig} audioConfig - An optional audio configuration associated with the synthesizer\r\n     */\r\n    public static FromConfig(speechConfig: SpeechConfig, autoDetectSourceLanguageConfig: AutoDetectSourceLanguageConfig, audioConfig?: AudioConfig): SpeechSynthesizer {\r\n        const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\r\n        autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);\r\n        return new SpeechSynthesizer(speechConfig, audioConfig);\r\n    }\r\n\r\n    public buildSsml(text: string): string {\r\n        const languageToDefaultVoice: IStringDictionary<string>  = {\r\n            [\"af-ZA\"]: \"af-ZA-AdriNeural\",\r\n            [\"am-ET\"]: \"am-ET-AmehaNeural\",\r\n            [\"ar-AE\"]: \"ar-AE-FatimaNeural\",\r\n            [\"ar-BH\"]: \"ar-BH-AliNeural\",\r\n            [\"ar-DZ\"]: \"ar-DZ-AminaNeural\",\r\n            [\"ar-EG\"]: \"ar-EG-SalmaNeural\",\r\n            [\"ar-IQ\"]: \"ar-IQ-BasselNeural\",\r\n            [\"ar-JO\"]: \"ar-JO-SanaNeural\",\r\n            [\"ar-KW\"]: \"ar-KW-FahedNeural\",\r\n            [\"ar-LY\"]: \"ar-LY-ImanNeural\",\r\n            [\"ar-MA\"]: \"ar-MA-JamalNeural\",\r\n            [\"ar-QA\"]: \"ar-QA-AmalNeural\",\r\n            [\"ar-SA\"]: \"ar-SA-HamedNeural\",\r\n            [\"ar-SY\"]: \"ar-SY-AmanyNeural\",\r\n            [\"ar-TN\"]: \"ar-TN-HediNeural\",\r\n            [\"ar-YE\"]: \"ar-YE-MaryamNeural\",\r\n            [\"bg-BG\"]: \"bg-BG-BorislavNeural\",\r\n            [\"bn-BD\"]: \"bn-BD-NabanitaNeural\",\r\n            [\"ca-ES\"]: \"ca-ES-JoanaNeural\",\r\n            [\"cs-CZ\"]: \"cs-CZ-AntoninNeural\",\r\n            [\"cy-GB\"]: \"cy-GB-AledNeural\",\r\n            [\"da-DK\"]: \"da-DK-ChristelNeural\",\r\n            [\"de-AT\"]: \"de-AT-IngridNeural\",\r\n            [\"de-CH\"]: \"de-CH-JanNeural\",\r\n            [\"de-DE\"]: \"de-DE-KatjaNeural\",\r\n            [\"el-GR\"]: \"el-GR-AthinaNeural\",\r\n            [\"en-AU\"]: \"en-AU-NatashaNeural\",\r\n            [\"en-CA\"]: \"en-CA-ClaraNeural\",\r\n            [\"en-GB\"]: \"en-GB-LibbyNeural\",\r\n            [\"en-HK\"]: \"en-HK-SamNeural\",\r\n            [\"en-IE\"]: \"en-IE-ConnorNeural\",\r\n            [\"en-IN\"]: \"en-IN-NeerjaNeural\",\r\n            [\"en-KE\"]: \"en-KE-AsiliaNeural\",\r\n            [\"en-NG\"]: \"en-NG-AbeoNeural\",\r\n            [\"en-NZ\"]: \"en-NZ-MitchellNeural\",\r\n            [\"en-PH\"]: \"en-PH-JamesNeural\",\r\n            [\"en-SG\"]: \"en-SG-LunaNeural\",\r\n            [\"en-TZ\"]: \"en-TZ-ElimuNeural\",\r\n            [\"en-US\"]: \"en-US-JennyNeural\",\r\n            [\"en-ZA\"]: \"en-ZA-LeahNeural\",\r\n            [\"es-AR\"]: \"es-AR-ElenaNeural\",\r\n            [\"es-BO\"]: \"es-BO-MarceloNeural\",\r\n            [\"es-CL\"]: \"es-CL-CatalinaNeural\",\r\n            [\"es-CO\"]: \"es-CO-GonzaloNeural\",\r\n            [\"es-CR\"]: \"es-CR-JuanNeural\",\r\n            [\"es-CU\"]: \"es-CU-BelkysNeural\",\r\n            [\"es-DO\"]: \"es-DO-EmilioNeural\",\r\n            [\"es-EC\"]: \"es-EC-AndreaNeural\",\r\n            [\"es-ES\"]: \"es-ES-AlvaroNeural\",\r\n            [\"es-GQ\"]: \"es-GQ-JavierNeural\",\r\n            [\"es-GT\"]: \"es-GT-AndresNeural\",\r\n            [\"es-HN\"]: \"es-HN-CarlosNeural\",\r\n            [\"es-MX\"]: \"es-MX-DaliaNeural\",\r\n            [\"es-NI\"]: \"es-NI-FedericoNeural\",\r\n            [\"es-PA\"]: \"es-PA-MargaritaNeural\",\r\n            [\"es-PE\"]: \"es-PE-AlexNeural\",\r\n            [\"es-PR\"]: \"es-PR-KarinaNeural\",\r\n            [\"es-PY\"]: \"es-PY-MarioNeural\",\r\n            [\"es-SV\"]: \"es-SV-LorenaNeural\",\r\n            [\"es-US\"]: \"es-US-AlonsoNeural\",\r\n            [\"es-UY\"]: \"es-UY-MateoNeural\",\r\n            [\"es-VE\"]: \"es-VE-PaolaNeural\",\r\n            [\"et-EE\"]: \"et-EE-AnuNeural\",\r\n            [\"fa-IR\"]: \"fa-IR-DilaraNeural\",\r\n            [\"fi-FI\"]: \"fi-FI-SelmaNeural\",\r\n            [\"fil-PH\"]: \"fil-PH-AngeloNeural\",\r\n            [\"fr-BE\"]: \"fr-BE-CharlineNeural\",\r\n            [\"fr-CA\"]: \"fr-CA-SylvieNeural\",\r\n            [\"fr-CH\"]: \"fr-CH-ArianeNeural\",\r\n            [\"fr-FR\"]: \"fr-FR-DeniseNeural\",\r\n            [\"ga-IE\"]: \"ga-IE-ColmNeural\",\r\n            [\"gl-ES\"]: \"gl-ES-RoiNeural\",\r\n            [\"gu-IN\"]: \"gu-IN-DhwaniNeural\",\r\n            [\"he-IL\"]: \"he-IL-AvriNeural\",\r\n            [\"hi-IN\"]: \"hi-IN-MadhurNeural\",\r\n            [\"hr-HR\"]: \"hr-HR-GabrijelaNeural\",\r\n            [\"hu-HU\"]: \"hu-HU-NoemiNeural\",\r\n            [\"id-ID\"]: \"id-ID-ArdiNeural\",\r\n            [\"it-IT\"]: \"it-IT-IsabellaNeural\",\r\n            [\"ja-JP\"]: \"ja-JP-NanamiNeural\",\r\n            [\"jv-ID\"]: \"jv-ID-DimasNeural\",\r\n            [\"km-KH\"]: \"km-KH-PisethNeural\",\r\n            [\"ko-KR\"]: \"ko-KR-SunHiNeural\",\r\n            [\"lt-LT\"]: \"lt-LT-LeonasNeural\",\r\n            [\"lv-LV\"]: \"lv-LV-EveritaNeural\",\r\n            [\"mr-IN\"]: \"mr-IN-AarohiNeural\",\r\n            [\"ms-MY\"]: \"ms-MY-OsmanNeural\",\r\n            [\"mt-MT\"]: \"mt-MT-GraceNeural\",\r\n            [\"my-MM\"]: \"my-MM-NilarNeural\",\r\n            [\"nb-NO\"]: \"nb-NO-PernilleNeural\",\r\n            [\"nl-BE\"]: \"nl-BE-ArnaudNeural\",\r\n            [\"nl-NL\"]: \"nl-NL-ColetteNeural\",\r\n            [\"pl-PL\"]: \"pl-PL-AgnieszkaNeural\",\r\n            [\"pt-BR\"]: \"pt-BR-FranciscaNeural\",\r\n            [\"pt-PT\"]: \"pt-PT-DuarteNeural\",\r\n            [\"ro-RO\"]: \"ro-RO-AlinaNeural\",\r\n            [\"ru-RU\"]: \"ru-RU-SvetlanaNeural\",\r\n            [\"sk-SK\"]: \"sk-SK-LukasNeural\",\r\n            [\"sl-SI\"]: \"sl-SI-PetraNeural\",\r\n            [\"so-SO\"]: \"so-SO-MuuseNeural\",\r\n            [\"su-ID\"]: \"su-ID-JajangNeural\",\r\n            [\"sv-SE\"]: \"sv-SE-SofieNeural\",\r\n            [\"sw-KE\"]: \"sw-KE-RafikiNeural\",\r\n            [\"sw-TZ\"]: \"sw-TZ-DaudiNeural\",\r\n            [\"ta-IN\"]: \"ta-IN-PallaviNeural\",\r\n            [\"ta-LK\"]: \"ta-LK-KumarNeural\",\r\n            [\"ta-SG\"]: \"ta-SG-AnbuNeural\",\r\n            [\"te-IN\"]: \"te-IN-MohanNeural\",\r\n            [\"th-TH\"]: \"th-TH-PremwadeeNeural\",\r\n            [\"tr-TR\"]: \"tr-TR-AhmetNeural\",\r\n            [\"uk-UA\"]: \"uk-UA-OstapNeural\",\r\n            [\"ur-IN\"]: \"ur-IN-GulNeural\",\r\n            [\"ur-PK\"]: \"ur-PK-AsadNeural\",\r\n            [\"uz-UZ\"]: \"uz-UZ-MadinaNeural\",\r\n            [\"vi-VN\"]: \"vi-VN-HoaiMyNeural\",\r\n            [\"zh-CN\"]: \"zh-CN-XiaoxiaoNeural\",\r\n            [\"zh-HK\"]: \"zh-HK-HiuMaanNeural\",\r\n            [\"zh-TW\"]: \"zh-TW-HsiaoChenNeural\",\r\n            [\"zu-ZA\"]: \"zu-ZA-ThandoNeural\",\r\n        };\r\n\r\n        let language = this.properties.getProperty(PropertyId.SpeechServiceConnection_SynthLanguage, \"en-US\");\r\n        let voice = this.properties.getProperty(PropertyId.SpeechServiceConnection_SynthVoice, \"\");\r\n        let ssml: string = SpeechSynthesizer.XMLEncode(text);\r\n        if (this.autoDetectSourceLanguage) {\r\n            language = \"en-US\";\r\n        } else {\r\n            voice = voice || languageToDefaultVoice[language];\r\n        }\r\n        if (voice) {\r\n            ssml = `<voice name='${voice}'>${ssml}</voice>`;\r\n        }\r\n        ssml = `<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xmlns:mstts='http://www.w3.org/2001/mstts' xmlns:emo='http://www.w3.org/2009/10/emotionml' xml:lang='${language}'>${ssml}</speak>`;\r\n        return ssml;\r\n    }\r\n\r\n    /**\r\n     * Executes speech synthesis on plain text.\r\n     * The task returns the synthesis result.\r\n     * @member SpeechSynthesizer.prototype.speakTextAsync\r\n     * @function\r\n     * @public\r\n     * @param text - Text to be synthesized.\r\n     * @param cb - Callback that received the SpeechSynthesisResult.\r\n     * @param err - Callback invoked in case of an error.\r\n     * @param stream - AudioOutputStream to receive the synthesized audio.\r\n     */\r\n    public speakTextAsync(text: string, cb?: (e: SpeechSynthesisResult) => void, err?: (e: string) => void, stream?: AudioOutputStream | PushAudioOutputStreamCallback | PathLike): void {\r\n        this.speakImpl(text, false, cb, err, stream);\r\n    }\r\n\r\n    /**\r\n     * Executes speech synthesis on SSML.\r\n     * The task returns the synthesis result.\r\n     * @member SpeechSynthesizer.prototype.speakSsmlAsync\r\n     * @function\r\n     * @public\r\n     * @param ssml - SSML to be synthesized.\r\n     * @param cb - Callback that received the SpeechSynthesisResult.\r\n     * @param err - Callback invoked in case of an error.\r\n     * @param stream - AudioOutputStream to receive the synthesized audio.\r\n     */\r\n    public speakSsmlAsync(ssml: string, cb?: (e: SpeechSynthesisResult) => void, err?: (e: string) => void, stream?: AudioOutputStream | PushAudioOutputStreamCallback | PathLike): void {\r\n        this.speakImpl(ssml, true, cb, err, stream);\r\n    }\r\n\r\n    /**\r\n     * Dispose of associated resources.\r\n     * @member SpeechSynthesizer.prototype.close\r\n     * @function\r\n     * @public\r\n     */\r\n    public close(cb?: () => void, err?: (error: string) => void): void {\r\n        Contracts.throwIfDisposed(this.privDisposed);\r\n\r\n        marshalPromiseToCallbacks(this.dispose(true), cb, err);\r\n    }\r\n\r\n    /**\r\n     * @Internal\r\n     * Do not use externally, object returned will change without warning or notice.\r\n     */\r\n    public get internalData(): object {\r\n        return this.privAdapter;\r\n    }\r\n\r\n    /**\r\n     * This method performs cleanup of resources.\r\n     * The Boolean parameter disposing indicates whether the method is called\r\n     * from Dispose (if disposing is true) or from the finalizer (if disposing is false).\r\n     * Derived classes should override this method to dispose resource if needed.\r\n     * @member SpeechSynthesizer.prototype.dispose\r\n     * @function\r\n     * @public\r\n     * @param {boolean} disposing - Flag to request disposal.\r\n     */\r\n    protected async dispose(disposing: boolean): Promise<void> {\r\n        if (this.privDisposed) {\r\n            return;\r\n        }\r\n\r\n        if (disposing) {\r\n            if (this.privAdapter) {\r\n                await this.privAdapter.dispose();\r\n            }\r\n        }\r\n\r\n        this.privDisposed = true;\r\n    }\r\n\r\n    //\r\n    // ################################################################################################################\r\n    // IMPLEMENTATION.\r\n    // Move to independent class\r\n    // ################################################################################################################\r\n    //\r\n    protected createSynthesizerConfig(speechConfig: SpeechServiceConfig): SynthesizerConfig {\r\n        return new SynthesizerConfig(\r\n            speechConfig,\r\n            this.privProperties);\r\n    }\r\n\r\n    // Creates the synthesis adapter\r\n    protected createSynthesisAdapter(\r\n        authentication: IAuthentication,\r\n        connectionFactory: ISynthesisConnectionFactory,\r\n        audioConfig: AudioConfig,\r\n        synthesizerConfig: SynthesizerConfig): SynthesisAdapterBase {\r\n        return new SynthesisAdapterBase(authentication, connectionFactory,\r\n            synthesizerConfig, this, this.audioConfig as AudioOutputConfigImpl);\r\n    }\r\n\r\n    protected implCommonSynthesizeSetup(): void {\r\n\r\n        let osPlatform = (typeof window !== \"undefined\") ? \"Browser\" : \"Node\";\r\n        let osName = \"unknown\";\r\n        let osVersion = \"unknown\";\r\n\r\n        if (typeof navigator !== \"undefined\") {\r\n            osPlatform = osPlatform + \"/\" + navigator.platform;\r\n            osName = navigator.userAgent;\r\n            osVersion = navigator.appVersion;\r\n        }\r\n\r\n        const synthesizerConfig = this.createSynthesizerConfig(\r\n            new SpeechServiceConfig(\r\n                new Context(new OS(osPlatform, osName, osVersion))));\r\n\r\n        const subscriptionKey = this.privProperties.getProperty(PropertyId.SpeechServiceConnection_Key, undefined);\r\n        const authentication = (subscriptionKey && subscriptionKey !== \"\") ?\r\n            new CognitiveSubscriptionKeyAuthentication(subscriptionKey) :\r\n            new CognitiveTokenAuthentication(\r\n                (authFetchEventId: string): Promise<string> => {\r\n                    const authorizationToken = this.privProperties.getProperty(PropertyId.SpeechServiceAuthorization_Token, undefined);\r\n                    return Promise.resolve(authorizationToken);\r\n                },\r\n                (authFetchEventId: string): Promise<string> => {\r\n                    const authorizationToken = this.privProperties.getProperty(PropertyId.SpeechServiceAuthorization_Token, undefined);\r\n                    return Promise.resolve(authorizationToken);\r\n                });\r\n\r\n        this.privAdapter = this.createSynthesisAdapter(\r\n            authentication,\r\n            this.privConnectionFactory,\r\n            this.audioConfig,\r\n            synthesizerConfig);\r\n\r\n        this.privAdapter.audioOutputFormat = AudioOutputFormatImpl.fromSpeechSynthesisOutputFormat(\r\n            (SpeechSynthesisOutputFormat as any)[this.properties.getProperty(PropertyId.SpeechServiceConnection_SynthOutputFormat, undefined)]\r\n        );\r\n    }\r\n\r\n    protected speakImpl(text: string, IsSsml: boolean, cb?: (e: SpeechSynthesisResult) => void, err?: (e: string) => void, dataStream?: AudioOutputStream | PushAudioOutputStreamCallback | PathLike): void {\r\n        try {\r\n            Contracts.throwIfDisposed(this.privDisposed);\r\n            const requestId = createNoDashGuid();\r\n            let audioDestination;\r\n            if (dataStream instanceof PushAudioOutputStreamCallback) {\r\n                audioDestination = new PushAudioOutputStreamImpl(dataStream);\r\n            } else if (dataStream instanceof PullAudioOutputStream) {\r\n                audioDestination = dataStream as PullAudioOutputStreamImpl;\r\n            } else if (dataStream !== undefined) {\r\n                audioDestination = new AudioFileWriter(dataStream as PathLike);\r\n            } else {\r\n                audioDestination = undefined;\r\n            }\r\n            this.synthesisRequestQueue.enqueue(new SynthesisRequest(requestId, text, IsSsml, (e: SpeechSynthesisResult): void => {\r\n                this.privSynthesizing = false;\r\n                if (!!cb) {\r\n                    try {\r\n                        cb(e);\r\n                    } catch (e) {\r\n                        if (!!err) {\r\n                            err(e);\r\n                        }\r\n                    }\r\n                }\r\n                cb = undefined;\r\n                /* tslint:disable:no-empty */\r\n                this.adapterSpeak().catch(() => { });\r\n\r\n            }, (e: string): void => {\r\n                if (!!err) {\r\n                    err(e);\r\n                }\r\n            }, audioDestination));\r\n\r\n            /* tslint:disable:no-empty */\r\n            this.adapterSpeak().catch(() => { });\r\n\r\n        } catch (error) {\r\n            if (!!err) {\r\n                if (error instanceof Error) {\r\n                    const typedError: Error = error as Error;\r\n                    err(typedError.name + \": \" + typedError.message);\r\n                } else {\r\n                    err(error);\r\n                }\r\n            }\r\n\r\n            // Destroy the synthesizer.\r\n            /* tslint:disable:no-empty */\r\n            this.dispose(true).catch(() => { });\r\n        }\r\n    }\r\n\r\n    protected async adapterSpeak(): Promise<void> {\r\n        if (!this.privDisposed && !this.privSynthesizing) {\r\n            this.privSynthesizing = true;\r\n            const request: SynthesisRequest = await this.synthesisRequestQueue.dequeue();\r\n            return this.privAdapter.Speak(request.text, request.isSSML, request.requestId, request.cb, request.err, request.dataStream);\r\n        }\r\n    }\r\n\r\n    private static XMLEncode(text: string): string {\r\n        return text.replace(/&/g, \"&amp;\")\r\n            .replace(/</g, \"&lt;\")\r\n            .replace(/>/g, \"&gt;\")\r\n            .replace(/\"/g, \"&quot;\")\r\n            .replace(/'/g, \"&apos;\");\r\n    }\r\n}\r\n\r\n// tslint:disable-next-line:max-classes-per-file\r\nexport class SynthesisRequest {\r\n    public requestId: string;\r\n    public text: string;\r\n    public isSSML: boolean;\r\n    public cb: (e: SpeechSynthesisResult) => void;\r\n    public err: (e: string) => void;\r\n    public dataStream: IAudioDestination;\r\n\r\n    constructor(requestId: string, text: string, isSSML: boolean, cb?: (e: SpeechSynthesisResult) => void, err?: (e: string) => void, dataStream?: IAudioDestination) {\r\n        this.requestId = requestId;\r\n        this.text = text;\r\n        this.isSSML = isSSML;\r\n        this.cb = cb;\r\n        this.err = err;\r\n        this.dataStream = dataStream;\r\n    }\r\n}\r\n"]}