UNPKG

microsoft-cognitiveservices-speech-sdk

Version:
1 lines 4.49 kB
{"version":3,"sources":["src/common.speech/TranscriberConnectionFactory.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,WAAW,EACX,iBAAiB,EACpB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EACH,qBAAqB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACH,QAAQ,EAER,gBAAgB,EAEnB,MAAM,cAAc,CAAC;AAMtB,qBAAa,4BAA6B,SAAQ,qBAAqB;IAEnE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAA4C;IAE3E,MAAM,CACT,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW;IA2BhC,cAAc,CAAC,WAAW,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;CAqBrH","file":"TranscriberConnectionFactory.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 OutputFormat,\r\n PropertyId\r\n} from \"../sdk/Exports.js\";\r\nimport {\r\n ConnectionFactoryBase\r\n} from \"./ConnectionFactoryBase.js\";\r\nimport {\r\n AuthInfo,\r\n OutputFormatPropertyName,\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 TranscriberConnectionFactory extends ConnectionFactoryBase {\r\n\r\n private readonly multiaudioRelativeUri: string = \"/speech/recognition/multiaudio\";\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, \"centralus\");\r\n const hostSuffix: string = ConnectionFactoryBase.getHostSuffix(region);\r\n const hostDefault: string = \"wss://transcribe.\" + region + \".cts.speech\" + hostSuffix + this.multiaudioRelativeUri;\r\n const host: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, hostDefault);\r\n\r\n const queryParams: IStringDictionary<string> = {};\r\n this.setQueryParams(queryParams, config, endpoint);\r\n\r\n if (!endpoint) {\r\n endpoint = host;\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 config.parameters.setProperty(PropertyId.SpeechServiceConnection_Url, endpoint);\r\n\r\n const enableCompression: boolean = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\r\n return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\r\n }\r\n\r\n public setQueryParams(queryParams: IStringDictionary<string>, config: RecognizerConfig, endpointUrl: string): void {\r\n\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 && !(QueryParameterNames.CustomSpeechDeploymentId in queryParams)) {\r\n queryParams[QueryParameterNames.CustomSpeechDeploymentId] = endpointId;\r\n }\r\n\r\n if (language && !(QueryParameterNames.Language in queryParams)) {\r\n queryParams[QueryParameterNames.Language] = language;\r\n }\r\n\r\n const wordLevelTimings: boolean = config.parameters.getProperty(PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, \"false\").toLowerCase() === \"true\";\r\n const detailed: boolean = config.parameters.getProperty(OutputFormatPropertyName, OutputFormat[OutputFormat.Simple]) !== OutputFormat[OutputFormat.Simple];\r\n if (wordLevelTimings || detailed) {\r\n queryParams[QueryParameterNames.Format] = OutputFormat[OutputFormat.Detailed].toLowerCase();\r\n }\r\n\r\n this.setCommonUrlParams(config, queryParams, endpointUrl);\r\n }\r\n}\r\n"]}