UNPKG

@euirim/microsoft-cognitiveservices-speech-sdk

Version:
82 lines (80 loc) 4.78 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("../common.speech/Exports"); var Exports_3 = require("../sdk/Exports"); var ConnectionFactoryBase_1 = require("./ConnectionFactoryBase"); var Exports_4 = require("./Exports"); var QueryParameterNames_1 = require("./QueryParameterNames"); var SpeechConnectionFactory = /** @class */ (function (_super) { __extends(SpeechConnectionFactory, _super); function SpeechConnectionFactory() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.interactiveRelativeUri = "/speech/recognition/interactive/cognitiveservices/v1"; _this.conversationRelativeUri = "/speech/recognition/conversation/cognitiveservices/v1"; _this.dictationRelativeUri = "/speech/recognition/dictation/cognitiveservices/v1"; _this.create = function (config, authInfo, connectionId) { var endpoint = config.parameters.getProperty(Exports_3.PropertyId.SpeechServiceConnection_Endpoint, undefined); var queryParams = {}; var endpointId = config.parameters.getProperty(Exports_3.PropertyId.SpeechServiceConnection_EndpointId, undefined); var language = config.parameters.getProperty(Exports_3.PropertyId.SpeechServiceConnection_RecoLanguage, undefined); if (endpointId) { if (!endpoint || endpoint.search(QueryParameterNames_1.QueryParameterNames.DeploymentIdParamName) === -1) { queryParams[QueryParameterNames_1.QueryParameterNames.DeploymentIdParamName] = endpointId; } } else if (language) { if (!endpoint || endpoint.search(QueryParameterNames_1.QueryParameterNames.LanguageParamName) === -1) { queryParams[QueryParameterNames_1.QueryParameterNames.LanguageParamName] = language; } } if (!endpoint || endpoint.search(QueryParameterNames_1.QueryParameterNames.FormatParamName) === -1) { queryParams[QueryParameterNames_1.QueryParameterNames.FormatParamName] = config.parameters.getProperty(Exports_2.OutputFormatPropertyName, Exports_3.OutputFormat[Exports_3.OutputFormat.Simple]).toLowerCase(); } _this.setCommonUrlParams(config, queryParams, endpoint); if (!endpoint) { var region = config.parameters.getProperty(Exports_3.PropertyId.SpeechServiceConnection_Region, undefined); var host = "wss://" + region + ".stt.speech.microsoft.com"; switch (config.recognitionMode) { case Exports_4.RecognitionMode.Conversation: if (config.parameters.getProperty(Exports_2.ForceDictationPropertyName, "false") === "true") { endpoint = host + _this.dictationRelativeUri; } else { endpoint = host + _this.conversationRelativeUri; } break; case Exports_4.RecognitionMode.Dictation: endpoint = host + _this.dictationRelativeUri; break; default: endpoint = host + _this.interactiveRelativeUri; // default is interactive break; } } var headers = {}; headers[authInfo.headerName] = authInfo.token; headers[QueryParameterNames_1.QueryParameterNames.ConnectionIdHeader] = connectionId; return new Exports_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_4.WebsocketMessageFormatter(), Exports_1.ProxyInfo.fromRecognizerConfig(config), connectionId); }; return _this; } return SpeechConnectionFactory; }(ConnectionFactoryBase_1.ConnectionFactoryBase)); exports.SpeechConnectionFactory = SpeechConnectionFactory; //# sourceMappingURL=SpeechConnectionFactory.js.map