hip1-microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 4.94 kB
Source Map (JSON)
{"version":3,"sources":["src/common.speech/TranslationConnectionFactory.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;AAItB,qBAAa,4BAA6B,SAAQ,qBAAqB;IAE5D,MAAM,CACT,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW;IAuBhC,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE,uBAAuB,CAAC,EAAE,OAAO,GAAG,MAAM;IAuBnF,cAAc,CAAC,WAAW,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;CAsBrH","file":"TranslationConnectionFactory.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n ProxyInfo,\n WebsocketConnection,\n} from \"../common.browser/Exports.js\";\nimport {\n IConnection,\n IStringDictionary,\n} from \"../common/Exports.js\";\nimport { StringUtils } from \"../common/StringUtils.js\";\nimport {\n PropertyId\n} from \"../sdk/Exports.js\";\nimport {\n ConnectionFactoryBase\n} from \"./ConnectionFactoryBase.js\";\nimport {\n AuthInfo,\n RecognitionMode,\n RecognizerConfig,\n WebsocketMessageFormatter,\n} from \"./Exports.js\";\nimport { HeaderNames } from \"./HeaderNames.js\";\nimport { QueryParameterNames } from \"./QueryParameterNames.js\";\n\nexport class TranslationConnectionFactory extends ConnectionFactoryBase {\n\n public create(\n config: RecognizerConfig,\n authInfo: AuthInfo,\n connectionId?: string): IConnection {\n\n const endpoint: string = this.getEndpointUrl(config);\n\n const queryParams: IStringDictionary<string> = {};\n\n if (config.autoDetectSourceLanguages !== undefined) {\n queryParams[QueryParameterNames.EnableLanguageId] = \"true\";\n }\n this.setQueryParams(queryParams, config, endpoint);\n\n const headers: IStringDictionary<string> = {};\n if (authInfo.token !== undefined && authInfo.token !== \"\") {\n headers[authInfo.headerName] = authInfo.token;\n }\n headers[HeaderNames.ConnectionId] = connectionId;\n\n config.parameters.setProperty(PropertyId.SpeechServiceConnection_Url, endpoint);\n\n const enableCompression: boolean = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\n return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\n }\n\n public getEndpointUrl(config: RecognizerConfig, returnRegionPlaceholder?: boolean): string {\n\n const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region);\n const hostSuffix: string = ConnectionFactoryBase.getHostSuffix(region);\n\n let endpointUrl: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);\n if (!endpointUrl) {\n if (config.autoDetectSourceLanguages !== undefined) {\n const host: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, \"wss://{region}.stt.speech\" + hostSuffix);\n endpointUrl = host + \"/speech/universal/v2\";\n } else {\n const host: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, \"wss://{region}.s2s.speech\" + hostSuffix);\n endpointUrl = host + \"/speech/translation/cognitiveservices/v1\";\n }\n }\n\n if (returnRegionPlaceholder === true) {\n return endpointUrl;\n }\n\n return StringUtils.formatString(endpointUrl, { region });\n }\n\n public setQueryParams(queryParams: IStringDictionary<string>, config: RecognizerConfig, endpointUrl: string): void {\n\n queryParams.from = config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);\n queryParams.to = config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages);\n queryParams.scenario = config.recognitionMode === RecognitionMode.Interactive ? \"interactive\" :\n config.recognitionMode === RecognitionMode.Conversation ? \"conversation\" : \"\";\n\n this.setCommonUrlParams(config, queryParams, endpointUrl);\n this.setUrlParameter(\n PropertyId.SpeechServiceResponse_TranslationRequestStablePartialResult,\n QueryParameterNames.StableTranslation,\n config,\n queryParams,\n endpointUrl\n );\n\n const translationVoice: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice, undefined);\n if (translationVoice !== undefined) {\n queryParams.voice = translationVoice;\n queryParams.features = \"texttospeech\";\n }\n }\n}\n"]}