@micdrop/client 2.2.9 → 3.0.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 CHANGED
@@ -1,57 +1,209 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
2
 
3
- interface AudioAnalyserEvents {
4
- volume: [number];
3
+ /**
4
+ * An input or output audio device offered by the system
5
+ */
6
+ interface MicdropDevice {
7
+ /** Identifier to hand back to `changeMicDevice` or `changeSpeakerDevice` */
8
+ id: string;
9
+ /** Name to show, as the system spells it */
10
+ label: string;
11
+ kind: 'audioinput' | 'audiooutput';
5
12
  }
6
- declare class AudioAnalyser extends EventEmitter<AudioAnalyserEvents> {
7
- volumeInterval: number;
8
- node: AnalyserNode;
9
- volume: number;
10
- private fftSize;
11
- private fftBins;
12
- private interval;
13
- constructor(audioContext: AudioContext, volumeInterval?: number);
13
+ interface MicEvents {
14
+ /** A batch of mono samples, in the -1..1 range, with its sample rate */
15
+ Frames: [Float32Array, number];
16
+ /** Level of the captured audio, emitted about ten times a second */
17
+ Volume: [number];
18
+ /** The system gained or lost an audio device */
19
+ DeviceChange: [];
20
+ Error: [Error];
21
+ }
22
+ /**
23
+ * What a {@link VAD} listens to. The `Mic` singleton implements it, and so can
24
+ * any other emitter, which makes voice activity detection testable on its own.
25
+ */
26
+ type MicSource = Pick<EventEmitter<MicEvents>, 'on' | 'off'>;
27
+ interface MicDriverEvents {
28
+ /** A batch of mono samples, in the -1..1 range, with its sample rate */
29
+ Frames: [Float32Array, number];
30
+ /** The system gained or lost an audio device */
31
+ DeviceChange: [];
32
+ Error: [Error];
33
+ }
34
+ /**
35
+ * Captures the microphone and pushes raw samples.
36
+ *
37
+ * `@micdrop/web` records with the Web Audio API and `@micdrop/react-native`
38
+ * with the native audio engine. Everything above this interface is shared.
39
+ */
40
+ declare abstract class MicDriver extends EventEmitter<MicDriverEvents> {
41
+ abstract get isStarted(): boolean;
42
+ /** Identifier of the input device in use, when the system reports one */
43
+ abstract get deviceId(): string | undefined;
44
+ /**
45
+ * Asks for the microphone permission and starts capturing
46
+ * @param deviceId - Input device to record from, defaults to the system one
47
+ */
48
+ abstract start(deviceId?: string): Promise<void>;
49
+ /** Stops capturing and releases the microphone */
50
+ abstract stop(): Promise<void>;
51
+ /** Lists the input devices the system offers */
52
+ abstract getDevices(): Promise<MicdropDevice[]>;
53
+ }
54
+ interface SpeakerDriverEvents {
55
+ StartPlaying: [];
56
+ StopPlaying: [];
57
+ /** Level of the audio being played */
58
+ Volume: [number];
59
+ }
60
+ /**
61
+ * Plays the 16 kHz mono PCM sent by the server.
62
+ */
63
+ declare abstract class SpeakerDriver extends EventEmitter<SpeakerDriverEvents> {
64
+ abstract get isPlaying(): boolean;
65
+ /** Identifier of the output device in use, when the system reports one */
66
+ abstract get deviceId(): string | undefined;
67
+ /** Prepares the audio graph, called before the first chunk arrives */
68
+ abstract start(): Promise<void>;
69
+ /**
70
+ * Queues samples for playback, right after the ones already queued
71
+ * @param pcm - Mono samples as 16 bits integers
72
+ * @param sampleRate - Sample rate of `pcm`, in Hz
73
+ */
74
+ abstract play(pcm: Int16Array, sampleRate: number): void;
75
+ /** Drops everything queued and stops playing immediately */
76
+ abstract stopAudio(): void;
77
+ /** Releases the audio graph */
78
+ abstract stop(): Promise<void>;
79
+ /**
80
+ * Plays through another output
81
+ * @param deviceId - Output device, or route on a phone
82
+ */
83
+ abstract changeDevice(deviceId: string): Promise<void>;
84
+ /** Lists the output devices the system offers */
85
+ abstract getDevices(): Promise<MicdropDevice[]>;
86
+ }
87
+ /** A buffer handed to an {@link AudioSink}, that can still be cancelled */
88
+ interface ScheduledAudio {
14
89
  stop(): void;
15
- private getMaxVolume;
90
+ }
91
+ /**
92
+ * The minimal slice of an audio engine needed to stream the assistant voice.
93
+ * Implemented on each platform, and faked in the test suite.
94
+ */
95
+ interface AudioSink {
96
+ /** Sample rate of the underlying audio graph, in Hz */
97
+ readonly sampleRate: number;
98
+ /** Current time of the audio graph, in seconds */
99
+ readonly currentTime: number;
100
+ /**
101
+ * Plays samples at a given time on the audio graph clock
102
+ * @param samples - Mono samples, in the -1..1 range, at `sampleRate`
103
+ * @param when - When to start, in seconds on the audio graph clock
104
+ * @param onEnded - Called once the samples have been played
105
+ */
106
+ schedule(samples: Float32Array, when: number, onEnded: () => void): ScheduledAudio;
16
107
  }
17
108
 
18
- declare class Mic$1 {
19
- analyser: AudioAnalyser;
20
- deviceId: string | undefined;
21
- private audioStream;
22
- private sourceNode;
23
- private getMicConstraints;
109
+ /**
110
+ * The microphone, as a single object shared by the whole app.
111
+ *
112
+ * It wraps a {@link MicDriver}, the browser one or the native one, and turns
113
+ * the samples it captures into the level used by the VAD and by level meters.
114
+ * Nothing here knows which platform it runs on.
115
+ */
116
+ declare class MicController extends EventEmitter<MicEvents> {
117
+ private driver;
118
+ private meter;
119
+ private pending;
120
+ private pendingLength;
121
+ private pendingRate;
122
+ private rateCheckedAt;
123
+ private rateCheckSamples;
124
+ private rateWarned;
125
+ /** Last level measured, in decibels, between -Infinity and 0 */
126
+ volume: number;
24
127
  /**
25
- * Starts the microphone
26
- * @param deviceId - The deviceId to use
27
- * @returns The microphone stream
128
+ * Replaces the audio driver, to record with another library
129
+ * @param driver - The driver to record with
28
130
  */
29
- start(deviceId?: string): Promise<MediaStream>;
131
+ setDriver(driver: MicDriver): void;
132
+ getDriver(): MicDriver;
133
+ get isStarted(): boolean;
134
+ get deviceId(): string | undefined;
30
135
  /**
31
- * Stops the microphone
136
+ * Asks for the microphone permission and starts capturing
137
+ * @param deviceId - Input device to record from, defaults to the system one
32
138
  */
33
- stop(): void;
139
+ start(deviceId?: string): Promise<void>;
140
+ /** Stops capturing and releases the microphone */
141
+ stop(): Promise<void>;
142
+ /** Lists the input devices the system offers */
143
+ getDevices(): Promise<MicdropDevice[]>;
144
+ private onFrames;
145
+ /**
146
+ * Times the captured audio against the rate it claims to be at.
147
+ *
148
+ * A microphone that announces 16 kHz while delivering 48 kHz sends speech to
149
+ * the server three times too slow, which comes back as a short transcript in
150
+ * a random language. That is invisible otherwise, so it is worth saying out
151
+ * loud once.
152
+ * @param samples - How many samples just arrived
153
+ * @param sampleRate - The rate they are said to be at
154
+ */
155
+ private checkRate;
156
+ private onDeviceChange;
157
+ private onError;
158
+ private resetVolume;
34
159
  }
35
160
 
36
161
  interface SpeakerEvents {
37
162
  StartPlaying: void;
38
163
  StopPlaying: void;
164
+ /** Level of the audio being played */
165
+ Volume: [number];
39
166
  }
40
- declare class Speaker$1 extends EventEmitter<SpeakerEvents> {
41
- isPlaying: boolean;
42
- analyser: AudioAnalyser;
43
- deviceId: string | undefined;
44
- devices: MediaDeviceInfo[];
45
- private audioStream?;
46
- private audioSourceNode?;
47
- private audioElementDestination?;
167
+ /**
168
+ * The speaker, as a single object shared by the whole app.
169
+ *
170
+ * It wraps a {@link SpeakerDriver} and plays the 16 kHz PCM sent by the server
171
+ * as it arrives.
172
+ */
173
+ declare class SpeakerController extends EventEmitter<SpeakerEvents> {
174
+ private driver;
175
+ /** Last level measured, in decibels, between -Infinity and 0 */
176
+ volume: number;
177
+ /**
178
+ * Replaces the audio driver, to play sound with another library
179
+ * @param driver - The driver to play with
180
+ */
181
+ setDriver(driver: SpeakerDriver): void;
182
+ getDriver(): SpeakerDriver;
183
+ get isPlaying(): boolean;
184
+ get deviceId(): string | undefined;
185
+ /** Prepares the audio graph, called before the first chunk arrives */
48
186
  start(): Promise<void>;
49
- playAudio(blob: Blob): Promise<void>;
50
- stopAudio(): Promise<void>;
187
+ /**
188
+ * Queues samples for playback, right after the ones already queued
189
+ * @param pcm - Mono samples as 16 bits integers, or the bytes holding them
190
+ * @param sampleRate - Sample rate of `pcm`, in Hz
191
+ */
192
+ playAudio(pcm: Int16Array | ArrayBuffer, sampleRate?: number): void;
193
+ /** Drops everything queued and stops playing immediately */
194
+ stopAudio(): void;
195
+ /** Releases the audio graph */
196
+ stop(): Promise<void>;
197
+ /**
198
+ * Plays through another output
199
+ * @param deviceId - Output device, or route on a phone
200
+ */
51
201
  changeDevice(deviceId: string): Promise<void>;
52
- get isDefaultDevice(): boolean;
53
- private setIsPlaying;
54
- private setDevice;
202
+ /** Lists the output devices the system offers */
203
+ getDevices(): Promise<MicdropDevice[]>;
204
+ private onStartPlaying;
205
+ private onStopPlaying;
206
+ private onVolume;
55
207
  }
56
208
 
57
209
  interface VADEvents {
@@ -86,9 +238,9 @@ declare abstract class VAD extends EventEmitter<VADEvents> {
86
238
  abstract get isPaused(): boolean;
87
239
  /**
88
240
  * Starts the VAD
89
- * @param stream - The stream to start the VAD on
241
+ * @param mic - The microphone to listen to
90
242
  */
91
- abstract start(stream: MediaStream): Promise<void>;
243
+ abstract start(mic: MicSource): Promise<void>;
92
244
  /**
93
245
  * Stops the VAD
94
246
  */
@@ -131,35 +283,128 @@ interface MicRecorderEvents {
131
283
  StopSpeaking: void;
132
284
  StateChange: [MicRecorderState];
133
285
  }
286
+ /**
287
+ * Turns what the microphone captures into the chunks sent to the server.
288
+ *
289
+ * It only records while the VAD hears someone, and keeps a short reserve of
290
+ * audio so the first syllable, spoken before the VAD reacted, is sent too.
291
+ */
134
292
  declare class MicRecorder extends EventEmitter<MicRecorderEvents> {
135
293
  private vadConfig?;
136
294
  state: MicRecorderState;
137
295
  vad: VAD;
138
- private stream;
139
- private source;
140
- private workletNode;
141
- private delayedStream;
296
+ private mic;
297
+ private isRecording;
142
298
  private speakingConfirmed;
299
+ private sourceSampleRate;
300
+ private reserve;
301
+ private reserveLength;
302
+ private buffer;
303
+ private bufferLength;
143
304
  private queuedChunks;
144
305
  constructor(vadConfig?: VADConfig | undefined);
145
- start: (stream: MediaStream) => Promise<void>;
306
+ start: (mic: MicSource) => Promise<void>;
146
307
  stop: () => void;
147
308
  changeVad: (vadConfig: VADConfig) => void;
309
+ private onFrames;
148
310
  private onStartSpeaking;
149
311
  private onConfirmSpeaking;
150
312
  private onCancelSpeaking;
151
313
  private onStopSpeaking;
152
- private onWorkletMessage;
314
+ private stopRecording;
315
+ /**
316
+ * Emits every complete chunk waiting in the buffer
317
+ * @param final - Also emit the incomplete last chunk
318
+ */
319
+ private flushChunks;
320
+ private emitChunk;
321
+ private resetBuffers;
153
322
  private changeState;
154
323
  }
155
324
 
156
- declare enum LocalStorageKeys {
157
- MicDevice = "micdrop.micDevice",
158
- SpeakerDevice = "micdrop.speakerDevice",
159
- VolumeVADOptions = "micdrop.VolumeVADOptions",
160
- SileroVADOptions = "micdrop.SileroVADOptions"
325
+ interface Pcm16AudioStreamEvents {
326
+ StartPlaying: [];
327
+ StopPlaying: [];
328
+ Volume: [number];
329
+ }
330
+ /**
331
+ * Turns the stream of PCM chunks sent by the server into continuous playback.
332
+ *
333
+ * Chunks arrive faster or slower than they are heard, so each one is scheduled
334
+ * right after the previous one on the audio graph clock instead of being played
335
+ * on arrival.
336
+ */
337
+ declare class Pcm16AudioStream extends EventEmitter<Pcm16AudioStreamEvents> {
338
+ private sink;
339
+ isPlaying: boolean;
340
+ private sources;
341
+ private nextStartTime;
342
+ private prebuffering;
343
+ private prebuffer;
344
+ private prebufferDuration;
345
+ private quietTimer?;
346
+ private endTimer?;
347
+ private volumeTimers;
348
+ private meter;
349
+ constructor(sink: AudioSink);
350
+ /**
351
+ * Queues samples for playback
352
+ * @param pcm - Mono samples as 16 bits integers
353
+ * @param sampleRate - Sample rate of `pcm`, in Hz
354
+ */
355
+ playAudio(pcm: Int16Array, sampleRate: number): void;
356
+ /** Drops everything queued and stops playing immediately */
357
+ stopAudio(): void;
358
+ private handleSamples;
359
+ private flushPrebuffer;
360
+ private resetPrebuffer;
361
+ private scheduleSamples;
362
+ private scheduleVolume;
363
+ private clearVolumeTimers;
364
+ private setIsPlaying;
161
365
  }
162
366
 
367
+ /**
368
+ * PCM helpers shared by the microphone and the speaker.
369
+ *
370
+ * Everything here is pure so it can be exercised without a device: the same
371
+ * functions run on iOS, on Android and in the test suite.
372
+ */
373
+ /**
374
+ * Resamples mono float samples with linear interpolation.
375
+ * @param input - Mono samples, in the -1..1 range
376
+ * @param inputRate - Sample rate of `input`, in Hz
377
+ * @param outputRate - Wanted sample rate, in Hz
378
+ * @returns The resampled samples, or `input` itself when both rates match
379
+ */
380
+ declare function resample(input: Float32Array, inputRate: number, outputRate: number): Float32Array;
381
+ /**
382
+ * Converts float samples to signed 16 bits PCM
383
+ * @param input - Mono samples, in the -1..1 range
384
+ * @returns The same samples as 16 bits integers
385
+ */
386
+ declare function floatToPcm16(input: Float32Array): Int16Array;
387
+ /**
388
+ * Converts signed 16 bits PCM to float samples
389
+ * @param input - Mono samples as 16 bits integers
390
+ * @returns The same samples in the -1..1 range
391
+ */
392
+ declare function pcm16ToFloat(input: Int16Array): Float32Array;
393
+ /**
394
+ * Concatenates chunks of samples into a single buffer
395
+ * @param chunks - The chunks to concatenate, in order
396
+ * @returns One buffer holding every sample
397
+ */
398
+ declare function concatFloat32(chunks: Float32Array[]): Float32Array;
399
+ /**
400
+ * Copies signed 16 bits PCM into a standalone ArrayBuffer, ready to be sent
401
+ * over a WebSocket. A typed array can be a view on a larger buffer, sending it
402
+ * as is would send the whole buffer.
403
+ * @param pcm - The samples to send
404
+ * @returns An ArrayBuffer holding exactly those samples
405
+ */
406
+ declare function pcm16ToArrayBuffer(pcm: Int16Array): ArrayBuffer;
407
+
163
408
  /**
164
409
  * Combine an array of VADs
165
410
  */
@@ -169,74 +414,172 @@ declare class MultipleVAD extends VAD {
169
414
  constructor(vads: Array<VAD | VADConfigName>);
170
415
  get isStarted(): boolean;
171
416
  get isPaused(): boolean;
172
- start(stream: MediaStream): Promise<void>;
417
+ start(mic: MicSource): Promise<void>;
173
418
  private onStatusChange;
174
419
  stop(): Promise<void>;
175
420
  pause(): Promise<void>;
176
421
  resume(): Promise<void>;
177
422
  }
178
423
 
424
+ /** Rate and window the Silero v5 model expects */
425
+ declare const SILERO_SAMPLE_RATE = 16000;
426
+ declare const SILERO_FRAME_SAMPLES = 512;
427
+ /**
428
+ * One loaded Silero model, whichever runtime holds it.
429
+ *
430
+ * `@micdrop/web` runs it with onnxruntime-web and `@micdrop/react-native` with
431
+ * onnxruntime-react-native. Both answer the same question: how likely is it
432
+ * that these 512 samples are speech.
433
+ */
434
+ interface SileroModel {
435
+ /**
436
+ * Scores one window of audio
437
+ * @param frame - 512 mono samples at 16 kHz, in the -1..1 range
438
+ * @returns The probability that it is speech, between 0 and 1
439
+ */
440
+ process(frame: Float32Array): Promise<number>;
441
+ /** Forgets what came before, at the start of a new call */
442
+ reset(): void;
443
+ /** Releases the runtime */
444
+ release(): Promise<void>;
445
+ }
446
+ /** Loads the model, which usually means fetching a couple of megabytes */
447
+ type SileroModelLoader = () => Promise<SileroModel>;
179
448
  type SileroVADOptions = {
449
+ /** Above this probability, the window counts as speech */
180
450
  positiveSpeechThreshold: number;
451
+ /** Below this probability, the window counts as silence */
181
452
  negativeSpeechThreshold: number;
453
+ /** Windows of speech needed before a turn is confirmed */
182
454
  minSpeechFrames: number;
455
+ /** Windows of silence tolerated inside a turn before it is closed */
183
456
  redemptionFrames: number;
184
457
  };
185
458
  /**
186
- * Silero VAD
187
- * @see https://github.com/ricky0123/vad
459
+ * Says how the Silero model is loaded on this platform. Called by
460
+ * `@micdrop/web` and `@micdrop/react-native` when they are imported.
461
+ * @param loader - Loads and returns a ready to use model
462
+ */
463
+ declare function setSileroModelLoader(loader: SileroModelLoader): void;
464
+ /**
465
+ * Voice activity detection with the Silero model.
466
+ *
467
+ * It hears the difference between a voice and a noise, where
468
+ * {@link VolumeVAD} only hears how loud the room is. The model itself is
469
+ * loaded by the platform package, everything else runs the same everywhere.
470
+ *
471
+ * @see https://github.com/snakers4/silero-vad
188
472
  */
189
473
  declare class SileroVAD extends VAD {
190
474
  readonly name = "SileroVAD";
191
475
  options: SileroVADOptions;
192
- private vad;
476
+ delay: number;
477
+ private model;
478
+ private mic;
193
479
  private _isPaused;
480
+ private buffer;
481
+ private bufferLength;
482
+ private bufferRate;
483
+ private speaking;
484
+ private speechFrames;
485
+ private silenceFrames;
486
+ private processing;
194
487
  constructor(options?: Partial<SileroVADOptions>);
195
488
  get isStarted(): boolean;
196
489
  get isPaused(): boolean;
197
- start(stream: MediaStream): Promise<void>;
490
+ start(mic: MicSource): Promise<void>;
198
491
  stop(): Promise<void>;
199
492
  pause(): Promise<void>;
200
493
  resume(): Promise<void>;
201
494
  setOptions(options: Partial<SileroVADOptions>): void;
202
495
  resetOptions(): void;
496
+ private onFrames;
497
+ private drain;
498
+ private onProbability;
499
+ private closeOpenTurn;
500
+ private resetState;
203
501
  }
204
502
 
205
503
  type VolumeVADOptions = {
504
+ /** Number of recent samples kept to decide whether someone is speaking */
206
505
  history: number;
506
+ /** Level above which audio counts as speech, in decibels */
207
507
  threshold: number;
208
508
  };
209
509
  /**
210
- * Volume-based Voice Activity Detection
211
- * Based on the hark library implementation
510
+ * Volume based Voice Activity Detection.
511
+ *
512
+ * It follows the level reported by the microphone, and needs a few consecutive
513
+ * loud samples before confirming speech, so a door slam or a keyboard click
514
+ * does not start a turn.
212
515
  */
213
516
  declare class VolumeVAD extends VAD {
214
517
  readonly name = "VolumeVAD";
215
518
  options: VolumeVADOptions;
216
- private _isPaused;
217
- private analyser;
218
- private sourceNode;
219
- private fftBins;
519
+ delay: number;
520
+ private mic;
220
521
  private running;
522
+ private _isPaused;
221
523
  private speaking;
222
524
  private attemptSpeaking;
223
525
  private speakingHistory;
224
526
  constructor(options?: Partial<VolumeVADOptions>);
225
- private getMaxVolume;
226
527
  get isStarted(): boolean;
227
528
  get isPaused(): boolean;
228
- start(stream: MediaStream): Promise<void>;
229
- private startLoop;
230
- private resetHistory;
529
+ start(mic: MicSource): Promise<void>;
231
530
  stop(): Promise<void>;
232
531
  pause(): Promise<void>;
233
532
  resume(): Promise<void>;
234
533
  setOptions(options: Partial<VolumeVADOptions>): void;
235
534
  resetOptions(): void;
535
+ private onVolume;
536
+ private reset;
236
537
  }
237
538
 
238
- declare const Mic: Mic$1;
239
- declare const Speaker: Speaker$1;
539
+ /**
540
+ * Measures how loud the microphone is, the way a browser AnalyserNode does.
541
+ *
542
+ * The level is the loudest frequency bin rather than the overall energy: a
543
+ * voice concentrates its power in a few bins while a fan or a room spreads it
544
+ * over all of them, so the two are told apart by about 25 dB instead of the 7 dB
545
+ * an RMS would give.
546
+ *
547
+ * Everything here is pure, so the same measurement runs in a browser, on a
548
+ * phone and in the test suite.
549
+ */
550
+ /** Sample rate the measurement expects, so a bin means the same frequency everywhere */
551
+ declare const VOLUME_SAMPLE_RATE = 16000;
552
+ /**
553
+ * Follows the level of a stream of audio.
554
+ *
555
+ * It keeps the previous measurement, so a single quiet frame in the middle of a
556
+ * word does not read as a pause.
557
+ */
558
+ declare class VolumeMeter {
559
+ private real;
560
+ private imaginary;
561
+ private magnitudes;
562
+ private smoothed;
563
+ private hasPrevious;
564
+ /**
565
+ * Measures a window of audio
566
+ * @param samples - At least 512 mono samples at 16 kHz, in the -1..1 range.
567
+ * Only the last 512 are looked at.
568
+ * @returns The level in decibels, between -Infinity (silence) and 0
569
+ */
570
+ measure(samples: Float32Array): number;
571
+ /** Forgets the previous window, for when capture stops and starts again */
572
+ reset(): void;
573
+ }
574
+ /**
575
+ * Measures one window of audio, without following what came before
576
+ * @param samples - Mono samples at 16 kHz, in the -1..1 range
577
+ * @returns The level in decibels, between -Infinity (silence) and 0
578
+ */
579
+ declare function getVolume(samples: Float32Array): number;
580
+
581
+ declare const Mic: MicController;
582
+ declare const Speaker: SpeakerController;
240
583
 
241
584
  declare enum MicdropClientCommands {
242
585
  StartSpeaking = "StartSpeaking",
@@ -299,7 +642,12 @@ declare class MicdropClientError extends Error {
299
642
  code: MicdropClientErrorCode;
300
643
  constructor(code?: MicdropClientErrorCode, message?: string);
301
644
  }
302
- declare function getClientErrorFromWSCloseEvent(event: CloseEvent): MicdropClientError | undefined;
645
+ /** What React Native gives on a WebSocket close */
646
+ interface WSCloseEvent {
647
+ code?: number;
648
+ reason?: string;
649
+ }
650
+ declare function getClientErrorFromWSCloseEvent(event: WSCloseEvent): MicdropClientError | undefined;
303
651
  declare function getClientErrorFromWSCloseEventCode(code: number): MicdropClientErrorCode | undefined;
304
652
  declare function isRecoverableError(error: MicdropClientError): boolean;
305
653
 
@@ -336,8 +684,8 @@ interface MicdropState {
336
684
  isMicMuted: boolean;
337
685
  micDeviceId: string | undefined;
338
686
  speakerDeviceId: string | undefined;
339
- micDevices: MediaDeviceInfo[];
340
- speakerDevices: MediaDeviceInfo[];
687
+ micDevices: MicdropDevice[];
688
+ speakerDevices: MicdropDevice[];
341
689
  conversation: MicdropConversation;
342
690
  error: MicdropClientError | undefined;
343
691
  }
@@ -346,10 +694,9 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
346
694
  micRecorder?: MicRecorder;
347
695
  conversation: MicdropConversation;
348
696
  error: MicdropClientError | undefined;
349
- speakerDevices: MediaDeviceInfo[];
350
- micDevices: MediaDeviceInfo[];
697
+ speakerDevices: MicdropDevice[];
698
+ micDevices: MicdropDevice[];
351
699
  private ws?;
352
- private micStream?;
353
700
  private startTime;
354
701
  private lastNotifiedState;
355
702
  private _isProcessing;
@@ -408,4 +755,28 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
408
755
 
409
756
  declare const Micdrop: MicdropClient;
410
757
 
411
- export { type DeepPartial, LocalStorageKeys, Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, Micdrop, type MicdropAnswerMetadata, type MicdropCallSummary, MicdropClient, MicdropClientCommands, MicdropClientError, MicdropClientErrorCode, type MicdropConversation, type MicdropConversationItem, type MicdropConversationMessage, type MicdropConversationToolCall, type MicdropConversationToolResult, type MicdropEvents, type MicdropOptions, type MicdropReconnectOptions, MicdropServerCommands, type MicdropState, type MicdropToolCall, MultipleVAD, SileroVAD, type SileroVADOptions, Speaker, VAD, type VADConfig, type VADConfigName, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions, equalVADConfig, getClientErrorFromWSCloseEvent, getClientErrorFromWSCloseEventCode, getVAD, isRecoverableError };
758
+ /**
759
+ * Where settings that outlive a call are kept.
760
+ *
761
+ * A browser has `localStorage`, a phone has whatever the app installs. Reads
762
+ * are synchronous, so a VAD can be built with its saved options in hand.
763
+ */
764
+ interface MicdropStorage {
765
+ getItem(key: string): string | null;
766
+ setItem(key: string, value: string): void;
767
+ removeItem(key: string): void;
768
+ }
769
+ declare enum MicdropStorageKeys {
770
+ MicDevice = "micdrop.micDevice",
771
+ SpeakerDevice = "micdrop.speakerDevice",
772
+ VolumeVADOptions = "micdrop.VolumeVADOptions",
773
+ SileroVADOptions = "micdrop.SileroVADOptions"
774
+ }
775
+ /**
776
+ * Chooses where settings are kept
777
+ * @param storage - Anything with the three `localStorage` methods
778
+ */
779
+ declare function setMicdropStorage(storage: MicdropStorage): void;
780
+ declare const storage: MicdropStorage;
781
+
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 };