Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Speech Endpoint As A Parameter #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/sdk/speech.browser/SpeechConnectionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}

Expand All @@ -47,15 +48,19 @@ export class SpeechConnectionFactory implements IConnectionFactory {
queryParams[TestHooksParamName] = "1";
}

if (config.EndpointId) {
queryParams[EndpointIdParamName] = config.EndpointId;
}

const headers: IStringDictionary<string> = {};
headers[authInfo.HeaderName] = authInfo.Token;
headers[ConnectionIdHeader] = connectionId;

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 {
Expand Down
16 changes: 15 additions & 1 deletion src/sdk/speech/RecognizerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down