UNPKG

microsoft-cognitiveservices-speech-sdk

Version:
1 lines 4.32 kB
{"version":3,"sources":["src/common.speech/ConnectionFactoryBase.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG9E,8BAAsB,qBAAsB,YAAW,kBAAkB;WAEvD,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;aAYnC,MAAM,CAClB,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW;IAEvC,SAAS,CAAC,kBAAkB,CACxB,MAAM,EAAE,gBAAgB,EACxB,WAAW,EAAE,iBAAiB,CAAC,MAAM,CAAC,EACtC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAyB3B,SAAS,CAAC,eAAe,CACrB,MAAM,EAAE,UAAU,EAClB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,gBAAgB,EACxB,WAAW,EAAE,iBAAiB,CAAC,MAAM,CAAC,EACtC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAW9B","file":"ConnectionFactoryBase.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n ServicePropertiesPropertyName,\r\n} from \"../common.speech/Exports.js\";\r\nimport { IConnection, IStringDictionary } from \"../common/Exports.js\";\r\nimport { PropertyId } from \"../sdk/Exports.js\";\r\nimport { AuthInfo, IConnectionFactory, RecognizerConfig } from \"./Exports.js\";\r\nimport { QueryParameterNames } from \"./QueryParameterNames.js\";\r\n\r\nexport abstract class ConnectionFactoryBase implements IConnectionFactory {\r\n\r\n public static getHostSuffix(region: string): string {\r\n if (!!region) {\r\n if (region.toLowerCase().startsWith(\"china\")) {\r\n return \".azure.cn\";\r\n }\r\n if (region.toLowerCase().startsWith(\"usgov\")) {\r\n return \".azure.us\";\r\n }\r\n }\r\n return \".microsoft.com\";\r\n }\r\n\r\n public abstract create(\r\n config: RecognizerConfig,\r\n authInfo: AuthInfo,\r\n connectionId?: string): IConnection;\r\n\r\n protected setCommonUrlParams(\r\n config: RecognizerConfig,\r\n queryParams: IStringDictionary<string>,\r\n endpoint: string): void {\r\n\r\n const propertyIdToParameterMap: Map<number, string> = new Map([\r\n [PropertyId.Speech_SegmentationSilenceTimeoutMs, QueryParameterNames.SegmentationSilenceTimeoutMs],\r\n [PropertyId.SpeechServiceConnection_EnableAudioLogging, QueryParameterNames.EnableAudioLogging],\r\n [PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, QueryParameterNames.EndSilenceTimeoutMs],\r\n [PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, QueryParameterNames.InitialSilenceTimeoutMs],\r\n [PropertyId.SpeechServiceResponse_PostProcessingOption, QueryParameterNames.Postprocessing],\r\n [PropertyId.SpeechServiceResponse_ProfanityOption, QueryParameterNames.Profanity],\r\n [PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, QueryParameterNames.EnableWordLevelTimestamps],\r\n [PropertyId.SpeechServiceResponse_StablePartialResultThreshold, QueryParameterNames.StableIntermediateThreshold],\r\n ]);\r\n\r\n propertyIdToParameterMap.forEach((parameterName: string, propertyId: PropertyId): void => {\r\n this.setUrlParameter(propertyId, parameterName, config, queryParams, endpoint);\r\n });\r\n\r\n\r\n const serviceProperties: IStringDictionary<string> = JSON.parse(config.parameters.getProperty(ServicePropertiesPropertyName, \"{}\")) as IStringDictionary<string>;\r\n\r\n Object.keys(serviceProperties).forEach((value: string): void => {\r\n queryParams[value] = serviceProperties[value];\r\n });\r\n }\r\n\r\n protected setUrlParameter(\r\n propId: PropertyId,\r\n parameterName: string,\r\n config: RecognizerConfig,\r\n queryParams: IStringDictionary<string>,\r\n endpoint: string): void {\r\n\r\n const value: string = config.parameters.getProperty(propId, undefined);\r\n\r\n // FIXME: The .search() check will incorrectly match parameter name anywhere in the string\r\n // including e.g. the path portion, or even as a substring of other query parameters\r\n if (value && (!endpoint || endpoint.search(parameterName) === -1)) {\r\n queryParams[parameterName] = value.toLocaleLowerCase();\r\n }\r\n }\r\n\r\n}\r\n"]}