@volley/recognition-client-sdk 0.1.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -0
- package/dist/browser-CDQ_TzeH.d.ts +1039 -0
- package/dist/index.d.ts +461 -0
- package/dist/index.js +2332 -0
- package/dist/index.js.map +1 -0
- package/dist/recog-client-sdk.browser.d.ts +2 -0
- package/dist/recog-client-sdk.browser.js +1843 -0
- package/dist/recog-client-sdk.browser.js.map +1 -0
- package/package.json +73 -0
- package/src/browser.ts +24 -0
- package/src/config-builder.ts +213 -0
- package/src/factory.ts +43 -0
- package/src/index.ts +86 -0
- package/src/recognition-client.spec.ts +551 -0
- package/src/recognition-client.ts +595 -0
- package/src/recognition-client.types.ts +260 -0
- package/src/simplified-vgf-recognition-client.spec.ts +671 -0
- package/src/simplified-vgf-recognition-client.ts +339 -0
- package/src/utils/audio-ring-buffer.ts +170 -0
- package/src/utils/message-handler.ts +131 -0
- package/src/utils/url-builder.ts +70 -0
- package/src/vgf-recognition-mapper.ts +225 -0
- package/src/vgf-recognition-state.ts +89 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Builder for Recognition Client
|
|
3
|
+
*
|
|
4
|
+
* Simple builder pattern for RealTimeTwoWayWebSocketRecognitionClientConfig
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
RealTimeTwoWayWebSocketRecognitionClientConfig,
|
|
9
|
+
RecognitionCallbackUrl
|
|
10
|
+
} from './recognition-client.types.js';
|
|
11
|
+
import type {
|
|
12
|
+
ASRRequestConfig,
|
|
13
|
+
GameContextV1,
|
|
14
|
+
TranscriptionResultV1,
|
|
15
|
+
MetadataResultV1,
|
|
16
|
+
ErrorResultV1
|
|
17
|
+
} from '@recog/shared-types';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Builder for RealTimeTwoWayWebSocketRecognitionClientConfig
|
|
21
|
+
*
|
|
22
|
+
* Provides a fluent API for building client configurations.
|
|
23
|
+
*
|
|
24
|
+
* Example:
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const config = new ConfigBuilder()
|
|
27
|
+
* .url('ws://localhost:3101/ws/v1/recognize')
|
|
28
|
+
* .asrRequestConfig({
|
|
29
|
+
* provider: RecognitionProvider.DEEPGRAM,
|
|
30
|
+
* model: 'nova-2-general'
|
|
31
|
+
* })
|
|
32
|
+
* .onTranscript((result) => console.log(result))
|
|
33
|
+
* .build();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class ConfigBuilder {
|
|
37
|
+
private config: Partial<RealTimeTwoWayWebSocketRecognitionClientConfig> = {};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Set the WebSocket URL
|
|
41
|
+
*/
|
|
42
|
+
url(url: string): this {
|
|
43
|
+
this.config.url = url;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Set ASR request configuration
|
|
49
|
+
*/
|
|
50
|
+
asrRequestConfig(config: ASRRequestConfig): this {
|
|
51
|
+
this.config.asrRequestConfig = config;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Set game context
|
|
57
|
+
*/
|
|
58
|
+
gameContext(context: GameContextV1): this {
|
|
59
|
+
this.config.gameContext = context;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Set audio utterance ID
|
|
65
|
+
*/
|
|
66
|
+
audioUtteranceId(id: string): this {
|
|
67
|
+
this.config.audioUtteranceId = id;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Set callback URLs
|
|
73
|
+
*/
|
|
74
|
+
callbackUrls(urls: RecognitionCallbackUrl[]): this {
|
|
75
|
+
this.config.callbackUrls = urls;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Set user ID
|
|
81
|
+
*/
|
|
82
|
+
userId(id: string): this {
|
|
83
|
+
this.config.userId = id;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Set game session ID
|
|
89
|
+
*/
|
|
90
|
+
gameSessionId(id: string): this {
|
|
91
|
+
this.config.gameSessionId = id;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Set device ID
|
|
97
|
+
*/
|
|
98
|
+
deviceId(id: string): this {
|
|
99
|
+
this.config.deviceId = id;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Set account ID
|
|
105
|
+
*/
|
|
106
|
+
accountId(id: string): this {
|
|
107
|
+
this.config.accountId = id;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Set question answer ID
|
|
113
|
+
*/
|
|
114
|
+
questionAnswerId(id: string): this {
|
|
115
|
+
this.config.questionAnswerId = id;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Set platform
|
|
121
|
+
*/
|
|
122
|
+
platform(platform: string): this {
|
|
123
|
+
this.config.platform = platform;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Set transcript callback
|
|
129
|
+
*/
|
|
130
|
+
onTranscript(callback: (result: TranscriptionResultV1) => void): this {
|
|
131
|
+
this.config.onTranscript = callback;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Set metadata callback
|
|
137
|
+
*/
|
|
138
|
+
onMetadata(callback: (metadata: MetadataResultV1) => void): this {
|
|
139
|
+
this.config.onMetadata = callback;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Set error callback
|
|
145
|
+
*/
|
|
146
|
+
onError(callback: (error: ErrorResultV1) => void): this {
|
|
147
|
+
this.config.onError = callback;
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Set connected callback
|
|
153
|
+
*/
|
|
154
|
+
onConnected(callback: () => void): this {
|
|
155
|
+
this.config.onConnected = callback;
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Set disconnected callback
|
|
161
|
+
*/
|
|
162
|
+
onDisconnected(callback: (code: number, reason: string) => void): this {
|
|
163
|
+
this.config.onDisconnected = callback;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Set high water mark
|
|
169
|
+
*/
|
|
170
|
+
highWaterMark(bytes: number): this {
|
|
171
|
+
this.config.highWaterMark = bytes;
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Set low water mark
|
|
177
|
+
*/
|
|
178
|
+
lowWaterMark(bytes: number): this {
|
|
179
|
+
this.config.lowWaterMark = bytes;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Set max buffer duration in seconds
|
|
185
|
+
*/
|
|
186
|
+
maxBufferDurationSec(seconds: number): this {
|
|
187
|
+
this.config.maxBufferDurationSec = seconds;
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Set chunks per second
|
|
193
|
+
*/
|
|
194
|
+
chunksPerSecond(chunks: number): this {
|
|
195
|
+
this.config.chunksPerSecond = chunks;
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Set logger function
|
|
201
|
+
*/
|
|
202
|
+
logger(logger: (level: 'debug' | 'info' | 'warn' | 'error', message: string, data?: any) => void): this {
|
|
203
|
+
this.config.logger = logger;
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Build the configuration
|
|
209
|
+
*/
|
|
210
|
+
build(): RealTimeTwoWayWebSocketRecognitionClientConfig {
|
|
211
|
+
return this.config as RealTimeTwoWayWebSocketRecognitionClientConfig;
|
|
212
|
+
}
|
|
213
|
+
}
|
package/src/factory.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory function for creating Recognition Client instances
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { RealTimeTwoWayWebSocketRecognitionClient } from './recognition-client.js';
|
|
6
|
+
import { ConfigBuilder } from './config-builder.js';
|
|
7
|
+
import type { IRecognitionClient, RealTimeTwoWayWebSocketRecognitionClientConfig } from './recognition-client.types.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create a recognition client from a configuration object
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const client = createClient({
|
|
15
|
+
* url: 'ws://localhost:3101/ws/v1/recognize',
|
|
16
|
+
* onTranscript: (result) => console.log(result)
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function createClient(config: RealTimeTwoWayWebSocketRecognitionClientConfig): IRecognitionClient {
|
|
21
|
+
return new RealTimeTwoWayWebSocketRecognitionClient(config);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a recognition client using the builder pattern
|
|
26
|
+
*
|
|
27
|
+
* Example:
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const client = createClientWithBuilder((builder) =>
|
|
30
|
+
* builder
|
|
31
|
+
* .url('ws://localhost:3101/ws/v1/recognize')
|
|
32
|
+
* .onTranscript((result) => console.log(result))
|
|
33
|
+
* .onError((error) => console.error(error))
|
|
34
|
+
* );
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function createClientWithBuilder(
|
|
38
|
+
configure: (builder: ConfigBuilder) => ConfigBuilder
|
|
39
|
+
): IRecognitionClient {
|
|
40
|
+
const builder = new ConfigBuilder();
|
|
41
|
+
const config = configure(builder).build();
|
|
42
|
+
return new RealTimeTwoWayWebSocketRecognitionClient(config);
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Export RealTimeTwoWayWebSocketRecognitionClient (primary SDK)
|
|
2
|
+
export {
|
|
3
|
+
RealTimeTwoWayWebSocketRecognitionClient,
|
|
4
|
+
type RealTimeTwoWayWebSocketRecognitionClientConfig,
|
|
5
|
+
type TranscriptionResult,
|
|
6
|
+
isNormalDisconnection
|
|
7
|
+
} from './recognition-client.js';
|
|
8
|
+
|
|
9
|
+
// Export interfaces for dependency injection and testing
|
|
10
|
+
export {
|
|
11
|
+
type IRecognitionClient,
|
|
12
|
+
type IRecognitionClientConfig,
|
|
13
|
+
type IRecognitionClientStats,
|
|
14
|
+
type RecognitionCallbackUrl,
|
|
15
|
+
ClientState
|
|
16
|
+
} from './recognition-client.types.js';
|
|
17
|
+
|
|
18
|
+
// Export configuration builder
|
|
19
|
+
export { ConfigBuilder } from './config-builder.js';
|
|
20
|
+
|
|
21
|
+
// Export factory functions
|
|
22
|
+
export { createClient, createClientWithBuilder } from './factory.js';
|
|
23
|
+
|
|
24
|
+
// Export VGF state management (new simplified interface)
|
|
25
|
+
export {
|
|
26
|
+
SimplifiedVGFRecognitionClient,
|
|
27
|
+
createSimplifiedVGFClient,
|
|
28
|
+
type ISimplifiedVGFRecognitionClient,
|
|
29
|
+
type SimplifiedVGFClientConfig
|
|
30
|
+
} from './simplified-vgf-recognition-client.js';
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
type RecognitionState,
|
|
34
|
+
RecognitionVGFStateSchema,
|
|
35
|
+
RecordingStatus,
|
|
36
|
+
TranscriptionStatus,
|
|
37
|
+
type RecordingStatusType,
|
|
38
|
+
type TranscriptionStatusType,
|
|
39
|
+
createInitialRecognitionState,
|
|
40
|
+
isValidRecordingStatusTransition
|
|
41
|
+
} from './vgf-recognition-state.js';
|
|
42
|
+
|
|
43
|
+
// Re-export WebSocket protocol types for advanced usage
|
|
44
|
+
export { AudioEncoding } from '@recog/websocket';
|
|
45
|
+
|
|
46
|
+
// Re-export necessary types from shared-types
|
|
47
|
+
export {
|
|
48
|
+
// Recognition context types
|
|
49
|
+
type GameContextV1,
|
|
50
|
+
RecognitionContextTypeV1,
|
|
51
|
+
ControlSignalTypeV1,
|
|
52
|
+
ControlSignalTypeV1 as ControlSignal, // Alias for backward compatibility
|
|
53
|
+
|
|
54
|
+
// Result types
|
|
55
|
+
type TranscriptionResultV1,
|
|
56
|
+
type FunctionCallResultV1,
|
|
57
|
+
type MetadataResultV1,
|
|
58
|
+
type ErrorResultV1,
|
|
59
|
+
RecognitionResultTypeV1,
|
|
60
|
+
|
|
61
|
+
// ASR configuration types
|
|
62
|
+
type ASRRequestConfig,
|
|
63
|
+
type ASRRequestV1,
|
|
64
|
+
RecognitionProvider,
|
|
65
|
+
DeepgramModel,
|
|
66
|
+
GoogleModel,
|
|
67
|
+
GeminiModel,
|
|
68
|
+
OpenAIModel,
|
|
69
|
+
Language,
|
|
70
|
+
SampleRate
|
|
71
|
+
} from '@recog/shared-types';
|
|
72
|
+
|
|
73
|
+
// Re-export shared config helpers so consumers don't depend on internal package
|
|
74
|
+
export {
|
|
75
|
+
getRecognitionServiceBase,
|
|
76
|
+
getRecognitionServiceHttpBase,
|
|
77
|
+
getRecognitionServiceWsBase,
|
|
78
|
+
getRecognitionServiceHost,
|
|
79
|
+
getRecognitionConductorBase,
|
|
80
|
+
getRecognitionConductorHttpBase,
|
|
81
|
+
getRecognitionConductorWsBase,
|
|
82
|
+
getRecognitionConductorHost,
|
|
83
|
+
normalizeStage,
|
|
84
|
+
RECOGNITION_SERVICE_BASES,
|
|
85
|
+
RECOGNITION_CONDUCTOR_BASES
|
|
86
|
+
} from '@recog/shared-config';
|