@micdrop/client 1.5.0 → 1.7.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/README.md CHANGED
@@ -47,8 +47,8 @@ call.params = {
47
47
  call.on('StateChange', () => {
48
48
  console.log('State changed')
49
49
  })
50
- call.on('EndInterview', () => {
51
- console.log('Interview ended')
50
+ call.on('EndCall', () => {
51
+ console.log('Call ended by assistant')
52
52
  })
53
53
  call.on('Error', (error) => {
54
54
  console.error('Error occurred:', error)
package/dist/index.d.mts CHANGED
@@ -17,7 +17,6 @@ declare class AudioAnalyser extends EventEmitter<AudioAnalyserEvents> {
17
17
 
18
18
  declare let mic: Mic;
19
19
  declare class Mic {
20
- defaultThreshold: number;
21
20
  private currentDeviceId;
22
21
  private audioStream;
23
22
  private sourceNode;
@@ -53,12 +52,6 @@ interface VADEvents {
53
52
  */
54
53
  declare abstract class VAD extends EventEmitter<VADEvents> {
55
54
  delay: number;
56
- protected threshold: number;
57
- /**
58
- * Constructor for the VAD class
59
- * @param threshold - The threshold to use for the VAD
60
- */
61
- constructor(threshold?: number);
62
55
  /**
63
56
  * Checks if the VAD is started
64
57
  * @returns True if the VAD is started, false otherwise
@@ -67,27 +60,22 @@ declare abstract class VAD extends EventEmitter<VADEvents> {
67
60
  /**
68
61
  * Starts the VAD
69
62
  * @param stream - The stream to start the VAD on
70
- * @param threshold - The threshold to use for the VAD
71
63
  */
72
- abstract start(stream: MediaStream, threshold?: number): Promise<void>;
64
+ abstract start(stream: MediaStream): Promise<void>;
73
65
  /**
74
66
  * Stops the VAD
75
67
  */
76
68
  abstract stop(): Promise<void>;
77
- /**
78
- * Sets the threshold for the VAD
79
- * @param threshold - The threshold to use for the VAD
80
- */
81
- abstract setThreshold(threshold: number): Promise<void>;
82
69
  }
83
70
 
84
- type MicRecorderVAD = VAD | 'volume' | 'silero';
71
+ type VADConfigName = 'volume' | 'silero';
72
+ type VADConfig = VAD | VADConfigName | Array<VAD | VADConfigName>;
73
+
85
74
  interface MicRecorderState {
86
75
  isStarting: boolean;
87
76
  isStarted: boolean;
88
77
  isMuted: boolean;
89
78
  isSpeaking: boolean;
90
- threshold: number;
91
79
  }
92
80
  interface MicRecorderEvents {
93
81
  Chunk: [Blob];
@@ -96,21 +84,18 @@ interface MicRecorderEvents {
96
84
  StateChange: [MicRecorderState];
97
85
  }
98
86
  declare class MicRecorder extends EventEmitter<MicRecorderEvents> {
99
- private vadConfig?;
100
87
  state: MicRecorderState;
101
88
  private audioInfo;
102
- private vad?;
89
+ private vad;
103
90
  private recorder;
104
91
  private delayedStream;
105
92
  private speakingConfirmed;
106
93
  private queuedChunks;
107
- constructor(vadConfig?: MicRecorderVAD | undefined);
94
+ constructor(vadConfig?: VADConfig);
108
95
  start(stream: MediaStream): Promise<void>;
109
96
  mute(): void;
110
97
  unmute(): void;
111
98
  stop(): void;
112
- setThreshold(threshold: number): void;
113
- private initVAD;
114
99
  private startSpeakingDetection;
115
100
  private stopSpeakingDetection;
116
101
  private onStartSpeaking;
@@ -150,41 +135,71 @@ declare global {
150
135
  declare enum LocalStorageKeys {
151
136
  MicDevice = "micdrop.micDevice",
152
137
  SpeakerDevice = "micdrop.speakerDevice",
153
- MicThreshold = "micdrop.micThreshold"
138
+ VolumeVADOptions = "micdrop.VolumeVADOptions",
139
+ SileroVADOptions = "micdrop.SileroVADOptions"
140
+ }
141
+
142
+ /**
143
+ * Combine an array of VADs
144
+ */
145
+ declare class MultipleVAD extends VAD {
146
+ vads: VAD[];
147
+ private startSpeakingCount;
148
+ private confirmSpeakingCount;
149
+ private lastEventName;
150
+ constructor(vads: Array<VAD | VADConfigName>);
151
+ emit(eventName: keyof VADEvents, ..._: any[]): boolean;
152
+ get isStarted(): boolean;
153
+ start(stream: MediaStream, threshold?: number): Promise<void>;
154
+ stop(): Promise<void>;
154
155
  }
155
156
 
157
+ type SileroVADOptions = {
158
+ positiveSpeechThreshold: number;
159
+ negativeSpeechThreshold: number;
160
+ minSpeechFrames: number;
161
+ redemptionFrames: number;
162
+ };
156
163
  /**
157
164
  * Silero VAD
158
165
  * @see https://github.com/ricky0123/vad
159
166
  */
160
167
  declare class SileroVAD extends VAD {
168
+ options: SileroVADOptions;
161
169
  private vad;
170
+ constructor(options?: Partial<SileroVADOptions>);
162
171
  get isStarted(): boolean;
163
- start(stream: MediaStream, threshold?: number): Promise<void>;
172
+ start(stream: MediaStream): Promise<void>;
164
173
  stop(): Promise<void>;
165
- setThreshold(threshold: number): Promise<void>;
174
+ setOptions(options: Partial<SileroVADOptions>): void;
175
+ resetOptions(): void;
166
176
  }
167
177
 
178
+ type VolumeVADOptions = {
179
+ history: number;
180
+ threshold: number;
181
+ };
168
182
  /**
169
183
  * Volume-based Voice Activity Detection
170
184
  * Based on the hark library implementation
171
185
  */
172
186
  declare class VolumeVAD extends VAD {
187
+ options: VolumeVADOptions;
173
188
  private analyser;
174
189
  private sourceNode;
175
190
  private fftBins;
176
191
  private running;
177
192
  private speaking;
178
193
  private attemptSpeaking;
179
- private history;
180
194
  private speakingHistory;
181
- constructor();
195
+ constructor(options?: Partial<VolumeVADOptions>);
182
196
  private getMaxVolume;
183
197
  get isStarted(): boolean;
184
- start(stream: MediaStream, threshold?: number): Promise<void>;
198
+ start(stream: MediaStream): Promise<void>;
185
199
  private startLoop;
186
200
  stop(): Promise<void>;
187
- setThreshold(threshold: number): Promise<void>;
201
+ setOptions(options: Partial<VolumeVADOptions>): void;
202
+ resetOptions(): void;
188
203
  }
189
204
 
190
205
  declare enum CallHandlerErrorCode {
@@ -198,24 +213,25 @@ declare class CallHandlerError extends Error {
198
213
  }
199
214
 
200
215
  interface CallHandlerEvents {
201
- EndInterview: [];
216
+ EndCall: [];
202
217
  Error: [CallHandlerError];
203
218
  StateChange: void;
204
219
  }
205
220
  interface CallHandlerOptions {
206
- vad?: MicRecorderVAD;
221
+ vad?: VADConfig;
207
222
  }
208
223
  declare global {
209
224
  interface Window {
210
- micdropCallHandler: CallHandler<any>;
225
+ micdropCallHandler: any;
211
226
  }
212
227
  }
213
228
  declare class CallHandler<Params extends {}, Options extends CallHandlerOptions = CallHandlerOptions> extends EventEmitter<CallHandlerEvents> {
214
229
  private options?;
215
- static getInstance<T extends {}, Options extends CallHandlerOptions = CallHandlerOptions>(options?: Options): CallHandler<T, Options>;
230
+ static getInstance<P extends {}, O extends CallHandlerOptions = CallHandlerOptions>(options?: O): CallHandler<P, O>;
216
231
  url?: string;
217
232
  params?: Params;
218
233
  micRecorder?: MicRecorder;
234
+ vad: VAD;
219
235
  conversation: Conversation;
220
236
  debug: boolean;
221
237
  private ws?;
@@ -231,7 +247,6 @@ declare class CallHandler<Params extends {}, Options extends CallHandlerOptions
231
247
  get isMicStarted(): boolean;
232
248
  get isMicMuted(): boolean;
233
249
  get isMicSpeaking(): boolean;
234
- get micThreshold(): number;
235
250
  get isProcessing(): boolean;
236
251
  start(): Promise<void>;
237
252
  stop(): Promise<void>;
@@ -247,15 +262,17 @@ declare class CallHandler<Params extends {}, Options extends CallHandlerOptions
247
262
  }
248
263
 
249
264
  declare enum CallClientCommands {
250
- StartSpeaking = "startSpeaking",
251
- StopSpeaking = "stopSpeaking",
252
- Mute = "mute"
265
+ StartSpeaking = "StartSpeaking",
266
+ StopSpeaking = "StopSpeaking",
267
+ Mute = "Mute"
253
268
  }
254
269
  declare enum CallServerCommands {
255
- Message = "message",
256
- CancelLastAssistantMessage = "cancelLastAssistantMessage",
257
- EnableSpeakerStreaming = "enableSpeakerStreaming",
258
- EndInterview = "endInterview"
270
+ Message = "Message",
271
+ CancelLastAssistantMessage = "CancelLastAssistantMessage",
272
+ CancelLastUserMessage = "CancelLastUserMessage",
273
+ SkipAnswer = "SkipAnswer",
274
+ EnableSpeakerStreaming = "EnableSpeakerStreaming",
275
+ EndCall = "EndCall"
259
276
  }
260
277
  interface CallConfig {
261
278
  systemPrompt: string;
@@ -274,10 +291,18 @@ interface CallSummary {
274
291
  duration: number;
275
292
  }
276
293
  type Conversation = ConversationMessage[];
277
- interface ConversationMessage<Data = any> {
294
+ type CallMetadata = {
295
+ commands?: {
296
+ endCall?: boolean;
297
+ cancelLastUserMessage?: boolean;
298
+ skipAnswer?: boolean;
299
+ };
300
+ [key: string]: any;
301
+ };
302
+ interface ConversationMessage<Data extends CallMetadata = CallMetadata> {
278
303
  role: 'system' | 'user' | 'assistant';
279
304
  content: string;
280
305
  metadata?: Data;
281
306
  }
282
307
 
283
- export { CallClientCommands, type CallConfig, CallHandler, CallHandlerError, CallHandlerErrorCode, type CallHandlerEvents, type CallHandlerOptions, CallServerCommands, type CallSummary, type Conversation, type ConversationMessage, LocalStorageKeys, mic as Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, type MicRecorderVAD, SileroVAD, speaker as Speaker, VAD, VolumeVAD };
308
+ export { CallClientCommands, type CallConfig, CallHandler, CallHandlerError, CallHandlerErrorCode, type CallHandlerEvents, type CallHandlerOptions, type CallMetadata, CallServerCommands, type CallSummary, type Conversation, type ConversationMessage, LocalStorageKeys, mic as Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, MultipleVAD, SileroVAD, type SileroVADOptions, speaker as Speaker, VAD, type VADEvents, VolumeVAD, type VolumeVADOptions };
package/dist/index.d.ts CHANGED
@@ -17,7 +17,6 @@ declare class AudioAnalyser extends EventEmitter<AudioAnalyserEvents> {
17
17
 
18
18
  declare let mic: Mic;
19
19
  declare class Mic {
20
- defaultThreshold: number;
21
20
  private currentDeviceId;
22
21
  private audioStream;
23
22
  private sourceNode;
@@ -53,12 +52,6 @@ interface VADEvents {
53
52
  */
54
53
  declare abstract class VAD extends EventEmitter<VADEvents> {
55
54
  delay: number;
56
- protected threshold: number;
57
- /**
58
- * Constructor for the VAD class
59
- * @param threshold - The threshold to use for the VAD
60
- */
61
- constructor(threshold?: number);
62
55
  /**
63
56
  * Checks if the VAD is started
64
57
  * @returns True if the VAD is started, false otherwise
@@ -67,27 +60,22 @@ declare abstract class VAD extends EventEmitter<VADEvents> {
67
60
  /**
68
61
  * Starts the VAD
69
62
  * @param stream - The stream to start the VAD on
70
- * @param threshold - The threshold to use for the VAD
71
63
  */
72
- abstract start(stream: MediaStream, threshold?: number): Promise<void>;
64
+ abstract start(stream: MediaStream): Promise<void>;
73
65
  /**
74
66
  * Stops the VAD
75
67
  */
76
68
  abstract stop(): Promise<void>;
77
- /**
78
- * Sets the threshold for the VAD
79
- * @param threshold - The threshold to use for the VAD
80
- */
81
- abstract setThreshold(threshold: number): Promise<void>;
82
69
  }
83
70
 
84
- type MicRecorderVAD = VAD | 'volume' | 'silero';
71
+ type VADConfigName = 'volume' | 'silero';
72
+ type VADConfig = VAD | VADConfigName | Array<VAD | VADConfigName>;
73
+
85
74
  interface MicRecorderState {
86
75
  isStarting: boolean;
87
76
  isStarted: boolean;
88
77
  isMuted: boolean;
89
78
  isSpeaking: boolean;
90
- threshold: number;
91
79
  }
92
80
  interface MicRecorderEvents {
93
81
  Chunk: [Blob];
@@ -96,21 +84,18 @@ interface MicRecorderEvents {
96
84
  StateChange: [MicRecorderState];
97
85
  }
98
86
  declare class MicRecorder extends EventEmitter<MicRecorderEvents> {
99
- private vadConfig?;
100
87
  state: MicRecorderState;
101
88
  private audioInfo;
102
- private vad?;
89
+ private vad;
103
90
  private recorder;
104
91
  private delayedStream;
105
92
  private speakingConfirmed;
106
93
  private queuedChunks;
107
- constructor(vadConfig?: MicRecorderVAD | undefined);
94
+ constructor(vadConfig?: VADConfig);
108
95
  start(stream: MediaStream): Promise<void>;
109
96
  mute(): void;
110
97
  unmute(): void;
111
98
  stop(): void;
112
- setThreshold(threshold: number): void;
113
- private initVAD;
114
99
  private startSpeakingDetection;
115
100
  private stopSpeakingDetection;
116
101
  private onStartSpeaking;
@@ -150,41 +135,71 @@ declare global {
150
135
  declare enum LocalStorageKeys {
151
136
  MicDevice = "micdrop.micDevice",
152
137
  SpeakerDevice = "micdrop.speakerDevice",
153
- MicThreshold = "micdrop.micThreshold"
138
+ VolumeVADOptions = "micdrop.VolumeVADOptions",
139
+ SileroVADOptions = "micdrop.SileroVADOptions"
140
+ }
141
+
142
+ /**
143
+ * Combine an array of VADs
144
+ */
145
+ declare class MultipleVAD extends VAD {
146
+ vads: VAD[];
147
+ private startSpeakingCount;
148
+ private confirmSpeakingCount;
149
+ private lastEventName;
150
+ constructor(vads: Array<VAD | VADConfigName>);
151
+ emit(eventName: keyof VADEvents, ..._: any[]): boolean;
152
+ get isStarted(): boolean;
153
+ start(stream: MediaStream, threshold?: number): Promise<void>;
154
+ stop(): Promise<void>;
154
155
  }
155
156
 
157
+ type SileroVADOptions = {
158
+ positiveSpeechThreshold: number;
159
+ negativeSpeechThreshold: number;
160
+ minSpeechFrames: number;
161
+ redemptionFrames: number;
162
+ };
156
163
  /**
157
164
  * Silero VAD
158
165
  * @see https://github.com/ricky0123/vad
159
166
  */
160
167
  declare class SileroVAD extends VAD {
168
+ options: SileroVADOptions;
161
169
  private vad;
170
+ constructor(options?: Partial<SileroVADOptions>);
162
171
  get isStarted(): boolean;
163
- start(stream: MediaStream, threshold?: number): Promise<void>;
172
+ start(stream: MediaStream): Promise<void>;
164
173
  stop(): Promise<void>;
165
- setThreshold(threshold: number): Promise<void>;
174
+ setOptions(options: Partial<SileroVADOptions>): void;
175
+ resetOptions(): void;
166
176
  }
167
177
 
178
+ type VolumeVADOptions = {
179
+ history: number;
180
+ threshold: number;
181
+ };
168
182
  /**
169
183
  * Volume-based Voice Activity Detection
170
184
  * Based on the hark library implementation
171
185
  */
172
186
  declare class VolumeVAD extends VAD {
187
+ options: VolumeVADOptions;
173
188
  private analyser;
174
189
  private sourceNode;
175
190
  private fftBins;
176
191
  private running;
177
192
  private speaking;
178
193
  private attemptSpeaking;
179
- private history;
180
194
  private speakingHistory;
181
- constructor();
195
+ constructor(options?: Partial<VolumeVADOptions>);
182
196
  private getMaxVolume;
183
197
  get isStarted(): boolean;
184
- start(stream: MediaStream, threshold?: number): Promise<void>;
198
+ start(stream: MediaStream): Promise<void>;
185
199
  private startLoop;
186
200
  stop(): Promise<void>;
187
- setThreshold(threshold: number): Promise<void>;
201
+ setOptions(options: Partial<VolumeVADOptions>): void;
202
+ resetOptions(): void;
188
203
  }
189
204
 
190
205
  declare enum CallHandlerErrorCode {
@@ -198,24 +213,25 @@ declare class CallHandlerError extends Error {
198
213
  }
199
214
 
200
215
  interface CallHandlerEvents {
201
- EndInterview: [];
216
+ EndCall: [];
202
217
  Error: [CallHandlerError];
203
218
  StateChange: void;
204
219
  }
205
220
  interface CallHandlerOptions {
206
- vad?: MicRecorderVAD;
221
+ vad?: VADConfig;
207
222
  }
208
223
  declare global {
209
224
  interface Window {
210
- micdropCallHandler: CallHandler<any>;
225
+ micdropCallHandler: any;
211
226
  }
212
227
  }
213
228
  declare class CallHandler<Params extends {}, Options extends CallHandlerOptions = CallHandlerOptions> extends EventEmitter<CallHandlerEvents> {
214
229
  private options?;
215
- static getInstance<T extends {}, Options extends CallHandlerOptions = CallHandlerOptions>(options?: Options): CallHandler<T, Options>;
230
+ static getInstance<P extends {}, O extends CallHandlerOptions = CallHandlerOptions>(options?: O): CallHandler<P, O>;
216
231
  url?: string;
217
232
  params?: Params;
218
233
  micRecorder?: MicRecorder;
234
+ vad: VAD;
219
235
  conversation: Conversation;
220
236
  debug: boolean;
221
237
  private ws?;
@@ -231,7 +247,6 @@ declare class CallHandler<Params extends {}, Options extends CallHandlerOptions
231
247
  get isMicStarted(): boolean;
232
248
  get isMicMuted(): boolean;
233
249
  get isMicSpeaking(): boolean;
234
- get micThreshold(): number;
235
250
  get isProcessing(): boolean;
236
251
  start(): Promise<void>;
237
252
  stop(): Promise<void>;
@@ -247,15 +262,17 @@ declare class CallHandler<Params extends {}, Options extends CallHandlerOptions
247
262
  }
248
263
 
249
264
  declare enum CallClientCommands {
250
- StartSpeaking = "startSpeaking",
251
- StopSpeaking = "stopSpeaking",
252
- Mute = "mute"
265
+ StartSpeaking = "StartSpeaking",
266
+ StopSpeaking = "StopSpeaking",
267
+ Mute = "Mute"
253
268
  }
254
269
  declare enum CallServerCommands {
255
- Message = "message",
256
- CancelLastAssistantMessage = "cancelLastAssistantMessage",
257
- EnableSpeakerStreaming = "enableSpeakerStreaming",
258
- EndInterview = "endInterview"
270
+ Message = "Message",
271
+ CancelLastAssistantMessage = "CancelLastAssistantMessage",
272
+ CancelLastUserMessage = "CancelLastUserMessage",
273
+ SkipAnswer = "SkipAnswer",
274
+ EnableSpeakerStreaming = "EnableSpeakerStreaming",
275
+ EndCall = "EndCall"
259
276
  }
260
277
  interface CallConfig {
261
278
  systemPrompt: string;
@@ -274,10 +291,18 @@ interface CallSummary {
274
291
  duration: number;
275
292
  }
276
293
  type Conversation = ConversationMessage[];
277
- interface ConversationMessage<Data = any> {
294
+ type CallMetadata = {
295
+ commands?: {
296
+ endCall?: boolean;
297
+ cancelLastUserMessage?: boolean;
298
+ skipAnswer?: boolean;
299
+ };
300
+ [key: string]: any;
301
+ };
302
+ interface ConversationMessage<Data extends CallMetadata = CallMetadata> {
278
303
  role: 'system' | 'user' | 'assistant';
279
304
  content: string;
280
305
  metadata?: Data;
281
306
  }
282
307
 
283
- export { CallClientCommands, type CallConfig, CallHandler, CallHandlerError, CallHandlerErrorCode, type CallHandlerEvents, type CallHandlerOptions, CallServerCommands, type CallSummary, type Conversation, type ConversationMessage, LocalStorageKeys, mic as Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, type MicRecorderVAD, SileroVAD, speaker as Speaker, VAD, VolumeVAD };
308
+ export { CallClientCommands, type CallConfig, CallHandler, CallHandlerError, CallHandlerErrorCode, type CallHandlerEvents, type CallHandlerOptions, type CallMetadata, CallServerCommands, type CallSummary, type Conversation, type ConversationMessage, LocalStorageKeys, mic as Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, MultipleVAD, SileroVAD, type SileroVADOptions, speaker as Speaker, VAD, type VADEvents, VolumeVAD, type VolumeVADOptions };