@glydeunity/voice-sdk 1.0.0 → 1.2.0
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/dist/index.d.ts +223 -4
- package/dist/voice-sdk.es.js +498 -2
- package/dist/voice-sdk.umd.js +135 -3
- package/package.json +5 -2
- package/dist/browser-C7NgeXQY.js +0 -17
- package/dist/index-BbD4w_Sz.js +0 -3091
package/dist/index.d.ts
CHANGED
|
@@ -1,32 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GLYDE Voice SDK
|
|
3
|
+
*
|
|
4
|
+
* Voice agent client for GLYDE Unity with support for multiple authentication methods
|
|
5
|
+
* and voice context types.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Deepgram agent configuration for LLM and voice settings
|
|
12
|
+
*/
|
|
13
|
+
export declare interface DeepgramAgentConfig {
|
|
14
|
+
think?: {
|
|
15
|
+
provider?: {
|
|
16
|
+
type: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
};
|
|
19
|
+
functions?: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
parameters: unknown;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
speak?: {
|
|
26
|
+
provider?: {
|
|
27
|
+
type: string;
|
|
28
|
+
model?: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
listen?: {
|
|
32
|
+
provider?: {
|
|
33
|
+
type: string;
|
|
34
|
+
model?: string;
|
|
35
|
+
version?: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* GlydeVoice - Voice Agent Client
|
|
42
|
+
*
|
|
43
|
+
* Connects to Deepgram Voice Agent API for bidirectional voice conversation.
|
|
44
|
+
* Uses wss://agent.deepgram.com/agent WebSocket endpoint which:
|
|
45
|
+
* - Receives user audio (microphone)
|
|
46
|
+
* - Transcribes speech to text (STT)
|
|
47
|
+
* - Sends to LLM for response
|
|
48
|
+
* - Converts response to speech (TTS)
|
|
49
|
+
* - Streams audio back to user
|
|
50
|
+
*
|
|
51
|
+
* Audio Architecture:
|
|
52
|
+
* - Microphone capture: AudioWorklet (audio-capture-processor.js) at 48kHz
|
|
53
|
+
* - Playback: AudioWorklet (audio-playback-processor.js) with ring buffer
|
|
54
|
+
* - Ring buffer enables instant interruption (clear buffer when user speaks)
|
|
55
|
+
*/
|
|
1
56
|
export declare class GlydeVoice {
|
|
2
57
|
private config;
|
|
3
|
-
private _deepgram;
|
|
4
58
|
private unityUrl;
|
|
5
59
|
private active;
|
|
60
|
+
private serverConfig;
|
|
61
|
+
private ws;
|
|
62
|
+
private audioContext;
|
|
63
|
+
private mediaStream;
|
|
64
|
+
private captureWorkletNode;
|
|
65
|
+
private playbackWorkletNode;
|
|
66
|
+
private isMuted;
|
|
67
|
+
private readonly outputSampleRate;
|
|
68
|
+
private readonly inputSampleRate;
|
|
69
|
+
private isAgentSpeaking;
|
|
70
|
+
private agentAudioDoneReceived;
|
|
71
|
+
/**
|
|
72
|
+
* Create a new GlydeVoice instance
|
|
73
|
+
* @param config - Configuration options
|
|
74
|
+
*/
|
|
6
75
|
constructor(config: GlydeVoiceConfig);
|
|
76
|
+
/**
|
|
77
|
+
* Get authentication headers based on configured auth method
|
|
78
|
+
* Supports publishableKey, apiKey, and JWT token (authToken)
|
|
79
|
+
* @returns Headers object with appropriate authentication
|
|
80
|
+
*/
|
|
81
|
+
private getAuthHeaders;
|
|
82
|
+
/**
|
|
83
|
+
* Fetch voice configuration from Unity API
|
|
84
|
+
* @returns Voice configuration including system prompt, tools, and Deepgram settings
|
|
85
|
+
*/
|
|
86
|
+
private fetchConfig;
|
|
7
87
|
/**
|
|
8
88
|
* Initialize and start the voice session
|
|
9
89
|
*/
|
|
10
90
|
start(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Create a blob URL from inline JavaScript code for AudioWorklet modules.
|
|
93
|
+
* This avoids CORS issues when the SDK is loaded from a different origin than the page.
|
|
94
|
+
* @param code - The JavaScript code to convert to a blob URL
|
|
95
|
+
* @returns A blob URL that can be used with audioWorklet.addModule()
|
|
96
|
+
*/
|
|
97
|
+
private createWorkletBlobUrl;
|
|
98
|
+
/**
|
|
99
|
+
* Initialize the audio system with both capture and playback worklets.
|
|
100
|
+
* Uses inline blob URLs to avoid CORS issues when SDK is embedded in external apps.
|
|
101
|
+
*/
|
|
102
|
+
private initializeAudio;
|
|
103
|
+
/**
|
|
104
|
+
* Handle text messages from the Voice Agent
|
|
105
|
+
*/
|
|
106
|
+
private handleTextMessage;
|
|
107
|
+
/**
|
|
108
|
+
* Handle binary audio data (Blob) from agent TTS
|
|
109
|
+
*/
|
|
110
|
+
private handleAudioData;
|
|
111
|
+
/**
|
|
112
|
+
* Handle binary audio buffer from agent TTS
|
|
113
|
+
* Deepgram sends linear16 PCM at 24kHz, we need to resample to 48kHz for playback
|
|
114
|
+
*/
|
|
115
|
+
private handleAudioBuffer;
|
|
116
|
+
/**
|
|
117
|
+
* Resample audio from 24kHz to 48kHz using linear interpolation
|
|
118
|
+
*/
|
|
119
|
+
private resample24kTo48k;
|
|
120
|
+
/**
|
|
121
|
+
* Clear the playback buffer (for interruption handling)
|
|
122
|
+
*/
|
|
123
|
+
private clearPlaybackBuffer;
|
|
124
|
+
/**
|
|
125
|
+
* Start capturing microphone audio using AudioWorklet
|
|
126
|
+
*/
|
|
127
|
+
private startMicrophone;
|
|
128
|
+
/**
|
|
129
|
+
* Save transcript to Unity backend
|
|
130
|
+
*/
|
|
131
|
+
private saveTranscript;
|
|
132
|
+
/**
|
|
133
|
+
* Toggle mute state
|
|
134
|
+
* @param muted - Whether to mute the microphone
|
|
135
|
+
*/
|
|
136
|
+
setMuted(muted: boolean): void;
|
|
137
|
+
/**
|
|
138
|
+
* Get current mute state
|
|
139
|
+
*/
|
|
140
|
+
getMuted(): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Check if the voice agent is currently active
|
|
143
|
+
*/
|
|
144
|
+
isActive(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Get the current server configuration
|
|
147
|
+
*/
|
|
148
|
+
getServerConfig(): VoiceConfig | null;
|
|
11
149
|
/**
|
|
12
150
|
* Stop the voice session
|
|
13
151
|
*/
|
|
14
152
|
stop(): void;
|
|
153
|
+
/**
|
|
154
|
+
* Cleanup resources
|
|
155
|
+
*/
|
|
156
|
+
private cleanup;
|
|
157
|
+
/**
|
|
158
|
+
* Emit event to callback
|
|
159
|
+
*/
|
|
15
160
|
private emit;
|
|
161
|
+
/**
|
|
162
|
+
* Render a simple UI widget (optional)
|
|
163
|
+
*/
|
|
16
164
|
private renderUI;
|
|
17
165
|
}
|
|
18
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Configuration options for GlydeVoice
|
|
169
|
+
*/
|
|
19
170
|
export declare interface GlydeVoiceConfig {
|
|
20
|
-
|
|
171
|
+
/** Publishable key for external apps (Screen) */
|
|
172
|
+
publishableKey?: string;
|
|
173
|
+
/** API key for programmatic access */
|
|
174
|
+
apiKey?: string;
|
|
175
|
+
/** JWT token for GLYDEBuddy passthrough (Teams app) */
|
|
176
|
+
authToken?: string;
|
|
177
|
+
/** Voice context type - determines which prompt and tools to use */
|
|
178
|
+
contextType: VoiceContextType;
|
|
179
|
+
/** Context identifier (e.g., application_uuid) - required for screening */
|
|
21
180
|
contextId?: string;
|
|
181
|
+
/** Unity API base URL - defaults to https://api.glydeunity.com */
|
|
22
182
|
unityBaseUrl?: string;
|
|
183
|
+
/** DOM element to render the widget UI (optional) */
|
|
23
184
|
container?: HTMLElement | string;
|
|
185
|
+
/** Event callback for voice agent events */
|
|
24
186
|
onEvent?: (event: VoiceEvent) => void;
|
|
187
|
+
/** Transcript callback for conversation text */
|
|
188
|
+
onTranscript?: (text: string, role: 'user' | 'agent') => void;
|
|
189
|
+
/** Override system prompt (skips config fetch) */
|
|
190
|
+
systemPrompt?: string;
|
|
191
|
+
/** Override Deepgram configuration */
|
|
192
|
+
deepgramConfig?: DeepgramAgentConfig;
|
|
25
193
|
}
|
|
26
194
|
|
|
195
|
+
/**
|
|
196
|
+
* MCP Tool definition for voice agent
|
|
197
|
+
*/
|
|
198
|
+
export declare interface MCPTool {
|
|
199
|
+
name: string;
|
|
200
|
+
description: string;
|
|
201
|
+
inputSchema?: unknown;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Voice configuration response from Unity API
|
|
206
|
+
*/
|
|
207
|
+
export declare interface VoiceConfig {
|
|
208
|
+
system_prompt: string;
|
|
209
|
+
available_tools: MCPTool[];
|
|
210
|
+
deepgram_config: DeepgramAgentConfig;
|
|
211
|
+
context: {
|
|
212
|
+
type: VoiceContextType;
|
|
213
|
+
id: string | null;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* GlydeVoice SDK - Voice Agent Client for GLYDE Unity
|
|
219
|
+
*
|
|
220
|
+
* Provides voice interaction capabilities with GLYDE AI agents through Deepgram Voice API.
|
|
221
|
+
* Supports multiple authentication methods: publishableKey, apiKey, and JWT token.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* // Using publishable key (external apps)
|
|
225
|
+
* const voice = new GlydeVoice({
|
|
226
|
+
* publishableKey: 'pk_...',
|
|
227
|
+
* contextType: 'screening',
|
|
228
|
+
* contextId: 'application-uuid'
|
|
229
|
+
* });
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* // Using JWT token (GLYDEBuddy Teams app)
|
|
233
|
+
* const voice = new GlydeVoice({
|
|
234
|
+
* authToken: userSession.accessToken,
|
|
235
|
+
* contextType: 'recruiter'
|
|
236
|
+
* });
|
|
237
|
+
*/
|
|
238
|
+
/**
|
|
239
|
+
* Voice context types supported by the voice agent
|
|
240
|
+
*/
|
|
241
|
+
export declare type VoiceContextType = 'screening' | 'recruiter' | 'custom' | 'phone';
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Voice events emitted by the agent
|
|
245
|
+
*/
|
|
27
246
|
export declare interface VoiceEvent {
|
|
28
|
-
type: 'open' | 'close' | 'error' | 'transcript' | 'agent_audio';
|
|
29
|
-
payload?:
|
|
247
|
+
type: 'open' | 'close' | 'error' | 'ready' | 'user_speaking' | 'agent_speaking' | 'microphone_ready' | 'transcript' | 'agent_audio';
|
|
248
|
+
payload?: unknown;
|
|
30
249
|
}
|
|
31
250
|
|
|
32
251
|
export { }
|