1 |
- {"ast":null,"code":"\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.SpeechConnectionFactory = void 0;\nconst Exports_js_1 = require(\"../common.browser/Exports.js\");\nconst Exports_js_2 = require(\"../common.speech/Exports.js\");\nconst Exports_js_3 = require(\"../sdk/Exports.js\");\nconst ConnectionFactoryBase_js_1 = require(\"./ConnectionFactoryBase.js\");\nconst Exports_js_4 = require(\"./Exports.js\");\nconst HeaderNames_js_1 = require(\"./HeaderNames.js\");\nconst QueryParameterNames_js_1 = require(\"./QueryParameterNames.js\");\nclass SpeechConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {\n constructor() {\n super(...arguments);\n this.interactiveRelativeUri = \"/speech/recognition/interactive/cognitiveservices/v1\";\n this.conversationRelativeUri = \"/speech/recognition/conversation/cognitiveservices/v1\";\n this.dictationRelativeUri = \"/speech/recognition/dictation/cognitiveservices/v1\";\n this.universalUri = \"/speech/universal/v\";\n }\n create(config, authInfo, connectionId) {\n let endpoint = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Endpoint, undefined);\n const region = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Region, undefined);\n const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);\n const host = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Host, \"wss://\" + region + \".stt.speech\" + hostSuffix);\n const queryParams = {};\n const endpointId = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_EndpointId, undefined);\n const language = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage, undefined);\n if (endpointId) {\n if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId) === -1) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId] = endpointId;\n }\n } else if (language) {\n if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.Language) === -1) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.Language] = language;\n }\n }\n if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.Format) === -1) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.Format] = config.parameters.getProperty(Exports_js_2.OutputFormatPropertyName, Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]).toLowerCase();\n }\n if (config.autoDetectSourceLanguages !== undefined) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.EnableLanguageId] = \"true\";\n }\n this.setCommonUrlParams(config, queryParams, endpoint);\n if (!endpoint) {\n switch (config.recognitionMode) {\n case Exports_js_4.RecognitionMode.Conversation:\n if (config.parameters.getProperty(Exports_js_2.ForceDictationPropertyName, \"false\") === \"true\") {\n endpoint = host + this.dictationRelativeUri;\n } else {\n if (config.recognitionEndpointVersion !== undefined && parseInt(config.recognitionEndpointVersion, 10) > 1) {\n endpoint = `${host}${this.universalUri}${config.recognitionEndpointVersion}`;\n } else {\n endpoint = host + this.conversationRelativeUri;\n }\n }\n break;\n case Exports_js_4.RecognitionMode.Dictation:\n endpoint = host + this.dictationRelativeUri;\n break;\n default:\n if (config.recognitionEndpointVersion !== undefined && parseInt(config.recognitionEndpointVersion, 10) > 1) {\n endpoint = `${host}${this.universalUri}${config.recognitionEndpointVersion}`;\n } else {\n endpoint = host + this.interactiveRelativeUri; // default is interactive\n }\n break;\n }\n }\n const headers = {};\n if (authInfo.token !== undefined && authInfo.token !== \"\") {\n headers[authInfo.headerName] = authInfo.token;\n }\n headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;\n const enableCompression = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\n const webSocketConnection = new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_4.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\n // Set the value of SpeechServiceConnection_Url to webSocketConnection.uri (and not to `endpoint`), since this value is the final\n // URI that was used to make the connection (including query parameters).\n const uri = webSocketConnection.uri;\n config.parameters.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Url, uri);\n return webSocketConnection;\n }\n}\nexports.SpeechConnectionFactory = SpeechConnectionFactory;","map":{"version":3,"names":["Object","defineProperty","exports","value","SpeechConnectionFactory","Exports_js_1","require","Exports_js_2","Exports_js_3","ConnectionFactoryBase_js_1","Exports_js_4","HeaderNames_js_1","QueryParameterNames_js_1","ConnectionFactoryBase","constructor","arguments","interactiveRelativeUri","conversationRelativeUri","dictationRelativeUri","universalUri","create","config","authInfo","connectionId","endpoint","parameters","getProperty","PropertyId","SpeechServiceConnection_Endpoint","undefined","region","SpeechServiceConnection_Region","hostSuffix","getHostSuffix","host","SpeechServiceConnection_Host","queryParams","endpointId","SpeechServiceConnection_EndpointId","language","SpeechServiceConnection_RecoLanguage","search","QueryParameterNames","CustomSpeechDeploymentId","Language","Format","OutputFormatPropertyName","OutputFormat","Simple","toLowerCase","autoDetectSourceLanguages","EnableLanguageId","setCommonUrlParams","recognitionMode","RecognitionMode","Conversation","ForceDictationPropertyName","recognitionEndpointVersion","parseInt","Dictation","headers","token","headerName","HeaderNames","ConnectionId","enableCompression","webSocketConnection","WebsocketConnection","WebsocketMessageFormatter","ProxyInfo","fromRecognizerConfig","uri","setProperty","SpeechServiceConnection_Url"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common.speech/SpeechConnectionFactory.js"],"sourcesContent":["\"use strict\";\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.SpeechConnectionFactory = void 0;\nconst Exports_js_1 = require(\"../common.browser/Exports.js\");\nconst Exports_js_2 = require(\"../common.speech/Exports.js\");\nconst Exports_js_3 = require(\"../sdk/Exports.js\");\nconst ConnectionFactoryBase_js_1 = require(\"./ConnectionFactoryBase.js\");\nconst Exports_js_4 = require(\"./Exports.js\");\nconst HeaderNames_js_1 = require(\"./HeaderNames.js\");\nconst QueryParameterNames_js_1 = require(\"./QueryParameterNames.js\");\nclass SpeechConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {\n constructor() {\n super(...arguments);\n this.interactiveRelativeUri = \"/speech/recognition/interactive/cognitiveservices/v1\";\n this.conversationRelativeUri = \"/speech/recognition/conversation/cognitiveservices/v1\";\n this.dictationRelativeUri = \"/speech/recognition/dictation/cognitiveservices/v1\";\n this.universalUri = \"/speech/universal/v\";\n }\n create(config, authInfo, connectionId) {\n let endpoint = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Endpoint, undefined);\n const region = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Region, undefined);\n const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);\n const host = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Host, \"wss://\" + region + \".stt.speech\" + hostSuffix);\n const queryParams = {};\n const endpointId = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_EndpointId, undefined);\n const language = config.parameters.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_RecoLanguage, undefined);\n if (endpointId) {\n if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId) === -1) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.CustomSpeechDeploymentId] = endpointId;\n }\n }\n else if (language) {\n if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.Language) === -1) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.Language] = language;\n }\n }\n if (!endpoint || endpoint.search(QueryParameterNames_js_1.QueryParameterNames.Format) === -1) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.Format] = config.parameters.getProperty(Exports_js_2.OutputFormatPropertyName, Exports_js_3.OutputFormat[Exports_js_3.OutputFormat.Simple]).toLowerCase();\n }\n if (config.autoDetectSourceLanguages !== undefined) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.EnableLanguageId] = \"true\";\n }\n this.setCommonUrlParams(config, queryParams, endpoint);\n if (!endpoint) {\n switch (config.recognitionMode) {\n case Exports_js_4.RecognitionMode.Conversation:\n if (config.parameters.getProperty(Exports_js_2.ForceDictationPropertyName, \"false\") === \"true\") {\n endpoint = host + this.dictationRelativeUri;\n }\n else {\n if (config.recognitionEndpointVersion !== undefined && parseInt(config.recognitionEndpointVersion, 10) > 1) {\n endpoint = `${host}${this.universalUri}${config.recognitionEndpointVersion}`;\n }\n else {\n endpoint = host + this.conversationRelativeUri;\n }\n }\n break;\n case Exports_js_4.RecognitionMode.Dictation:\n endpoint = host + this.dictationRelativeUri;\n break;\n default:\n if (config.recognitionEndpointVersion !== undefined && parseInt(config.recognitionEndpointVersion, 10) > 1) {\n endpoint = `${host}${this.universalUri}${config.recognitionEndpointVersion}`;\n }\n else {\n endpoint = host + this.interactiveRelativeUri; // default is interactive\n }\n break;\n }\n }\n const headers = {};\n if (authInfo.token !== undefined && authInfo.token !== \"\") {\n headers[authInfo.headerName] = authInfo.token;\n }\n headers[HeaderNames_js_1.HeaderNames.ConnectionId] = connectionId;\n const enableCompression = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\n const webSocketConnection = new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_4.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\n // Set the value of SpeechServiceConnection_Url to webSocketConnection.uri (and not to `endpoint`), since this value is the final\n // URI that was used to make the connection (including query parameters).\n const uri = webSocketConnection.uri;\n config.parameters.setProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Url, uri);\n return webSocketConnection;\n }\n}\nexports.SpeechConnectionFactory = SpeechConnectionFactory;\n\n"],"mappings":"AAA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