This repository was archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathRecognizerConfig.ts
More file actions
193 lines (157 loc) · 4.56 KB
/
RecognizerConfig.ts
File metadata and controls
193 lines (157 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
export enum RecognitionAPI {
BingSpeech,
CustomSpeech,
}
export enum RecognitionMode {
Interactive,
Conversation,
Dictation,
}
export enum SpeechResultFormat {
Simple,
Detailed,
}
export class RecognizerConfig {
private recognitionMode: RecognitionMode = RecognitionMode.Interactive;
private language: string;
private format: SpeechResultFormat;
private speechConfig: SpeechConfig;
private recognitionActivityTimeout: number;
private recognitionAPI: RecognitionAPI;
private endpointId: string;
constructor(
platformConfig: SpeechConfig,
recognitionMode: RecognitionMode = RecognitionMode.Interactive,
language: string = "en-us",
format: SpeechResultFormat = SpeechResultFormat.Simple,
recognitionAPI: RecognitionAPI,
endpointId: string) {
this.speechConfig = platformConfig ? platformConfig : new SpeechConfig(new Context(null, null));
this.recognitionMode = recognitionMode;
this.language = language;
this.format = format;
this.recognitionActivityTimeout = recognitionMode === RecognitionMode.Interactive ? 8000 : 25000;
this.recognitionAPI = recognitionAPI,
this.endpointId = endpointId;
}
public get RecognitionMode(): RecognitionMode {
return this.recognitionMode;
}
public get Language(): string {
return this.language;
}
public get Format(): SpeechResultFormat {
return this.format;
}
public get SpeechConfig(): SpeechConfig {
return this.speechConfig;
}
public get RecognitionActivityTimeout(): number {
return this.recognitionActivityTimeout;
}
public get IsContinuousRecognition(): boolean {
return this.recognitionMode !== RecognitionMode.Interactive;
}
public get RecognitionAPI(): RecognitionAPI {
return this.recognitionAPI;
}
public get EndpointId(): string {
return this.endpointId;
}
}
// tslint:disable-next-line:max-classes-per-file
export class SpeechConfig {
private context: Context;
constructor(context: Context) {
this.context = context;
}
public Serialize = (): string => {
return JSON.stringify(this, (key: any, value: any): any => {
if (value && typeof value === "object") {
const replacement: any = {};
for (const k in value) {
if (Object.hasOwnProperty.call(value, k)) {
replacement[k && k.charAt(0).toLowerCase() + k.substring(1)] = value[k];
}
}
return replacement;
}
return value;
});
}
public get Context(): Context {
return this.context;
}
}
// tslint:disable-next-line:max-classes-per-file
export class Context {
private system: System;
private os: OS;
private device: Device;
constructor(os: OS, device: Device) {
this.system = new System();
this.os = os;
this.device = device;
}
public get System(): System {
return this.system;
}
public get OS(): OS {
return this.os;
}
public get Device(): Device {
return this.device;
}
}
// tslint:disable-next-line:max-classes-per-file
export class System {
private version: string;
constructor() {
// TODO: Tie this with the sdk Version somehow
this.version = "1.0.00000";
}
public get Version(): string {
// Controlled by sdk
return this.version;
}
}
// tslint:disable-next-line:max-classes-per-file
export class OS {
private platform: string;
private name: string;
private version: string;
constructor(platform: string, name: string, version: string) {
this.platform = platform;
this.name = name;
this.version = version;
}
public get Platform(): string {
return this.platform;
}
public get Name(): string {
return this.name;
}
public get Version(): string {
return this.version;
}
}
// tslint:disable-next-line:max-classes-per-file
export class Device {
private manufacturer: string;
private model: string;
private version: string;
constructor(manufacturer: string, model: string, version: string) {
this.manufacturer = manufacturer;
this.model = model;
this.version = version;
}
public get Manufacturer(): string {
return this.manufacturer;
}
public get Model(): string {
return this.model;
}
public get Version(): string {
return this.version;
}
}