@euirim/microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 18.5 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/SpeechConfig.ts"],"names":[],"mappings":"AAUA,OAAO,EACH,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,sBAAsB,EACzB,MAAM,WAAW,CAAC;AAEnB;;;GAGG;AACH,8BAAsB,YAAY;IAC9B;;;OAGG;IACH,SAAS;IAET;;;;;;;;;OASG;WACW,gBAAgB,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY;IAYrF;;;;;;;;;;;;;;;;;;OAkBG;WACW,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,YAAY;IAYjF;;;;;;;;;;;;;;;OAeG;WACW,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY;IAW9F;;;;;;OAMG;aACa,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAExE;;;;;;;;OAQG;aACa,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI;IAEtH;;;;;OAKG;;;;;;;;;;aACiB,kBAAkB,EAAI,MAAM;IAahD;;;;;OAKG;;;;;;;;aACiB,yBAAyB,EAAI,MAAM;IAWvD;;;;;;;OAOG;aACa,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAE9D;;;;;;;;OAQG;aACa,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM;IAE/D;;;;;;OAMG;;;;;;;aACiB,YAAY,EAAI,YAAY;IAUhD;;;;;;OAMG;;;;;;;;aACiB,UAAU,E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;IAQtF,YAAY,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI;IAI9C,kBAAkB,IAAI,IAAI;IAG1B,0BAA0B,IAAI,IAAI;IAGlC,eAAe,IAAI,IAAI;IAIvB,KAAK,IAAI,gBAAgB;CAKnC","file":"SpeechConfig.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} from \"./Exports\";\n\n/**\n * Speech configuration.\n * @class SpeechConfig\n */\nexport abstract class SpeechConfig {\n /**\n * Creates and initializes an instance.\n * @constructor\n */\n protected constructor() { }\n\n /**\n * Static instance of SpeechConfig returned by passing subscriptionKey and service region.\n * Note: Please use your LanguageUnderstanding subscription key in case you want to use the Intent recognizer.\n * @member SpeechConfig.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 {SpeechConfig} The speech factory\n */\n public static fromSubscription(subscriptionKey: string, region: string): SpeechConfig {\n Contracts.throwIfNullOrWhitespace(subscriptionKey, \"subscriptionKey\");\n Contracts.throwIfNullOrWhitespace(region, \"region\");\n\n const speechImpl: SpeechConfigImpl = new SpeechConfigImpl();\n speechImpl.setProperty(PropertyId.SpeechServiceConnection_Region, region);\n speechImpl.setProperty(PropertyId.SpeechServiceConnection_IntentRegion, region);\n speechImpl.setProperty(PropertyId.SpeechServiceConnection_Key, subscriptionKey);\n\n return speechImpl;\n }\n\n /**\n * Creates an instance of the speech config with specified endpoint and subscription key.\n * This method is intended only for users who use a non-standard service endpoint or parameters.\n * Note: Please use your LanguageUnderstanding subscription key in case you want to use the Intent recognizer.\n * Note: The query parameters specified in the endpoint URL are not changed, even if they are set by any other APIs.\n * For example, if language is defined in the uri as query parameter \"language=de-DE\", and also set by\n * SpeechConfig.speechRecognitionLanguage = \"en-US\", the language setting in uri takes precedence,\n * and the effective language is \"de-DE\". Only the parameters that are not specified in the\n * 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 SpeechConfig.fromEndpoint\n * @function\n * @public\n * @param {URL} endpoint - The service endpoint to connect to.\n * @param {string} subscriptionKey - The subscription key. If a subscription key is not specified, an authorization token must be set.\n * @returns {SpeechConfig} A speech factory instance.\n */\n public static fromEndpoint(endpoint: URL, subscriptionKey?: string): SpeechConfig {\n Contracts.throwIfNull(endpoint, \"endpoint\");\n\n const speechImpl: SpeechConfigImpl = new SpeechConfigImpl();\n speechImpl.setProperty(PropertyId.SpeechServiceConnection_Endpoint, endpoint.href);\n\n if (undefined !== subscriptionKey) {\n speechImpl.setProperty(PropertyId.SpeechServiceConnection_Key, subscriptionKey);\n }\n return speechImpl;\n }\n\n /**\n * Creates an instance of the speech factory with specified initial authorization token and 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 calling this setter with a new valid token.\n * Note: Please use a token derived from your LanguageUnderstanding subscription key in case you want\n * to use the Intent recognizer. As configuration values are copied when creating a new recognizer,\n * the new token value will not apply to recognizers that have already been created. For recognizers\n * 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 SpeechConfig.fromAuthorizationToken\n * @function\n * @public\n * @param {string} authorizationToken - The initial authorization token.\n * @param {string} region - The region name (see the <a href=\"https://aka.ms/csspeech/region\">region page</a>).\n * @returns {SpeechConfig} A speech factory instance.\n */\n public static fromAuthorizationToken(authorizationToken: string, region: string): SpeechConfig {\n Contracts.throwIfNull(authorizationToken, \"authorizationToken\");\n Contracts.throwIfNullOrWhitespace(region, \"region\");\n\n const speechImpl: SpeechConfigImpl = new SpeechConfigImpl();\n speechImpl.setProperty(PropertyId.SpeechServiceConnection_Region, region);\n speechImpl.setProperty(PropertyId.SpeechServiceConnection_IntentRegion, region);\n speechImpl.authorizationToken = authorizationToken;\n return speechImpl;\n }\n\n /**\n * Sets the proxy configuration.\n * Only relevant in Node.js environments.\n * Added in version 1.4.0.\n * @param proxyHostName The host name of the proxy server.\n * @param proxyPort The port number of the proxy server.\n */\n public abstract setProxy(proxyHostName: string, proxyPort: number): void;\n\n /**\n * Sets the proxy configuration.\n * Only relevant in Node.js environments.\n * Added in version 1.4.0.\n * @param proxyHostName The host name of the proxy server, without the protocol scheme (http://)\n * @param porxyPort The port number of the proxy server.\n * @param proxyUserName The user name of the proxy server.\n * @param proxyPassword The password of the proxy server.\n */\n public abstract setProxy(proxyHostName: string, proxyPort: number, proxyUserName: string, proxyPassword: string): void;\n\n /**\n * Gets the authorization token.\n * @member SpeechConfig.prototype.authorizationToken\n * @function\n * @public\n */\n public abstract get authorizationToken(): string;\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 SpeechConfig.prototype.authorizationToken\n * @function\n * @public\n * @param {string} value - The authorization token.\n */\n public abstract set authorizationToken(value: string);\n\n /**\n * Returns the configured language.\n * @member SpeechConfig.prototype.speechRecognitionLanguage\n * @function\n * @public\n */\n public abstract get speechRecognitionLanguage(): string;\n\n /**\n * Gets/Sets the input language.\n * @member SpeechConfig.prototype.speechRecognitionLanguage\n * @function\n * @public\n * @param {string} value - The authorization token.\n */\n public abstract set speechRecognitionLanguage(value: string);\n\n /**\n * Sets an arbitrary property.\n * @member SpeechConfig.prototype.setProperty\n * @function\n * @public\n * @param {string} name - The name of the property to set.\n * @param {string} value - The new value of the property.\n */\n public abstract setProperty(name: string, value: string): void;\n\n /**\n * Returns the current value of an arbitrary property.\n * @member SpeechConfig.prototype.getProperty\n * @function\n * @public\n * @param {string} name - The name of the property to query.\n * @param {string} def - The value to return in case the property is not known.\n * @returns {string} The current value, or provided default, of the given property.\n */\n public abstract getProperty(name: string, def?: string): string;\n\n /**\n * Gets output format.\n * @member SpeechConfig.prototype.outputFormat\n * @function\n * @public\n * @returns {OutputFormat} Returns the output format.\n */\n public abstract get outputFormat(): OutputFormat;\n\n /**\n * Gets/Sets the output format.\n * @member SpeechConfig.prototype.outputFormat\n * @function\n * @public\n */\n public abstract set outputFormat(format: OutputFormat);\n\n /**\n * Gets the endpoint ID of a customized speech model that is used for speech recognition.\n * @member SpeechConfig.prototype.endpointId\n * @function\n * @public\n * @return {string} The endpoint ID\n */\n public abstract get endpointId(): string;\n\n /**\n * Gets/Sets the endpoint ID of a customized speech model that is used for speech recognition.\n * @member SpeechConfig.prototype.endpointId\n * @function\n * @public\n * @param {string} value - The endpoint ID\n */\n public abstract set endpointId(value: string);\n\n /**\n * Closes the configuration.\n * @member SpeechConfig.prototype.close\n * @function\n * @public\n */\n /* tslint:disable:no-empty */\n public close(): void { }\n\n /**\n * @member SpeechConfig.prototype.subscriptionKey\n * @function\n * @public\n * @return {SubscriptionKey} The subscription key set on the config.\n */\n public abstract get subscriptionKey(): string;\n\n /**\n * @member SpeechConfig.prototype.region\n * @function\n * @public\n * @return {region} The region set on the config.\n */\n public abstract get region(): string;\n\n /**\n * @member SpeechConfig.prototype.setServiceProperty\n * @function\n * @public\n * @param {name} The name of the property.\n * @param {value} Value to set.\n * @param {channel} The channel used to pass the specified property to service.\n * @summary Sets a property value that will be passed to service using the specified channel.\n * Added in version 1.7.0.\n */\n public abstract setServiceProperty(name: string, value: string, channel: ServicePropertyChannel): void;\n\n /**\n * @member SpeechConfig.prototype.setProfanity\n * @function\n * @public\n * @param {profanity} Profanity option to set.\n * @summary Sets profanity option.\n * Added in version 1.7.0.\n */\n public abstract setProfanity(profanity: ProfanityOption): void;\n\n /**\n * @member SpeechConfig.prototype.enableAudioLogging\n * @function\n * @public\n * @summary Enable audio logging in service.\n * Added in version 1.7.0.\n */\n public abstract enableAudioLogging(): void;\n\n /**\n * @member SpeechConfig.prototype.requestWordLevelTimestamps\n * @function\n * @public\n * @summary Includes word-level timestamps.\n * Added in version 1.7.0.\n */\n public abstract requestWordLevelTimestamps(): void;\n\n /**\n * @member SpeechConfig.prototype.enableDictation\n * @function\n * @public\n * @summary Enable dictation. Only supported in speech continuous recognition.\n * Added in version 1.7.0.\n */\n public abstract enableDictation(): void;\n}\n\n/**\n * @public\n * @class SpeechConfigImpl\n */\n// tslint:disable-next-line:max-classes-per-file\nexport class SpeechConfigImpl extends SpeechConfig {\n\n private privProperties: PropertyCollection;\n\n public constructor() {\n super();\n this.privProperties = new PropertyCollection();\n this.speechRecognitionLanguage = \"en-US\"; // Should we have a default?\n this.outputFormat = OutputFormat.Simple;\n }\n\n public get properties(): PropertyCollection {\n return this.privProperties;\n }\n\n public get endPoint(): URL {\n return new URL(this.privProperties.getProperty(PropertyId.SpeechServiceConnection_Endpoint));\n }\n\n public get subscriptionKey(): string {\n return this.privProperties.getProperty(PropertyId.SpeechServiceConnection_Key);\n }\n\n public get region(): string {\n return this.privProperties.getProperty(PropertyId.SpeechServiceConnection_Region);\n }\n\n public get authorizationToken(): string {\n return this.privProperties.getProperty(PropertyId.SpeechServiceAuthorization_Token);\n }\n\n public set authorizationToken(value: string) {\n this.privProperties.setProperty(PropertyId.SpeechServiceAuthorization_Token, value);\n }\n\n public get speechRecognitionLanguage(): string {\n return this.privProperties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);\n }\n\n public set speechRecognitionLanguage(value: string) {\n this.privProperties.setProperty(PropertyId.SpeechServiceConnection_RecoLanguage, value);\n }\n\n public get outputFormat(): OutputFormat {\n return (OutputFormat as any)[this.privProperties.getProperty(OutputFormatPropertyName, undefined)];\n }\n\n public set outputFormat(value: OutputFormat) {\n this.privProperties.setProperty(OutputFormatPropertyName, OutputFormat[value]);\n }\n\n public get endpointId(): string {\n return this.privProperties.getProperty(PropertyId.SpeechServiceConnection_EndpointId);\n }\n\n public set endpointId(value: string) {\n this.privProperties.setProperty(PropertyId.SpeechServiceConnection_EndpointId, value);\n }\n\n public setProperty(name: string | PropertyId, value: string): void {\n Contracts.throwIfNull(value, \"value\");\n\n this.privProperties.setProperty(name, value);\n }\n\n public getProperty(name: string | PropertyId, def?: string): string {\n\n return this.privProperties.getProperty(name, def);\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 public setServiceProperty(name: string, value: string, channel: ServicePropertyChannel): void {\n const currentProperties: IStringDictionary<string> = JSON.parse( this.privProperties.getProperty(ServicePropertiesPropertyName, \"{}\"));\n\n currentProperties[name] = value;\n\n this.privProperties.setProperty(ServicePropertiesPropertyName, JSON.stringify(currentProperties));\n }\n\n public setProfanity(profanity: ProfanityOption): void {\n this.privProperties.setProperty(PropertyId.SpeechServiceResponse_ProfanityOption, ProfanityOption[profanity]);\n }\n\n public enableAudioLogging(): void {\n this.privProperties.setProperty(PropertyId.SpeechServiceConnection_EnableAudioLogging, \"true\");\n }\n public requestWordLevelTimestamps(): void {\n this.privProperties.setProperty(PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, \"true\");\n }\n public enableDictation(): void {\n this.privProperties.setProperty(ForceDictationPropertyName, \"true\");\n }\n\n public clone(): SpeechConfigImpl {\n const ret: SpeechConfigImpl = new SpeechConfigImpl();\n ret.privProperties = this.privProperties.clone();\n return ret;\n }\n}\n"]}