@euirim/microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
40 lines (38 loc) • 2.36 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { ProxyInfo, WebsocketConnection, } from "../common.browser/Exports";
import { PropertyId } from "../sdk/Exports";
import { ConnectionFactoryBase } from "./ConnectionFactoryBase";
import { WebsocketMessageFormatter, } from "./Exports";
import { QueryParameterNames } from "./QueryParameterNames";
const TestHooksParamName = "testhooks";
const ConnectionIdHeader = "X-ConnectionId";
export class TranslationConnectionFactory extends ConnectionFactoryBase {
constructor() {
super(...arguments);
this.create = (config, authInfo, connectionId) => {
let endpoint = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);
if (!endpoint) {
const region = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);
endpoint = "wss://" + region + ".s2s.speech.microsoft.com/speech/translation/cognitiveservices/v1";
}
const queryParams = {
from: config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage),
to: config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages),
};
this.setCommonUrlParams(config, queryParams, endpoint);
this.setUrlParameter(PropertyId.SpeechServiceResponse_TranslationRequestStablePartialResult, QueryParameterNames.StableTranslation, config, queryParams, endpoint);
const voiceName = "voice";
const featureName = "features";
if (config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice, undefined) !== undefined) {
queryParams[voiceName] = config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice);
queryParams[featureName] = "texttospeech";
}
const headers = {};
headers[authInfo.headerName] = authInfo.token;
headers[ConnectionIdHeader] = connectionId;
return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), connectionId);
};
}
}
//# sourceMappingURL=TranslationConnectionFactory.js.map