UNPKG

@voice-ping/cognitive-services-speech

Version:

VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft

1 lines 2.53 kB
{"version":3,"sources":["src/common.speech/SpeechSynthesisConnectionFactory.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,WAAW,EAEd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACH,QAAQ,EACR,iBAAiB,EAEpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAK5E,qBAAa,gCAAiC,YAAW,2BAA2B;IAEhF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6C;IAEnE,MAAM,wFAyBZ;CACJ","file":"SpeechSynthesisConnectionFactory.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n ProxyInfo,\n WebsocketConnection, WebsocketMessageAdapter,\n} from \"../common.browser/Exports\";\nimport {\n IConnection,\n IStringDictionary\n} from \"../common/Exports\";\nimport { PropertyId } from \"../sdk/Exports\";\nimport {\n AuthInfo,\n SynthesizerConfig,\n WebsocketMessageFormatter\n} from \"./Exports\";\nimport { ISynthesisConnectionFactory } from \"./ISynthesisConnectionFactory\";\nimport {\n QueryParameterNames\n} from \"./QueryParameterNames\";\n\nexport class SpeechSynthesisConnectionFactory implements ISynthesisConnectionFactory {\n\n private readonly synthesisUri: string = \"/cognitiveservices/websocket/v1\";\n\n public create = (\n config: SynthesizerConfig,\n authInfo: AuthInfo,\n connectionId?: string): IConnection => {\n\n let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);\n const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);\n const hostSuffix = (region && region.toLowerCase().startsWith(\"china\")) ? \".azure.cn\" : \".microsoft.com\";\n const host: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, \"wss://\" + region + \".tts.speech\" + hostSuffix);\n\n const queryParams: IStringDictionary<string> = {};\n\n if (!endpoint) {\n endpoint = host + this.synthesisUri;\n }\n\n const headers: IStringDictionary<string> = {};\n if (authInfo.token !== undefined && authInfo.token !== \"\") {\n headers[authInfo.headerName] = authInfo.token;\n }\n headers[QueryParameterNames.ConnectionIdHeader] = connectionId;\n\n config.parameters.setProperty(PropertyId.SpeechServiceConnection_Url, endpoint);\n\n return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromParameters(config.parameters), connectionId);\n }\n}\n"]}