microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 5.99 kB
Source Map (JSON)
{"version":3,"sources":["src/common.speech/ConversationTranscriberConnectionFactory.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,WAAW,EACX,iBAAiB,EACpB,MAAM,sBAAsB,CAAC;AAO9B,OAAO,EACH,qBAAqB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACH,QAAQ,EACR,gBAAgB,EAEnB,MAAM,cAAc,CAAC;AAMtB,qBAAa,wCAAyC,SAAQ,qBAAqB;IAC/E,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;IAExD,MAAM,CACT,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW;IAgDvC,SAAS,CAAC,cAAc,CACpB,MAAM,EAAE,gBAAgB,EACxB,WAAW,EAAE,iBAAiB,CAAC,MAAM,CAAC,EACtC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAuB9B","file":"ConversationTranscriberConnectionFactory.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n ProxyInfo,\r\n WebsocketConnection,\r\n} from \"../common.browser/Exports.js\";\r\nimport {\r\n IConnection,\r\n IStringDictionary\r\n} from \"../common/Exports.js\";\r\nimport {\r\n PropertyId\r\n} from \"../sdk/Exports.js\";\r\nimport {\r\n ServicePropertiesPropertyName\r\n} from \"../common.speech/Exports.js\";\r\nimport {\r\n ConnectionFactoryBase\r\n} from \"./ConnectionFactoryBase.js\";\r\nimport {\r\n AuthInfo,\r\n RecognizerConfig,\r\n WebsocketMessageFormatter\r\n} from \"./Exports.js\";\r\nimport { HeaderNames } from \"./HeaderNames.js\";\r\nimport {\r\n QueryParameterNames\r\n} from \"./QueryParameterNames.js\";\r\n\r\nexport class ConversationTranscriberConnectionFactory extends ConnectionFactoryBase {\r\n private readonly universalUri: string = \"/speech/universal/v2\";\r\n\r\n public create(\r\n config: RecognizerConfig,\r\n authInfo: AuthInfo,\r\n connectionId?: string): IConnection {\r\n\r\n let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);\r\n const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);\r\n const hostSuffix: string = ConnectionFactoryBase.getHostSuffix(region);\r\n const host: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, \"wss://\" + region + \".stt.speech\" + hostSuffix);\r\n const queryParams: IStringDictionary<string> = {};\r\n const endpointId: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_EndpointId, undefined);\r\n const language: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage, undefined);\r\n\r\n if (endpointId) {\r\n if (!endpoint || endpoint.search(QueryParameterNames.CustomSpeechDeploymentId) === -1) {\r\n queryParams[QueryParameterNames.CustomSpeechDeploymentId] = endpointId;\r\n }\r\n } else if (language) {\r\n if (!endpoint || endpoint.search(QueryParameterNames.Language) === -1) {\r\n queryParams[QueryParameterNames.Language] = language;\r\n }\r\n }\r\n\r\n if (config.autoDetectSourceLanguages !== undefined) {\r\n queryParams[QueryParameterNames.EnableLanguageId] = \"true\";\r\n }\r\n\r\n this.setV2UrlParams(config, queryParams, endpoint);\r\n\r\n if (!endpoint) {\r\n endpoint = `${host}${this.universalUri}`;\r\n }\r\n\r\n const headers: IStringDictionary<string> = {};\r\n if (authInfo.token !== undefined && authInfo.token !== \"\") {\r\n headers[authInfo.headerName] = authInfo.token;\r\n }\r\n headers[HeaderNames.ConnectionId] = connectionId;\r\n\r\n const enableCompression: boolean = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\r\n\r\n const webSocketConnection = new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\r\n\r\n // Set the value of SpeechServiceConnection_Url to webSocketConnection.uri (and not to `endpoint`), since this value is the final\r\n // URI that was used to make the connection (including query parameters).\r\n const uri: string = webSocketConnection.uri;\r\n config.parameters.setProperty(PropertyId.SpeechServiceConnection_Url, uri);\r\n\r\n return webSocketConnection;\r\n }\r\n\r\n protected setV2UrlParams(\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_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"]}