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OAKG;;;;;;;IACQ,UAAU,EAAI,MAAM;IAc/B;;;;;;OAMG;IACI,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQ7C;;;;;;OAMG;aACQ,eAAe,EAAI,MAAM,EAAE;IAUtC;;;;;OAKG;;;;;;;;IACQ,SAAS,EAAI,MAAM;IAiB9B;;;;;;OAMG;aACQ,MAAM,EAAI,MAAM;IAIpB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IACxD,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI;IAQ7G;;;;;;;;OAQG;IACI,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM;IAItD;;;;;;;OAOG;IACI,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIrD;;;;;;OAMG;aACQ,UAAU,EAAI,kBAAkB;IAI3C;;;;;OAKG;IACI,KAAK,IAAI,IAAI;IAIb,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,GAAG,IAAI;IAQtF,YAAY,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI;IAI9C,kBAAkB,IAAI,IAAI;IAG1B,0BAA0B,IAAI,IAAI;IAGlC,eAAe,IAAI,IAAI;CAIjC","file":"SpeechTranslationConfig.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n    ForceDictationPropertyName,\n    OutputFormatPropertyName,\n    ServicePropertiesPropertyName\n} from \"../common.speech/Exports\";\nimport { IStringDictionary } from \"../common/Exports\";\nimport { Contracts } from \"./Contracts\";\nimport {\n    OutputFormat,\n    ProfanityOption,\n    PropertyCollection,\n    PropertyId,\n    ServicePropertyChannel,\n    SpeechConfig,\n} from \"./Exports\";\n\n/**\n * Speech translation configuration.\n * @class SpeechTranslationConfig\n */\nexport abstract class SpeechTranslationConfig extends SpeechConfig {\n\n    /**\n     * Creates an instance of recognizer config.\n     */\n    protected constructor() {\n        super();\n    }\n\n    /**\n     * Static instance of SpeechTranslationConfig returned by passing a subscription key and service region.\n     * @member SpeechTranslationConfig.fromSubscription\n     * @function\n     * @public\n     * @param {string} subscriptionKey - The subscription key.\n     * @param {string} region - The region name (see the <a href=\"https://aka.ms/csspeech/region\">region page</a>).\n     * @returns {SpeechTranslationConfig} The speech translation config.\n     */\n    public static fromSubscription(subscriptionKey: string, region: string): SpeechTranslationConfig {\n        Contracts.throwIfNullOrWhitespace(subscriptionKey, \"subscriptionKey\");\n        Contracts.throwIfNullOrWhitespace(region, \"region\");\n\n        const ret: SpeechTranslationConfigImpl = new SpeechTranslationConfigImpl();\n        ret.properties.setProperty(PropertyId.SpeechServiceConnection_Key, subscriptionKey);\n        ret.properties.setProperty(PropertyId.SpeechServiceConnection_Region, region);\n        return ret;\n    }\n\n    /**\n     * Static instance of SpeechTranslationConfig returned by passing authorization token and service region.\n     * Note: The caller needs to ensure that the authorization token is valid. Before the authorization token\n     *       expires, the caller needs to refresh it by setting the property authorizationToken with a new\n     *       valid token. Otherwise, all the recognizers created by this SpeechTranslationConfig instance\n     *       will encounter errors during recognition.\n     * As configuration values are copied when creating a new recognizer, the new token value will not apply\n     * to recognizers that have already been created.\n     * For recognizers that have been created before, you need to set authorization token of the corresponding recognizer\n     * to refresh the token. Otherwise, the recognizers will encounter errors during recognition.\n     * @member SpeechTranslationConfig.fromAuthorizationToken\n     * @function\n     * @public\n     * @param {string} authorizationToken - The authorization token.\n     * @param {string} region - The region name (see the <a href=\"https://aka.ms/csspeech/region\">region page</a>).\n     * @returns {SpeechTranslationConfig} The speech translation config.\n     */\n    public static fromAuthorizationToken(authorizationToken: string, region: string): SpeechTranslationConfig {\n        Contracts.throwIfNullOrWhitespace(authorizationToken, \"authorizationToken\");\n        Contracts.throwIfNullOrWhitespace(region, \"region\");\n\n        const ret: SpeechTranslationConfigImpl = new SpeechTranslationConfigImpl();\n        ret.properties.setProperty(PropertyId.SpeechServiceAuthorization_Token, authorizationToken);\n        ret.properties.setProperty(PropertyId.SpeechServiceConnection_Region, region);\n        return ret;\n    }\n\n    /**\n     * Creates an instance of the speech translation config with specified endpoint and subscription key.\n     * This method is intended only for users who use a non-standard service endpoint or paramters.\n     * Note: The query properties specified in the endpoint URL are not changed, even if they are\n     *       set by any other APIs. For example, if language is defined in the uri as query parameter\n     *       \"language=de-DE\", and also set by the speechRecognitionLanguage property, the language\n     *       setting in uri takes precedence, and the effective language is \"de-DE\".\n     * Only the properties that are not specified in the endpoint URL can be set by other APIs.\n     * Note: To use authorization token with fromEndpoint, pass an empty string to the subscriptionKey in the\n     *       fromEndpoint method, and then set authorizationToken=\"token\" on the created SpeechConfig instance to\n     *       use the authorization token.\n     * @member SpeechTranslationConfig.fromEndpoint\n     * @function\n     * @public\n     * @param {URL} endpoint - The service endpoint to connect to.\n     * @param {string} subscriptionKey - The subscription key.\n     * @returns {SpeechTranslationConfig} A speech config instance.\n     */\n    public static fromEndpoint(endpoint: URL, subscriptionKey: string): SpeechTranslationConfig {\n        Contracts.throwIfNull(endpoint, \"endpoint\");\n        Contracts.throwIfNull(subscriptionKey, \"subscriptionKey\");\n\n        const ret: SpeechTranslationConfigImpl = new SpeechTranslationConfigImpl();\n        ret.properties.setProperty(PropertyId.SpeechServiceConnection_Endpoint, endpoint.href);\n        ret.properties.setProperty(PropertyId.SpeechServiceConnection_Key, subscriptionKey);\n        return ret;\n    }\n\n    /**\n     * Gets/Sets the authorization token.\n     * Note: The caller needs to ensure that the authorization token is valid. Before the authorization token\n     * expires, the caller needs to refresh it by calling this setter with a new valid token.\n     * @member SpeechTranslationConfig.prototype.authorizationToken\n     * @function\n     * @public\n     * @param {string} value - The authorization token.\n     */\n    public abstract set authorizationToken(value: string);\n\n    /**\n     * Gets/Sets the speech recognition language.\n     * @member SpeechTranslationConfig.prototype.speechRecognitionLanguage\n     * @function\n     * @public\n     * @param {string} value - The authorization token.\n     */\n    public abstract set speechRecognitionLanguage(value: string);\n\n    /**\n     * Add a (text) target language to translate into.\n     * @member SpeechTranslationConfig.prototype.addTargetLanguage\n     * @function\n     * @public\n     * @param {string} value - The language such as de-DE\n     */\n    public abstract addTargetLanguage(value: string): void;\n\n    /**\n     * Gets the (text) target language to translate into.\n     * @member SpeechTranslationConfig.prototype.targetLanguages\n     * @function\n     * @public\n     * @param {string} value - The language such as de-DE\n     */\n    public abstract get targetLanguages(): string[];\n\n    /**\n     * Gets the selected voice name.\n     * @member SpeechTranslationConfig.prototype.voiceName\n     * @function\n     * @public\n     * @returns {string} The voice name.\n     */\n    public abstract get voiceName(): string;\n\n    /**\n     * Gets/Sets voice of the translated language, enable voice synthesis output.\n     * @member SpeechTranslationConfig.prototype.voiceName\n     * @function\n     * @public\n     * @param {string} value - The name of the voice.\n     */\n    public abstract set voiceName(value: string);\n\n    /**\n     * Sets a named property as value\n     * @member SpeechTranslationConfig.prototype.setProperty\n     * @function\n     * @public\n     * @param {string} name - The name of the property.\n     * @param {string} value - The value.\n     */\n    public abstract setProperty(name: string, value: string): void;\n\n    /**\n     * Dispose of associated resources.\n     * @member SpeechTranslationConfig.prototype.close\n     * @function\n     * @public\n     */\n    public abstract close(): void;\n}\n\n/**\n * @private\n * @class SpeechTranslationConfigImpl\n */\n// tslint:disable-next-line:max-classes-per-file\nexport class SpeechTranslationConfigImpl extends SpeechTranslationConfig {\n\n    private privSpeechProperties: PropertyCollection;\n\n    public constructor() {\n        super();\n        this.privSpeechProperties = new PropertyCollection();\n        this.outputFormat = OutputFormat.Simple;\n    }\n    /**\n     * Gets/Sets the authorization token.\n     * If this is set, subscription key is ignored.\n     * User needs to make sure the provided authorization token is valid and not expired.\n     * @member SpeechTranslationConfigImpl.prototype.authorizationToken\n     * @function\n     * @public\n     * @param {string} value - The authorization token.\n     */\n    public set authorizationToken(value: string) {\n        Contracts.throwIfNullOrWhitespace(value, \"value\");\n\n        this.privSpeechProperties.setProperty(PropertyId.SpeechServiceAuthorization_Token, value);\n    }\n\n    /**\n     * Gets/Sets the speech recognition language.\n     * @member SpeechTranslationConfigImpl.prototype.speechRecognitionLanguage\n     * @function\n     * @public\n     * @param {string} value - The authorization token.\n     */\n    public set speechRecognitionLanguage(value: string) {\n        Contracts.throwIfNullOrWhitespace(value, \"value\");\n        this.privSpeechProperties.setProperty(PropertyId.SpeechServiceConnection_RecoLanguage, value);\n    }\n\n    /**\n     * @member SpeechTranslationConfigImpl.prototype.subscriptionKey\n     * @function\n     * @public\n     */\n    public get subscriptionKey(): string {\n        return this.privSpeechProperties.getProperty(PropertyId[PropertyId.SpeechServiceConnection_Key]);\n    }\n\n    /**\n     * Gets the output format\n     * @member SpeechTranslationConfigImpl.prototype.outputFormat\n     * @function\n     * @public\n     */\n    public get outputFormat(): OutputFormat {\n        return (OutputFormat as any)[this.privSpeechProperties.getProperty(OutputFormatPropertyName, undefined)];\n    }\n\n    /**\n     * Gets/Sets the output format\n     * @member SpeechTranslationConfigImpl.prototype.outputFormat\n     * @function\n     * @public\n     */\n    public set outputFormat(value: OutputFormat) {\n        this.privSpeechProperties.setProperty(OutputFormatPropertyName, OutputFormat[value]);\n    }\n\n    /**\n     * Gets the endpoint id.\n     * @member SpeechTranslationConfigImpl.prototype.endpointId\n     * @function\n     * @public\n     */\n    public get endpointId(): string {\n        return this.privSpeechProperties.getProperty(PropertyId.SpeechServiceConnection_EndpointId);\n    }\n\n    /**\n     * Gets/Sets the endpoint id.\n     * @member SpeechTranslationConfigImpl.prototype.endpointId\n     * @function\n     * @public\n     */\n    public set endpointId(value: string) {\n        this.privSpeechProperties.setProperty(PropertyId.SpeechServiceConnection_Endpoint, value);\n    }\n\n    /**\n     * Add a (text) target language to translate into.\n     * @member SpeechTranslationConfigImpl.prototype.addTargetLanguage\n     * @function\n     * @public\n     * @param {string} value - The language such as de-DE\n     */\n    public addTargetLanguage(value: string): void {\n        Contracts.throwIfNullOrWhitespace(value, \"value\");\n\n        const languages: string[] = this.targetLanguages;\n        languages.push(value);\n        this.privSpeechProperties.setProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages, languages.join(\",\"));\n    }\n\n    /**\n     * Gets the (text) target language to translate into.\n     * @member SpeechTranslationConfigImpl.prototype.targetLanguages\n     * @function\n     * @public\n     * @param {string} value - The language such as de-DE\n     */\n    public get targetLanguages(): string[] {\n\n        if (this.privSpeechProperties.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages, undefined) !== undefined) {\n            return this.privSpeechProperties.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages).split(\",\");\n        } else {\n            return [];\n        }\n\n    }\n\n    /**\n     * Gets the voice name.\n     * @member SpeechTranslationConfigImpl.prototype.voiceName\n     * @function\n     * @public\n     */\n    public get voiceName(): string {\n        return this.getProperty(PropertyId[PropertyId.SpeechServiceConnection_TranslationVoice]);\n    }\n\n    /**\n     * Gets/Sets the voice of the translated language, enable voice synthesis output.\n     * @member SpeechTranslationConfigImpl.prototype.voiceName\n     * @function\n     * @public\n     * @param {string} value - The name of the voice.\n     */\n    public set voiceName(value: string) {\n        Contracts.throwIfNullOrWhitespace(value, \"value\");\n\n        this.privSpeechProperties.setProperty(PropertyId.SpeechServiceConnection_TranslationVoice, value);\n    }\n\n    /**\n     * Provides the region.\n     * @member SpeechTranslationConfigImpl.prototype.region\n     * @function\n     * @public\n     * @returns {string} The region.\n     */\n    public get region(): string {\n        return this.privSpeechProperties.getProperty(PropertyId.SpeechServiceConnection_Region);\n    }\n\n    public setProxy(proxyHostName: string, proxyPort: number): void;\n    public setProxy(proxyHostName: string, proxyPort: number, proxyUserName: string, proxyPassword: string): void;\n    public setProxy(proxyHostName: any, proxyPort: any, proxyUserName?: any, proxyPassword?: any): void {\n        this.setProperty(PropertyId[PropertyId.SpeechServiceConnection_ProxyHostName], proxyHostName);\n        this.setProperty(PropertyId[PropertyId.SpeechServiceConnection_ProxyPort], proxyPort);\n        this.setProperty(PropertyId[PropertyId.SpeechServiceConnection_ProxyUserName], proxyUserName);\n        this.setProperty(PropertyId[PropertyId.SpeechServiceConnection_ProxyPassword], proxyPassword);\n    }\n\n    /**\n     * Gets an arbitrary property value.\n     * @member SpeechTranslationConfigImpl.prototype.getProperty\n     * @function\n     * @public\n     * @param {string} name - The name of the property.\n     * @param {string} def - The default value of the property in case it is not set.\n     * @returns {string} The value of the property.\n     */\n    public getProperty(name: string, def?: string): string {\n        return this.privSpeechProperties.getProperty(name, def);\n    }\n\n    /**\n     * Gets/Sets an arbitrary property value.\n     * @member SpeechTranslationConfigImpl.prototype.setProperty\n     * @function\n     * @public\n     * @param {string} name - The name of the property.\n     * @param {string} value - The value of the property.\n     */\n    public setProperty(name: string, value: string): void {\n        this.privSpeechProperties.setProperty(name, value);\n    }\n\n    /**\n     * Provides access to custom properties.\n     * @member SpeechTranslationConfigImpl.prototype.properties\n     * @function\n     * @public\n     * @returns {PropertyCollection} The properties.\n     */\n    public get properties(): PropertyCollection {\n        return this.privSpeechProperties;\n    }\n\n    /**\n     * Dispose of associated resources.\n     * @member SpeechTranslationConfigImpl.prototype.close\n     * @function\n     * @public\n     */\n    public close(): void {\n        return;\n    }\n\n    public setServiceProperty(name: string, value: string, channel: ServicePropertyChannel): void {\n        const currentProperties: IStringDictionary<string> = JSON.parse(this.privSpeechProperties.getProperty(ServicePropertiesPropertyName, \"{}\"));\n\n        currentProperties[name] = value;\n\n        this.privSpeechProperties.setProperty(ServicePropertiesPropertyName, JSON.stringify(currentProperties));\n    }\n\n    public setProfanity(profanity: ProfanityOption): void {\n        this.privSpeechProperties.setProperty(PropertyId.SpeechServiceResponse_ProfanityOption, ProfanityOption[profanity]);\n    }\n\n    public enableAudioLogging(): void {\n        this.privSpeechProperties.setProperty(PropertyId.SpeechServiceConnection_EnableAudioLogging, \"true\");\n    }\n    public requestWordLevelTimestamps(): void {\n        this.privSpeechProperties.setProperty(PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, \"true\");\n    }\n    public enableDictation(): void {\n        this.privSpeechProperties.setProperty(ForceDictationPropertyName, \"true\");\n    }\n\n}\n"]}