From 25445b15c71b63771d8d208ebca29ececec1c444 Mon Sep 17 00:00:00 2001 From: Michael Holcomb Date: Tue, 5 Jun 2018 15:44:34 -0700 Subject: [PATCH] Added the ability to pass in a custom speech endpoint and endpoint Id to the SpeechConnectionFactory. Speech endpoint will default to Bing if none is passed in. --- .../speech.browser/SpeechConnectionFactory.ts | 15 ++++++++++----- src/sdk/speech/RecognizerConfig.ts | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/sdk/speech.browser/SpeechConnectionFactory.ts b/src/sdk/speech.browser/SpeechConnectionFactory.ts index ca18fb1..cdd7275 100644 --- a/src/sdk/speech.browser/SpeechConnectionFactory.ts +++ b/src/sdk/speech.browser/SpeechConnectionFactory.ts @@ -16,6 +16,7 @@ import { } from "../speech/Exports"; const TestHooksParamName: string = "testhooks"; +const EndpointIdParamName: string = "cid"; const ConnectionIdHeader: string = "X-ConnectionId"; export class SpeechConnectionFactory implements IConnectionFactory { @@ -28,13 +29,13 @@ export class SpeechConnectionFactory implements IConnectionFactory { let endpoint = ""; switch (config.RecognitionMode) { case RecognitionMode.Conversation: - endpoint = this.Host + this.ConversationRelativeUri; + endpoint = this.Host(config.Host) + this.ConversationRelativeUri; break; case RecognitionMode.Dictation: - endpoint = this.Host + this.DictationRelativeUri; + endpoint = this.Host(config.Host) + this.DictationRelativeUri; break; default: - endpoint = this.Host + this.InteractiveRelativeUri; // default is interactive + endpoint = this.Host(config.Host) + this.InteractiveRelativeUri; // default is interactive break; } @@ -47,6 +48,10 @@ export class SpeechConnectionFactory implements IConnectionFactory { queryParams[TestHooksParamName] = "1"; } + if (config.EndpointId) { + queryParams[EndpointIdParamName] = config.EndpointId; + } + const headers: IStringDictionary = {}; headers[authInfo.HeaderName] = authInfo.Token; headers[ConnectionIdHeader] = connectionId; @@ -54,8 +59,8 @@ export class SpeechConnectionFactory implements IConnectionFactory { return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), connectionId); } - private get Host(): string { - return Storage.Local.GetOrAdd("Host", "wss://speech.platform.bing.com"); + private Host(host: string): string { + return Storage.Local.GetOrAdd("Host", host); } private get InteractiveRelativeUri(): string { diff --git a/src/sdk/speech/RecognizerConfig.ts b/src/sdk/speech/RecognizerConfig.ts index 96fab91..2f7f50a 100644 --- a/src/sdk/speech/RecognizerConfig.ts +++ b/src/sdk/speech/RecognizerConfig.ts @@ -16,16 +16,22 @@ export class RecognizerConfig { private format: SpeechResultFormat; private speechConfig: SpeechConfig; private recognitionActivityTimeout: number; + private host: string; + private endpointId: string; constructor( platformConfig: SpeechConfig, recognitionMode: RecognitionMode = RecognitionMode.Interactive, language: string = "en-us", - format: SpeechResultFormat = SpeechResultFormat.Simple) { + format: SpeechResultFormat = SpeechResultFormat.Simple, + endpoint: string = "wss://speech.platform.bing.com", + endpointId: string = null) { this.speechConfig = platformConfig ? platformConfig : new SpeechConfig(new Context(null, null)); this.recognitionMode = recognitionMode; this.language = language; this.format = format; + this.host = endpoint; + this.endpointId = endpointId; this.recognitionActivityTimeout = recognitionMode === RecognitionMode.Interactive ? 8000 : 25000; } @@ -41,6 +47,14 @@ export class RecognizerConfig { return this.format; } + public get Host(): string { + return this.host; + } + + public get EndpointId(): string { + return this.endpointId; + } + public get SpeechConfig(): SpeechConfig { return this.speechConfig; }