microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
52 lines (50 loc) • 3.13 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectionFactoryBase = void 0;
const Exports_js_1 = require("../common.speech/Exports.js");
const Exports_js_2 = require("../sdk/Exports.js");
const QueryParameterNames_js_1 = require("./QueryParameterNames.js");
class ConnectionFactoryBase {
static getHostSuffix(region) {
if (!!region) {
if (region.toLowerCase().startsWith("china")) {
return ".azure.cn";
}
if (region.toLowerCase().startsWith("usgov")) {
return ".azure.us";
}
}
return ".microsoft.com";
}
setCommonUrlParams(config, queryParams, endpoint) {
const propertyIdToParameterMap = new Map([
[Exports_js_2.PropertyId.Speech_SegmentationSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.SegmentationSilenceTimeoutMs],
[Exports_js_2.PropertyId.SpeechServiceConnection_EnableAudioLogging, QueryParameterNames_js_1.QueryParameterNames.EnableAudioLogging],
[Exports_js_2.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.EndSilenceTimeoutMs],
[Exports_js_2.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, QueryParameterNames_js_1.QueryParameterNames.InitialSilenceTimeoutMs],
[Exports_js_2.PropertyId.SpeechServiceResponse_PostProcessingOption, QueryParameterNames_js_1.QueryParameterNames.Postprocessing],
[Exports_js_2.PropertyId.SpeechServiceResponse_ProfanityOption, QueryParameterNames_js_1.QueryParameterNames.Profanity],
[Exports_js_2.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps, QueryParameterNames_js_1.QueryParameterNames.EnableWordLevelTimestamps],
[Exports_js_2.PropertyId.SpeechServiceResponse_StablePartialResultThreshold, QueryParameterNames_js_1.QueryParameterNames.StableIntermediateThreshold],
]);
propertyIdToParameterMap.forEach((parameterName, propertyId) => {
this.setUrlParameter(propertyId, parameterName, config, queryParams, endpoint);
});
const serviceProperties = JSON.parse(config.parameters.getProperty(Exports_js_1.ServicePropertiesPropertyName, "{}"));
Object.keys(serviceProperties).forEach((value) => {
queryParams[value] = serviceProperties[value];
});
}
setUrlParameter(propId, parameterName, config, queryParams, endpoint) {
const value = config.parameters.getProperty(propId, undefined);
// FIXME: The .search() check will incorrectly match parameter name anywhere in the string
// including e.g. the path portion, or even as a substring of other query parameters
if (value && (!endpoint || endpoint.search(parameterName) === -1)) {
queryParams[parameterName] = value.toLocaleLowerCase();
}
}
}
exports.ConnectionFactoryBase = ConnectionFactoryBase;
//# sourceMappingURL=ConnectionFactoryBase.js.map