UNPKG

@euirim/microsoft-cognitiveservices-speech-sdk

Version:
1 lines 3.03 kB
{"version":3,"sources":["src/common.speech/TranslationConnectionFactory.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,WAAW,EAEd,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EACH,qBAAqB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,QAAQ,EAER,gBAAgB,EAEnB,MAAM,WAAW,CAAC;AAMnB,qBAAa,4BAA6B,SAAQ,qBAAqB;IAE5D,MAAM,uFAuCZ;CACJ","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\";\nimport {\n IConnection,\n IStringDictionary,\n} from \"../common/Exports\";\nimport {\n PropertyId\n} from \"../sdk/Exports\";\nimport {\n ConnectionFactoryBase\n} from \"./ConnectionFactoryBase\";\nimport {\n AuthInfo,\n IConnectionFactory,\n RecognizerConfig,\n WebsocketMessageFormatter,\n} from \"./Exports\";\nimport { QueryParameterNames } from \"./QueryParameterNames\";\n\nconst TestHooksParamName: string = \"testhooks\";\nconst ConnectionIdHeader: string = \"X-ConnectionId\";\n\nexport class TranslationConnectionFactory extends ConnectionFactoryBase {\n\n public create = (\n config: RecognizerConfig,\n authInfo: AuthInfo,\n connectionId?: string): IConnection => {\n\n let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);\n if (!endpoint) {\n const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);\n\n endpoint = \"wss://\" + region + \".s2s.speech.microsoft.com/speech/translation/cognitiveservices/v1\";\n }\n\n const queryParams: IStringDictionary<string> = {\n from: config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage),\n to: config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages),\n };\n\n this.setCommonUrlParams(config, queryParams, endpoint);\n this.setUrlParameter(\n PropertyId.SpeechServiceResponse_TranslationRequestStablePartialResult,\n QueryParameterNames.StableTranslation,\n config,\n queryParams,\n endpoint\n );\n\n const voiceName: string = \"voice\";\n const featureName: string = \"features\";\n\n if (config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice, undefined) !== undefined) {\n queryParams[voiceName] = config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice);\n queryParams[featureName] = \"texttospeech\";\n }\n\n const headers: IStringDictionary<string> = {};\n headers[authInfo.headerName] = authInfo.token;\n headers[ConnectionIdHeader] = connectionId;\n\n return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), connectionId);\n }\n}\n"]}