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.TranslationConnectionFactory = void 0;\nconst Exports_js_1 = require(\"../common.browser/Exports.js\");\nconst StringUtils_js_1 = require(\"../common/StringUtils.js\");\nconst Exports_js_2 = require(\"../sdk/Exports.js\");\nconst ConnectionFactoryBase_js_1 = require(\"./ConnectionFactoryBase.js\");\nconst Exports_js_3 = require(\"./Exports.js\");\nconst HeaderNames_js_1 = require(\"./HeaderNames.js\");\nconst QueryParameterNames_js_1 = require(\"./QueryParameterNames.js\");\nclass TranslationConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {\n create(config, authInfo, connectionId) {\n const endpoint = this.getEndpointUrl(config);\n const queryParams = {};\n if (config.autoDetectSourceLanguages !== undefined) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.EnableLanguageId] = \"true\";\n }\n this.setQueryParams(queryParams, config, endpoint);\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 config.parameters.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url, endpoint);\n const enableCompression = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\n return new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_3.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\n }\n getEndpointUrl(config, returnRegionPlaceholder) {\n const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region);\n const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);\n let endpointUrl = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, undefined);\n if (!endpointUrl) {\n if (config.autoDetectSourceLanguages !== undefined) {\n const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, \"wss://{region}.stt.speech\" + hostSuffix);\n endpointUrl = host + \"/speech/universal/v2\";\n } else {\n const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, \"wss://{region}.s2s.speech\" + hostSuffix);\n endpointUrl = host + \"/speech/translation/cognitiveservices/v1\";\n }\n }\n if (returnRegionPlaceholder === true) {\n return endpointUrl;\n }\n return StringUtils_js_1.StringUtils.formatString(endpointUrl, {\n region\n });\n }\n setQueryParams(queryParams, config, endpointUrl) {\n queryParams.from = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage);\n queryParams.to = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationToLanguages);\n queryParams.scenario = config.recognitionMode === Exports_js_3.RecognitionMode.Interactive ? \"interactive\" : config.recognitionMode === Exports_js_3.RecognitionMode.Conversation ? \"conversation\" : \"\";\n this.setCommonUrlParams(config, queryParams, endpointUrl);\n this.setUrlParameter(Exports_js_2.PropertyId.SpeechServiceResponse_TranslationRequestStablePartialResult, QueryParameterNames_js_1.QueryParameterNames.StableTranslation, config, queryParams, endpointUrl);\n const translationVoice = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationVoice, undefined);\n if (translationVoice !== undefined) {\n queryParams.voice = translationVoice;\n queryParams.features = \"texttospeech\";\n }\n }\n}\nexports.TranslationConnectionFactory = TranslationConnectionFactory;","map":{"version":3,"names":["Object","defineProperty","exports","value","TranslationConnectionFactory","Exports_js_1","require","StringUtils_js_1","Exports_js_2","ConnectionFactoryBase_js_1","Exports_js_3","HeaderNames_js_1","QueryParameterNames_js_1","ConnectionFactoryBase","create","config","authInfo","connectionId","endpoint","getEndpointUrl","queryParams","autoDetectSourceLanguages","undefined","QueryParameterNames","EnableLanguageId","setQueryParams","headers","token","headerName","HeaderNames","ConnectionId","parameters","setProperty","PropertyId","SpeechServiceConnection_Url","enableCompression","getProperty","WebsocketConnection","WebsocketMessageFormatter","ProxyInfo","fromRecognizerConfig","returnRegionPlaceholder","region","SpeechServiceConnection_Region","hostSuffix","getHostSuffix","endpointUrl","SpeechServiceConnection_Endpoint","host","SpeechServiceConnection_Host","StringUtils","formatString","from","SpeechServiceConnection_RecoLanguage","to","SpeechServiceConnection_TranslationToLanguages","scenario","recognitionMode","RecognitionMode","Interactive","Conversation","setCommonUrlParams","setUrlParameter","SpeechServiceResponse_TranslationRequestStablePartialResult","StableTranslation","translationVoice","SpeechServiceConnection_TranslationVoice","voice","features"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common.speech/TranslationConnectionFactory.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.TranslationConnectionFactory = void 0;\nconst Exports_js_1 = require(\"../common.browser/Exports.js\");\nconst StringUtils_js_1 = require(\"../common/StringUtils.js\");\nconst Exports_js_2 = require(\"../sdk/Exports.js\");\nconst ConnectionFactoryBase_js_1 = require(\"./ConnectionFactoryBase.js\");\nconst Exports_js_3 = require(\"./Exports.js\");\nconst HeaderNames_js_1 = require(\"./HeaderNames.js\");\nconst QueryParameterNames_js_1 = require(\"./QueryParameterNames.js\");\nclass TranslationConnectionFactory extends ConnectionFactoryBase_js_1.ConnectionFactoryBase {\n create(config, authInfo, connectionId) {\n const endpoint = this.getEndpointUrl(config);\n const queryParams = {};\n if (config.autoDetectSourceLanguages !== undefined) {\n queryParams[QueryParameterNames_js_1.QueryParameterNames.EnableLanguageId] = \"true\";\n }\n this.setQueryParams(queryParams, config, endpoint);\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 config.parameters.setProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Url, endpoint);\n const enableCompression = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\n return new Exports_js_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_js_3.WebsocketMessageFormatter(), Exports_js_1.ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\n }\n getEndpointUrl(config, returnRegionPlaceholder) {\n const region = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Region);\n const hostSuffix = ConnectionFactoryBase_js_1.ConnectionFactoryBase.getHostSuffix(region);\n let endpointUrl = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Endpoint, undefined);\n if (!endpointUrl) {\n if (config.autoDetectSourceLanguages !== undefined) {\n const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, \"wss://{region}.stt.speech\" + hostSuffix);\n endpointUrl = host + \"/speech/universal/v2\";\n }\n else {\n const host = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_Host, \"wss://{region}.s2s.speech\" + hostSuffix);\n endpointUrl = host + \"/speech/translation/cognitiveservices/v1\";\n }\n }\n if (returnRegionPlaceholder === true) {\n return endpointUrl;\n }\n return StringUtils_js_1.StringUtils.formatString(endpointUrl, { region });\n }\n setQueryParams(queryParams, config, endpointUrl) {\n queryParams.from = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_RecoLanguage);\n queryParams.to = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationToLanguages);\n queryParams.scenario = config.recognitionMode === Exports_js_3.RecognitionMode.Interactive ? \"interactive\" :\n config.recognitionMode === Exports_js_3.RecognitionMode.Conversation ? \"conversation\" : \"\";\n this.setCommonUrlParams(config, queryParams, endpointUrl);\n this.setUrlParameter(Exports_js_2.PropertyId.SpeechServiceResponse_TranslationRequestStablePartialResult, QueryParameterNames_js_1.QueryParameterNames.StableTranslation, config, queryParams, endpointUrl);\n const translationVoice = config.parameters.getProperty(Exports_js_2.PropertyId.SpeechServiceConnection_TranslationVoice, undefined);\n if (translationVoice !== undefined) {\n queryParams.voice = translationVoice;\n queryParams.features = \"texttospeech\";\n }\n }\n}\nexports.TranslationConnectionFactory = TranslationConnectionFactory;\n\n"],"mappings":"AAAA,YAAY;;AACZ;AACA;AACAA,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,4BAA4B,GAAG,KAAK,CAAC;AAC7C,MAAMC,YAAY,GAAGC,OAAO,CAAC,8BAA8B,CAAC;AAC5D,MAAMC,gBAAgB,GAAGD,OAAO,CAAC,0BAA0B,CAAC;AAC5D,MAAME,YAAY,GAAGF,OAAO,CAAC,mBAAmB,CAAC;AACjD,MAAMG,0BAA0B,GAAGH,OAAO,CAAC,4BAA4B,CAAC;AACxE,MAAMI,YAAY,GAAGJ,OAAO,CAAC,cAAc,CAAC;AAC5C,MAAMK,gBAAgB,GAAGL,OAAO,CAAC,kBAAkB,CAAC;AACpD,MAAMM,wBAAwB,GAAGN,OAAO,CAAC,0BAA0B,CAAC;AACpE,MAAMF,4BAA4B,SAASK,0BAA0B,CAACI,qBAAqB,CAAC;EACxFC,MAAMA,CAACC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAE;IACnC,MAAMC,QAAQ,GAAG,IAAI,CAACC,cAAc,CAACJ,MAAM,CAAC;IAC5C,MAAMK,WAAW,GAAG,CAAC,CAAC;IACtB,IAAIL,MAAM,CAACM,yBAAyB,KAAKC,SAAS,EAAE;MAChDF,WAAW,CAACR,wBAAwB,CAACW,mBAAmB,CAACC,gBAAgB,CAAC,GAAG,MAAM;IACvF;IACA,IAAI,CAACC,cAAc,CAACL,WAAW,EAAEL,MAAM,EAAEG,QAAQ,CAAC;IAClD,MAAMQ,OAAO,GAAG,CAAC,CAAC;IAClB,IAAIV,QAAQ,CAACW,KAAK,KAAKL,SAAS,IAAIN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