@voice-ping/cognitive-services-speech
Version:
VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft
31 lines (29 loc) • 1.75 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 { WebsocketMessageFormatter } from "./Exports";
import { QueryParameterNames } from "./QueryParameterNames";
export class SpeechSynthesisConnectionFactory {
constructor() {
this.synthesisUri = "/cognitiveservices/websocket/v1";
this.create = (config, authInfo, connectionId) => {
let endpoint = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);
const region = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);
const hostSuffix = (region && region.toLowerCase().startsWith("china")) ? ".azure.cn" : ".microsoft.com";
const host = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, "wss://" + region + ".tts.speech" + hostSuffix);
const queryParams = {};
if (!endpoint) {
endpoint = host + this.synthesisUri;
}
const headers = {};
if (authInfo.token !== undefined && authInfo.token !== "") {
headers[authInfo.headerName] = authInfo.token;
}
headers[QueryParameterNames.ConnectionIdHeader] = connectionId;
config.parameters.setProperty(PropertyId.SpeechServiceConnection_Url, endpoint);
return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromParameters(config.parameters), connectionId);
};
}
}
//# sourceMappingURL=SpeechSynthesisConnectionFactory.js.map