UNPKG

@voice-ping/cognitive-services-speech

Version:

VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft

110 lines (108 loc) 4.81 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var Exports_1 = require("../common.browser/Exports"); var Exports_2 = require("../sdk/Exports"); var ConnectionFactoryBase_1 = require("./ConnectionFactoryBase"); var Exports_3 = require("./Exports"); var TestHooksParamName = "testhooks"; var ConnectionIdHeader = "X-ConnectionId"; var IntentConnectionFactory = /** @class */ (function (_super) { __extends(IntentConnectionFactory, _super); function IntentConnectionFactory() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.create = function (config, authInfo, connectionId) { var endpoint = config.parameters.getProperty(Exports_2.PropertyId.SpeechServiceConnection_Endpoint); if (!endpoint) { var region = config.parameters.getProperty(Exports_2.PropertyId.SpeechServiceConnection_IntentRegion); var hostSuffix = (region && region.toLowerCase().startsWith("china")) ? ".azure.cn" : ".microsoft.com"; var host = config.parameters.getProperty(Exports_2.PropertyId.SpeechServiceConnection_Host, "wss://" + region + ".sr.speech" + hostSuffix); endpoint = host + "/speech/recognition/interactive/cognitiveservices/v1"; } var queryParams = { format: "simple", language: config.parameters.getProperty(Exports_2.PropertyId.SpeechServiceConnection_RecoLanguage), }; _this.setCommonUrlParams(config, queryParams, endpoint); var headers = {}; if (authInfo.token !== undefined && authInfo.token !== "") { headers[authInfo.headerName] = authInfo.token; } headers[ConnectionIdHeader] = connectionId; config.parameters.setProperty(Exports_2.PropertyId.SpeechServiceConnection_Url, endpoint); return new Exports_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_3.WebsocketMessageFormatter(), Exports_1.ProxyInfo.fromRecognizerConfig(config), connectionId); }; return _this; } IntentConnectionFactory.prototype.getSpeechRegionFromIntentRegion = function (intentRegion) { switch (intentRegion) { case "West US": case "US West": case "westus": return "uswest"; case "West US 2": case "US West 2": case "westus2": return "uswest2"; case "South Central US": case "US South Central": case "southcentralus": return "ussouthcentral"; case "West Central US": case "US West Central": case "westcentralus": return "uswestcentral"; case "East US": case "US East": case "eastus": return "useast"; case "East US 2": case "US East 2": case "eastus2": return "useast2"; case "West Europe": case "Europe West": case "westeurope": return "europewest"; case "North Europe": case "Europe North": case "northeurope": return "europenorth"; case "Brazil South": case "South Brazil": case "southbrazil": return "brazilsouth"; case "Australia East": case "East Australia": case "eastaustralia": return "australiaeast"; case "Southeast Asia": case "Asia Southeast": case "southeastasia": return "asiasoutheast"; case "East Asia": case "Asia East": case "eastasia": return "asiaeast"; default: return intentRegion; } }; return IntentConnectionFactory; }(ConnectionFactoryBase_1.ConnectionFactoryBase)); exports.IntentConnectionFactory = IntentConnectionFactory; //# sourceMappingURL=IntentConnectionFactory.js.map