@micdrop/client 3.0.0 → 3.1.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.mts +139 -49
- package/dist/index.d.ts +139 -49
- package/dist/index.js +118 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -206,6 +206,75 @@ declare class SpeakerController extends EventEmitter<SpeakerEvents> {
|
|
|
206
206
|
private onVolume;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
declare enum MicdropClientCommands {
|
|
210
|
+
StartSpeaking = "StartSpeaking",
|
|
211
|
+
StopSpeaking = "StopSpeaking",
|
|
212
|
+
Mute = "Mute"
|
|
213
|
+
}
|
|
214
|
+
declare enum MicdropServerCommands {
|
|
215
|
+
Message = "Message",
|
|
216
|
+
CancelLastUserMessage = "CancelLastUserMessage",
|
|
217
|
+
SkipAnswer = "SkipAnswer",
|
|
218
|
+
EndCall = "EndCall",
|
|
219
|
+
ToolCall = "ToolCall"
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Hears whether a sentence has landed, where voice activity detection only
|
|
223
|
+
* hears whether someone is speaking.
|
|
224
|
+
*
|
|
225
|
+
* `SmartTurn` from `@micdrop/smart-turn` implements it, and so can anything
|
|
226
|
+
* else, a call to a service included. Both sides of a call can hold one, the
|
|
227
|
+
* client to decide when its turn ends and the server to decide when to answer.
|
|
228
|
+
*/
|
|
229
|
+
interface TurnDetector {
|
|
230
|
+
/**
|
|
231
|
+
* Feeds the audio received since the last call
|
|
232
|
+
* @param samples - Mono samples, in the -1..1 range
|
|
233
|
+
* @param sampleRate - Sample rate of `samples`, in Hz
|
|
234
|
+
*/
|
|
235
|
+
push(samples: Float32Array, sampleRate?: number): void;
|
|
236
|
+
/** Answers whether the turn pushed so far sounds finished */
|
|
237
|
+
predict(): Promise<{
|
|
238
|
+
complete: boolean;
|
|
239
|
+
}>;
|
|
240
|
+
/** Starts a new turn, forgetting the previous one */
|
|
241
|
+
reset(): void;
|
|
242
|
+
}
|
|
243
|
+
interface MicdropCallSummary {
|
|
244
|
+
conversation: MicdropConversation;
|
|
245
|
+
duration: number;
|
|
246
|
+
}
|
|
247
|
+
type MicdropConversationItem = MicdropConversationMessage | MicdropConversationToolCall | MicdropConversationToolResult;
|
|
248
|
+
type MicdropConversation = Array<MicdropConversationItem>;
|
|
249
|
+
type MicdropAnswerMetadata = {
|
|
250
|
+
[key: string]: any;
|
|
251
|
+
};
|
|
252
|
+
interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
|
|
253
|
+
role: 'system' | 'user' | 'assistant';
|
|
254
|
+
content: string;
|
|
255
|
+
metadata?: Data;
|
|
256
|
+
}
|
|
257
|
+
interface MicdropConversationToolCall {
|
|
258
|
+
role: 'tool_call';
|
|
259
|
+
toolCallId: string;
|
|
260
|
+
toolName: string;
|
|
261
|
+
parameters: string;
|
|
262
|
+
}
|
|
263
|
+
interface MicdropConversationToolResult {
|
|
264
|
+
role: 'tool_result';
|
|
265
|
+
toolCallId: string;
|
|
266
|
+
toolName: string;
|
|
267
|
+
output: string;
|
|
268
|
+
}
|
|
269
|
+
interface MicdropToolCall {
|
|
270
|
+
name: string;
|
|
271
|
+
parameters: any;
|
|
272
|
+
output: any;
|
|
273
|
+
}
|
|
274
|
+
type DeepPartial<T> = T extends object ? {
|
|
275
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
276
|
+
} : T;
|
|
277
|
+
|
|
209
278
|
interface VADEvents {
|
|
210
279
|
StartSpeaking: void;
|
|
211
280
|
ConfirmSpeaking: void;
|
|
@@ -272,6 +341,13 @@ type VADConfig = VAD | VADConfigName | Array<VAD | VADConfigName>;
|
|
|
272
341
|
declare function getVAD(vad?: VADConfig): VAD;
|
|
273
342
|
declare function equalVADConfig(a?: VADConfig, b?: VADConfig): boolean;
|
|
274
343
|
|
|
344
|
+
/**
|
|
345
|
+
* How long a turn may stay open after the detector asked to wait.
|
|
346
|
+
*
|
|
347
|
+
* Long enough to cover the pause of someone looking for their words, and short
|
|
348
|
+
* enough that a wrong verdict costs one awkward silence rather than the call.
|
|
349
|
+
*/
|
|
350
|
+
declare const DEFAULT_TURN_MAX_WAIT = 4000;
|
|
275
351
|
interface MicRecorderState {
|
|
276
352
|
isStarting: boolean;
|
|
277
353
|
isStarted: boolean;
|
|
@@ -288,9 +364,22 @@ interface MicRecorderEvents {
|
|
|
288
364
|
*
|
|
289
365
|
* It only records while the VAD hears someone, and keeps a short reserve of
|
|
290
366
|
* audio so the first syllable, spoken before the VAD reacted, is sent too.
|
|
367
|
+
*
|
|
368
|
+
* Recording and the turn are two different things. The VAD decides what is
|
|
369
|
+
* worth sending, so the silences stay out of the stream either way. A
|
|
370
|
+
* {@link TurnDetector}, when there is one, decides when the turn is over, and
|
|
371
|
+
* a pause the speaker is about to fill leaves it open.
|
|
291
372
|
*/
|
|
292
373
|
declare class MicRecorder extends EventEmitter<MicRecorderEvents> {
|
|
293
374
|
private vadConfig?;
|
|
375
|
+
private turnDetector?;
|
|
376
|
+
/**
|
|
377
|
+
* How long a turn stays open once the detector asked to wait.
|
|
378
|
+
*
|
|
379
|
+
* The way out of a detector that hears an unfinished sentence where there
|
|
380
|
+
* is none: the speaker who never comes back still gets an answer.
|
|
381
|
+
*/
|
|
382
|
+
turnMaxWait: number;
|
|
294
383
|
state: MicRecorderState;
|
|
295
384
|
vad: VAD;
|
|
296
385
|
private mic;
|
|
@@ -302,15 +391,41 @@ declare class MicRecorder extends EventEmitter<MicRecorderEvents> {
|
|
|
302
391
|
private buffer;
|
|
303
392
|
private bufferLength;
|
|
304
393
|
private queuedChunks;
|
|
305
|
-
|
|
394
|
+
private turnOpen;
|
|
395
|
+
private turnListening;
|
|
396
|
+
private turnTimer;
|
|
397
|
+
private turnRound;
|
|
398
|
+
constructor(vadConfig?: VADConfig | undefined, turnDetector?: TurnDetector | undefined,
|
|
399
|
+
/**
|
|
400
|
+
* How long a turn stays open once the detector asked to wait.
|
|
401
|
+
*
|
|
402
|
+
* The way out of a detector that hears an unfinished sentence where there
|
|
403
|
+
* is none: the speaker who never comes back still gets an answer.
|
|
404
|
+
*/
|
|
405
|
+
turnMaxWait?: number);
|
|
306
406
|
start: (mic: MicSource) => Promise<void>;
|
|
307
407
|
stop: () => void;
|
|
408
|
+
/**
|
|
409
|
+
* Changes what decides when a turn is over
|
|
410
|
+
* @param turnDetector - The new detector, or nothing to leave it to the VAD
|
|
411
|
+
*/
|
|
412
|
+
changeTurnDetector: (turnDetector?: TurnDetector) => void;
|
|
308
413
|
changeVad: (vadConfig: VADConfig) => void;
|
|
309
414
|
private onFrames;
|
|
310
415
|
private onStartSpeaking;
|
|
311
416
|
private onConfirmSpeaking;
|
|
312
417
|
private onCancelSpeaking;
|
|
313
418
|
private onStopSpeaking;
|
|
419
|
+
/**
|
|
420
|
+
* Ends the turn, unless the detector hears an unfinished sentence.
|
|
421
|
+
*
|
|
422
|
+
* A microphone that is no longer listening ends it straight away: a muted or
|
|
423
|
+
* paused call has nothing more to say, whatever the sentence sounded like.
|
|
424
|
+
*/
|
|
425
|
+
private closeTurn;
|
|
426
|
+
private endTurn;
|
|
427
|
+
/** Drops the pending close, both the timer and the answer still owed */
|
|
428
|
+
private cancelPendingClose;
|
|
314
429
|
private stopRecording;
|
|
315
430
|
/**
|
|
316
431
|
* Emits every complete chunk waiting in the buffer
|
|
@@ -581,53 +696,6 @@ declare function getVolume(samples: Float32Array): number;
|
|
|
581
696
|
declare const Mic: MicController;
|
|
582
697
|
declare const Speaker: SpeakerController;
|
|
583
698
|
|
|
584
|
-
declare enum MicdropClientCommands {
|
|
585
|
-
StartSpeaking = "StartSpeaking",
|
|
586
|
-
StopSpeaking = "StopSpeaking",
|
|
587
|
-
Mute = "Mute"
|
|
588
|
-
}
|
|
589
|
-
declare enum MicdropServerCommands {
|
|
590
|
-
Message = "Message",
|
|
591
|
-
CancelLastUserMessage = "CancelLastUserMessage",
|
|
592
|
-
SkipAnswer = "SkipAnswer",
|
|
593
|
-
EndCall = "EndCall",
|
|
594
|
-
ToolCall = "ToolCall"
|
|
595
|
-
}
|
|
596
|
-
interface MicdropCallSummary {
|
|
597
|
-
conversation: MicdropConversation;
|
|
598
|
-
duration: number;
|
|
599
|
-
}
|
|
600
|
-
type MicdropConversationItem = MicdropConversationMessage | MicdropConversationToolCall | MicdropConversationToolResult;
|
|
601
|
-
type MicdropConversation = Array<MicdropConversationItem>;
|
|
602
|
-
type MicdropAnswerMetadata = {
|
|
603
|
-
[key: string]: any;
|
|
604
|
-
};
|
|
605
|
-
interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
|
|
606
|
-
role: 'system' | 'user' | 'assistant';
|
|
607
|
-
content: string;
|
|
608
|
-
metadata?: Data;
|
|
609
|
-
}
|
|
610
|
-
interface MicdropConversationToolCall {
|
|
611
|
-
role: 'tool_call';
|
|
612
|
-
toolCallId: string;
|
|
613
|
-
toolName: string;
|
|
614
|
-
parameters: string;
|
|
615
|
-
}
|
|
616
|
-
interface MicdropConversationToolResult {
|
|
617
|
-
role: 'tool_result';
|
|
618
|
-
toolCallId: string;
|
|
619
|
-
toolName: string;
|
|
620
|
-
output: string;
|
|
621
|
-
}
|
|
622
|
-
interface MicdropToolCall {
|
|
623
|
-
name: string;
|
|
624
|
-
parameters: any;
|
|
625
|
-
output: any;
|
|
626
|
-
}
|
|
627
|
-
type DeepPartial<T> = T extends object ? {
|
|
628
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
629
|
-
} : T;
|
|
630
|
-
|
|
631
699
|
declare enum MicdropClientErrorCode {
|
|
632
700
|
MissingUrl = "MissingUrl",
|
|
633
701
|
Mic = "Mic",
|
|
@@ -666,6 +734,14 @@ interface MicdropOptions {
|
|
|
666
734
|
url?: string;
|
|
667
735
|
params?: Record<string, any>;
|
|
668
736
|
vad?: VADConfig;
|
|
737
|
+
/**
|
|
738
|
+
* Holds the turn open while the sentence sounds unfinished, so a hesitation
|
|
739
|
+
* no longer counts as the end of a question. Without one, a turn ends as
|
|
740
|
+
* soon as the VAD hears enough silence.
|
|
741
|
+
*/
|
|
742
|
+
turnDetector?: TurnDetector;
|
|
743
|
+
/** How long a turn may stay open after the detector asked to wait */
|
|
744
|
+
turnMaxWait?: number;
|
|
669
745
|
disableInterruption?: boolean;
|
|
670
746
|
debugLog?: boolean;
|
|
671
747
|
reconnect?: MicdropReconnectOptions;
|
|
@@ -734,6 +810,20 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
|
|
|
734
810
|
vad?: VADConfig;
|
|
735
811
|
deviceId?: string;
|
|
736
812
|
}) => Promise<void>;
|
|
813
|
+
/**
|
|
814
|
+
* Changes what decides when a turn is over, during a call or before one
|
|
815
|
+
* @param turnDetector - The new detector, or nothing to leave it to the VAD
|
|
816
|
+
*/
|
|
817
|
+
setTurnDetector: (turnDetector?: TurnDetector) => void;
|
|
818
|
+
/**
|
|
819
|
+
* Says how long a held turn waits for the rest of the sentence.
|
|
820
|
+
*
|
|
821
|
+
* The way out of a wrong verdict: a detector can hear an unfinished sentence
|
|
822
|
+
* where there is none, and the speaker who never comes back still gets an
|
|
823
|
+
* answer once this runs out.
|
|
824
|
+
* @param milliseconds - How long to wait past the detector asking to
|
|
825
|
+
*/
|
|
826
|
+
setTurnMaxWait: (milliseconds: number) => void;
|
|
737
827
|
changeMicDevice: (deviceId: string) => Promise<void>;
|
|
738
828
|
changeSpeakerDevice: (deviceId: string) => Promise<void>;
|
|
739
829
|
private stopMic;
|
|
@@ -779,4 +869,4 @@ declare enum MicdropStorageKeys {
|
|
|
779
869
|
declare function setMicdropStorage(storage: MicdropStorage): void;
|
|
780
870
|
declare const storage: MicdropStorage;
|
|
781
871
|
|
|
782
|
-
export { type AudioSink, type DeepPartial, Mic, MicController, MicDriver, type MicDriverEvents, type MicEvents, MicRecorder, type MicRecorderEvents, type MicRecorderState, type MicSource, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConversation, type MicdropConversationItem, type MicdropConversationMessage, type MicdropConversationToolCall, type MicdropConversationToolResult, type MicdropDevice, type MicdropEvents, type MicdropOptions, type MicdropReconnectOptions, MicdropServerCommands, type MicdropState, type MicdropStorage, MicdropStorageKeys, type MicdropToolCall, MultipleVAD, Pcm16AudioStream, type Pcm16AudioStreamEvents, SILERO_FRAME_SAMPLES, SILERO_SAMPLE_RATE, type ScheduledAudio, type SileroModel, type SileroModelLoader, SileroVAD, type SileroVADOptions, Speaker, SpeakerController, SpeakerDriver, type SpeakerDriverEvents, type SpeakerEvents, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VOLUME_SAMPLE_RATE, VolumeMeter, VolumeVAD, type VolumeVADOptions, type WSCloseEvent, concatFloat32, equalVADConfig, floatToPcm16, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD, getVolume, isRecoverableError, pcm16ToArrayBuffer, pcm16ToFloat, resample, setMicdropStorage, setSileroModelLoader, storage };
|
|
872
|
+
export { type AudioSink, DEFAULT_TURN_MAX_WAIT, type DeepPartial, Mic, MicController, MicDriver, type MicDriverEvents, type MicEvents, MicRecorder, type MicRecorderEvents, type MicRecorderState, type MicSource, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConversation, type MicdropConversationItem, type MicdropConversationMessage, type MicdropConversationToolCall, type MicdropConversationToolResult, type MicdropDevice, type MicdropEvents, type MicdropOptions, type MicdropReconnectOptions, MicdropServerCommands, type MicdropState, type MicdropStorage, MicdropStorageKeys, type MicdropToolCall, MultipleVAD, Pcm16AudioStream, type Pcm16AudioStreamEvents, SILERO_FRAME_SAMPLES, SILERO_SAMPLE_RATE, type ScheduledAudio, type SileroModel, type SileroModelLoader, SileroVAD, type SileroVADOptions, Speaker, SpeakerController, SpeakerDriver, type SpeakerDriverEvents, type SpeakerEvents, type TurnDetector, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VOLUME_SAMPLE_RATE, VolumeMeter, VolumeVAD, type VolumeVADOptions, type WSCloseEvent, concatFloat32, equalVADConfig, floatToPcm16, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD, getVolume, isRecoverableError, pcm16ToArrayBuffer, pcm16ToFloat, resample, setMicdropStorage, setSileroModelLoader, storage };
|
package/dist/index.d.ts
CHANGED
|
@@ -206,6 +206,75 @@ declare class SpeakerController extends EventEmitter<SpeakerEvents> {
|
|
|
206
206
|
private onVolume;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
declare enum MicdropClientCommands {
|
|
210
|
+
StartSpeaking = "StartSpeaking",
|
|
211
|
+
StopSpeaking = "StopSpeaking",
|
|
212
|
+
Mute = "Mute"
|
|
213
|
+
}
|
|
214
|
+
declare enum MicdropServerCommands {
|
|
215
|
+
Message = "Message",
|
|
216
|
+
CancelLastUserMessage = "CancelLastUserMessage",
|
|
217
|
+
SkipAnswer = "SkipAnswer",
|
|
218
|
+
EndCall = "EndCall",
|
|
219
|
+
ToolCall = "ToolCall"
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Hears whether a sentence has landed, where voice activity detection only
|
|
223
|
+
* hears whether someone is speaking.
|
|
224
|
+
*
|
|
225
|
+
* `SmartTurn` from `@micdrop/smart-turn` implements it, and so can anything
|
|
226
|
+
* else, a call to a service included. Both sides of a call can hold one, the
|
|
227
|
+
* client to decide when its turn ends and the server to decide when to answer.
|
|
228
|
+
*/
|
|
229
|
+
interface TurnDetector {
|
|
230
|
+
/**
|
|
231
|
+
* Feeds the audio received since the last call
|
|
232
|
+
* @param samples - Mono samples, in the -1..1 range
|
|
233
|
+
* @param sampleRate - Sample rate of `samples`, in Hz
|
|
234
|
+
*/
|
|
235
|
+
push(samples: Float32Array, sampleRate?: number): void;
|
|
236
|
+
/** Answers whether the turn pushed so far sounds finished */
|
|
237
|
+
predict(): Promise<{
|
|
238
|
+
complete: boolean;
|
|
239
|
+
}>;
|
|
240
|
+
/** Starts a new turn, forgetting the previous one */
|
|
241
|
+
reset(): void;
|
|
242
|
+
}
|
|
243
|
+
interface MicdropCallSummary {
|
|
244
|
+
conversation: MicdropConversation;
|
|
245
|
+
duration: number;
|
|
246
|
+
}
|
|
247
|
+
type MicdropConversationItem = MicdropConversationMessage | MicdropConversationToolCall | MicdropConversationToolResult;
|
|
248
|
+
type MicdropConversation = Array<MicdropConversationItem>;
|
|
249
|
+
type MicdropAnswerMetadata = {
|
|
250
|
+
[key: string]: any;
|
|
251
|
+
};
|
|
252
|
+
interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
|
|
253
|
+
role: 'system' | 'user' | 'assistant';
|
|
254
|
+
content: string;
|
|
255
|
+
metadata?: Data;
|
|
256
|
+
}
|
|
257
|
+
interface MicdropConversationToolCall {
|
|
258
|
+
role: 'tool_call';
|
|
259
|
+
toolCallId: string;
|
|
260
|
+
toolName: string;
|
|
261
|
+
parameters: string;
|
|
262
|
+
}
|
|
263
|
+
interface MicdropConversationToolResult {
|
|
264
|
+
role: 'tool_result';
|
|
265
|
+
toolCallId: string;
|
|
266
|
+
toolName: string;
|
|
267
|
+
output: string;
|
|
268
|
+
}
|
|
269
|
+
interface MicdropToolCall {
|
|
270
|
+
name: string;
|
|
271
|
+
parameters: any;
|
|
272
|
+
output: any;
|
|
273
|
+
}
|
|
274
|
+
type DeepPartial<T> = T extends object ? {
|
|
275
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
276
|
+
} : T;
|
|
277
|
+
|
|
209
278
|
interface VADEvents {
|
|
210
279
|
StartSpeaking: void;
|
|
211
280
|
ConfirmSpeaking: void;
|
|
@@ -272,6 +341,13 @@ type VADConfig = VAD | VADConfigName | Array<VAD | VADConfigName>;
|
|
|
272
341
|
declare function getVAD(vad?: VADConfig): VAD;
|
|
273
342
|
declare function equalVADConfig(a?: VADConfig, b?: VADConfig): boolean;
|
|
274
343
|
|
|
344
|
+
/**
|
|
345
|
+
* How long a turn may stay open after the detector asked to wait.
|
|
346
|
+
*
|
|
347
|
+
* Long enough to cover the pause of someone looking for their words, and short
|
|
348
|
+
* enough that a wrong verdict costs one awkward silence rather than the call.
|
|
349
|
+
*/
|
|
350
|
+
declare const DEFAULT_TURN_MAX_WAIT = 4000;
|
|
275
351
|
interface MicRecorderState {
|
|
276
352
|
isStarting: boolean;
|
|
277
353
|
isStarted: boolean;
|
|
@@ -288,9 +364,22 @@ interface MicRecorderEvents {
|
|
|
288
364
|
*
|
|
289
365
|
* It only records while the VAD hears someone, and keeps a short reserve of
|
|
290
366
|
* audio so the first syllable, spoken before the VAD reacted, is sent too.
|
|
367
|
+
*
|
|
368
|
+
* Recording and the turn are two different things. The VAD decides what is
|
|
369
|
+
* worth sending, so the silences stay out of the stream either way. A
|
|
370
|
+
* {@link TurnDetector}, when there is one, decides when the turn is over, and
|
|
371
|
+
* a pause the speaker is about to fill leaves it open.
|
|
291
372
|
*/
|
|
292
373
|
declare class MicRecorder extends EventEmitter<MicRecorderEvents> {
|
|
293
374
|
private vadConfig?;
|
|
375
|
+
private turnDetector?;
|
|
376
|
+
/**
|
|
377
|
+
* How long a turn stays open once the detector asked to wait.
|
|
378
|
+
*
|
|
379
|
+
* The way out of a detector that hears an unfinished sentence where there
|
|
380
|
+
* is none: the speaker who never comes back still gets an answer.
|
|
381
|
+
*/
|
|
382
|
+
turnMaxWait: number;
|
|
294
383
|
state: MicRecorderState;
|
|
295
384
|
vad: VAD;
|
|
296
385
|
private mic;
|
|
@@ -302,15 +391,41 @@ declare class MicRecorder extends EventEmitter<MicRecorderEvents> {
|
|
|
302
391
|
private buffer;
|
|
303
392
|
private bufferLength;
|
|
304
393
|
private queuedChunks;
|
|
305
|
-
|
|
394
|
+
private turnOpen;
|
|
395
|
+
private turnListening;
|
|
396
|
+
private turnTimer;
|
|
397
|
+
private turnRound;
|
|
398
|
+
constructor(vadConfig?: VADConfig | undefined, turnDetector?: TurnDetector | undefined,
|
|
399
|
+
/**
|
|
400
|
+
* How long a turn stays open once the detector asked to wait.
|
|
401
|
+
*
|
|
402
|
+
* The way out of a detector that hears an unfinished sentence where there
|
|
403
|
+
* is none: the speaker who never comes back still gets an answer.
|
|
404
|
+
*/
|
|
405
|
+
turnMaxWait?: number);
|
|
306
406
|
start: (mic: MicSource) => Promise<void>;
|
|
307
407
|
stop: () => void;
|
|
408
|
+
/**
|
|
409
|
+
* Changes what decides when a turn is over
|
|
410
|
+
* @param turnDetector - The new detector, or nothing to leave it to the VAD
|
|
411
|
+
*/
|
|
412
|
+
changeTurnDetector: (turnDetector?: TurnDetector) => void;
|
|
308
413
|
changeVad: (vadConfig: VADConfig) => void;
|
|
309
414
|
private onFrames;
|
|
310
415
|
private onStartSpeaking;
|
|
311
416
|
private onConfirmSpeaking;
|
|
312
417
|
private onCancelSpeaking;
|
|
313
418
|
private onStopSpeaking;
|
|
419
|
+
/**
|
|
420
|
+
* Ends the turn, unless the detector hears an unfinished sentence.
|
|
421
|
+
*
|
|
422
|
+
* A microphone that is no longer listening ends it straight away: a muted or
|
|
423
|
+
* paused call has nothing more to say, whatever the sentence sounded like.
|
|
424
|
+
*/
|
|
425
|
+
private closeTurn;
|
|
426
|
+
private endTurn;
|
|
427
|
+
/** Drops the pending close, both the timer and the answer still owed */
|
|
428
|
+
private cancelPendingClose;
|
|
314
429
|
private stopRecording;
|
|
315
430
|
/**
|
|
316
431
|
* Emits every complete chunk waiting in the buffer
|
|
@@ -581,53 +696,6 @@ declare function getVolume(samples: Float32Array): number;
|
|
|
581
696
|
declare const Mic: MicController;
|
|
582
697
|
declare const Speaker: SpeakerController;
|
|
583
698
|
|
|
584
|
-
declare enum MicdropClientCommands {
|
|
585
|
-
StartSpeaking = "StartSpeaking",
|
|
586
|
-
StopSpeaking = "StopSpeaking",
|
|
587
|
-
Mute = "Mute"
|
|
588
|
-
}
|
|
589
|
-
declare enum MicdropServerCommands {
|
|
590
|
-
Message = "Message",
|
|
591
|
-
CancelLastUserMessage = "CancelLastUserMessage",
|
|
592
|
-
SkipAnswer = "SkipAnswer",
|
|
593
|
-
EndCall = "EndCall",
|
|
594
|
-
ToolCall = "ToolCall"
|
|
595
|
-
}
|
|
596
|
-
interface MicdropCallSummary {
|
|
597
|
-
conversation: MicdropConversation;
|
|
598
|
-
duration: number;
|
|
599
|
-
}
|
|
600
|
-
type MicdropConversationItem = MicdropConversationMessage | MicdropConversationToolCall | MicdropConversationToolResult;
|
|
601
|
-
type MicdropConversation = Array<MicdropConversationItem>;
|
|
602
|
-
type MicdropAnswerMetadata = {
|
|
603
|
-
[key: string]: any;
|
|
604
|
-
};
|
|
605
|
-
interface MicdropConversationMessage<Data extends MicdropAnswerMetadata = MicdropAnswerMetadata> {
|
|
606
|
-
role: 'system' | 'user' | 'assistant';
|
|
607
|
-
content: string;
|
|
608
|
-
metadata?: Data;
|
|
609
|
-
}
|
|
610
|
-
interface MicdropConversationToolCall {
|
|
611
|
-
role: 'tool_call';
|
|
612
|
-
toolCallId: string;
|
|
613
|
-
toolName: string;
|
|
614
|
-
parameters: string;
|
|
615
|
-
}
|
|
616
|
-
interface MicdropConversationToolResult {
|
|
617
|
-
role: 'tool_result';
|
|
618
|
-
toolCallId: string;
|
|
619
|
-
toolName: string;
|
|
620
|
-
output: string;
|
|
621
|
-
}
|
|
622
|
-
interface MicdropToolCall {
|
|
623
|
-
name: string;
|
|
624
|
-
parameters: any;
|
|
625
|
-
output: any;
|
|
626
|
-
}
|
|
627
|
-
type DeepPartial<T> = T extends object ? {
|
|
628
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
629
|
-
} : T;
|
|
630
|
-
|
|
631
699
|
declare enum MicdropClientErrorCode {
|
|
632
700
|
MissingUrl = "MissingUrl",
|
|
633
701
|
Mic = "Mic",
|
|
@@ -666,6 +734,14 @@ interface MicdropOptions {
|
|
|
666
734
|
url?: string;
|
|
667
735
|
params?: Record<string, any>;
|
|
668
736
|
vad?: VADConfig;
|
|
737
|
+
/**
|
|
738
|
+
* Holds the turn open while the sentence sounds unfinished, so a hesitation
|
|
739
|
+
* no longer counts as the end of a question. Without one, a turn ends as
|
|
740
|
+
* soon as the VAD hears enough silence.
|
|
741
|
+
*/
|
|
742
|
+
turnDetector?: TurnDetector;
|
|
743
|
+
/** How long a turn may stay open after the detector asked to wait */
|
|
744
|
+
turnMaxWait?: number;
|
|
669
745
|
disableInterruption?: boolean;
|
|
670
746
|
debugLog?: boolean;
|
|
671
747
|
reconnect?: MicdropReconnectOptions;
|
|
@@ -734,6 +810,20 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
|
|
|
734
810
|
vad?: VADConfig;
|
|
735
811
|
deviceId?: string;
|
|
736
812
|
}) => Promise<void>;
|
|
813
|
+
/**
|
|
814
|
+
* Changes what decides when a turn is over, during a call or before one
|
|
815
|
+
* @param turnDetector - The new detector, or nothing to leave it to the VAD
|
|
816
|
+
*/
|
|
817
|
+
setTurnDetector: (turnDetector?: TurnDetector) => void;
|
|
818
|
+
/**
|
|
819
|
+
* Says how long a held turn waits for the rest of the sentence.
|
|
820
|
+
*
|
|
821
|
+
* The way out of a wrong verdict: a detector can hear an unfinished sentence
|
|
822
|
+
* where there is none, and the speaker who never comes back still gets an
|
|
823
|
+
* answer once this runs out.
|
|
824
|
+
* @param milliseconds - How long to wait past the detector asking to
|
|
825
|
+
*/
|
|
826
|
+
setTurnMaxWait: (milliseconds: number) => void;
|
|
737
827
|
changeMicDevice: (deviceId: string) => Promise<void>;
|
|
738
828
|
changeSpeakerDevice: (deviceId: string) => Promise<void>;
|
|
739
829
|
private stopMic;
|
|
@@ -779,4 +869,4 @@ declare enum MicdropStorageKeys {
|
|
|
779
869
|
declare function setMicdropStorage(storage: MicdropStorage): void;
|
|
780
870
|
declare const storage: MicdropStorage;
|
|
781
871
|
|
|
782
|
-
export { type AudioSink, type DeepPartial, Mic, MicController, MicDriver, type MicDriverEvents, type MicEvents, MicRecorder, type MicRecorderEvents, type MicRecorderState, type MicSource, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConversation, type MicdropConversationItem, type MicdropConversationMessage, type MicdropConversationToolCall, type MicdropConversationToolResult, type MicdropDevice, type MicdropEvents, type MicdropOptions, type MicdropReconnectOptions, MicdropServerCommands, type MicdropState, type MicdropStorage, MicdropStorageKeys, type MicdropToolCall, MultipleVAD, Pcm16AudioStream, type Pcm16AudioStreamEvents, SILERO_FRAME_SAMPLES, SILERO_SAMPLE_RATE, type ScheduledAudio, type SileroModel, type SileroModelLoader, SileroVAD, type SileroVADOptions, Speaker, SpeakerController, SpeakerDriver, type SpeakerDriverEvents, type SpeakerEvents, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VOLUME_SAMPLE_RATE, VolumeMeter, VolumeVAD, type VolumeVADOptions, type WSCloseEvent, concatFloat32, equalVADConfig, floatToPcm16, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD, getVolume, isRecoverableError, pcm16ToArrayBuffer, pcm16ToFloat, resample, setMicdropStorage, setSileroModelLoader, storage };
|
|
872
|
+
export { type AudioSink, DEFAULT_TURN_MAX_WAIT, type DeepPartial, Mic, MicController, MicDriver, type MicDriverEvents, type MicEvents, MicRecorder, type MicRecorderEvents, type MicRecorderState, type MicSource, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConversation, type MicdropConversationItem, type MicdropConversationMessage, type MicdropConversationToolCall, type MicdropConversationToolResult, type MicdropDevice, type MicdropEvents, type MicdropOptions, type MicdropReconnectOptions, MicdropServerCommands, type MicdropState, type MicdropStorage, MicdropStorageKeys, type MicdropToolCall, MultipleVAD, Pcm16AudioStream, type Pcm16AudioStreamEvents, SILERO_FRAME_SAMPLES, SILERO_SAMPLE_RATE, type ScheduledAudio, type SileroModel, type SileroModelLoader, SileroVAD, type SileroVADOptions, Speaker, SpeakerController, SpeakerDriver, type SpeakerDriverEvents, type SpeakerEvents, type TurnDetector, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VOLUME_SAMPLE_RATE, VolumeMeter, VolumeVAD, type VolumeVADOptions, type WSCloseEvent, concatFloat32, equalVADConfig, floatToPcm16, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD, getVolume, isRecoverableError, pcm16ToArrayBuffer, pcm16ToFloat, resample, setMicdropStorage, setSileroModelLoader, storage };
|