@micdrop/client 3.2.0 → 3.2.1

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 CHANGED
@@ -334,7 +334,7 @@ declare abstract class VAD extends EventEmitter<VADEvents> {
334
334
  * Sets the status of the VAD
335
335
  * @param status - The status to set
336
336
  */
337
- private setStatus;
337
+ protected setStatus(status: VADStatus): void;
338
338
  }
339
339
 
340
340
  type VADConfigName = 'volume' | 'silero';
@@ -600,6 +600,7 @@ declare class SileroVAD extends VAD {
600
600
  private speechFrames;
601
601
  private silenceFrames;
602
602
  private processing;
603
+ private round;
603
604
  constructor(options?: Partial<SileroVADOptions>);
604
605
  get isStarted(): boolean;
605
606
  get isPaused(): boolean;
@@ -791,6 +792,7 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
791
792
  private _isMuted;
792
793
  private _isPaused;
793
794
  private _isReconnecting;
795
+ private _isStartingCall;
794
796
  private reconnectAttempt;
795
797
  private reconnectTimer?;
796
798
  private connectionTimer?;
package/dist/index.d.ts CHANGED
@@ -334,7 +334,7 @@ declare abstract class VAD extends EventEmitter<VADEvents> {
334
334
  * Sets the status of the VAD
335
335
  * @param status - The status to set
336
336
  */
337
- private setStatus;
337
+ protected setStatus(status: VADStatus): void;
338
338
  }
339
339
 
340
340
  type VADConfigName = 'volume' | 'silero';
@@ -600,6 +600,7 @@ declare class SileroVAD extends VAD {
600
600
  private speechFrames;
601
601
  private silenceFrames;
602
602
  private processing;
603
+ private round;
603
604
  constructor(options?: Partial<SileroVADOptions>);
604
605
  get isStarted(): boolean;
605
606
  get isPaused(): boolean;
@@ -791,6 +792,7 @@ declare class MicdropClient extends EventEmitter<MicdropEvents> implements Micdr
791
792
  private _isMuted;
792
793
  private _isPaused;
793
794
  private _isReconnecting;
795
+ private _isStartingCall;
794
796
  private reconnectAttempt;
795
797
  private reconnectTimer?;
796
798
  private connectionTimer?;
package/dist/index.js CHANGED
@@ -651,6 +651,9 @@ var SileroVAD = class extends VAD {
651
651
  this.speechFrames = 0;
652
652
  this.silenceFrames = 0;
653
653
  this.processing = false;
654
+ // Bumped whenever the state is reset, so a window scored before that is
655
+ // dropped rather than reopening a turn
656
+ this.round = 0;
654
657
  this.onFrames = (frames, sampleRate) => {
655
658
  if (this._isPaused || !this.model) return;
656
659
  if (sampleRate !== this.bufferRate) {
@@ -688,6 +691,7 @@ var SileroVAD = class extends VAD {
688
691
  }
689
692
  this.model = await loadModel();
690
693
  this.resetState();
694
+ this.setStatus(0 /* Silence */);
691
695
  this.mic = mic;
692
696
  mic.on("Frames", this.onFrames);
693
697
  }
@@ -734,9 +738,11 @@ var SileroVAD = class extends VAD {
734
738
  this.buffer = rest.length ? [rest] : [];
735
739
  this.bufferLength = rest.length;
736
740
  const frame = resample(window, this.bufferRate, SILERO_SAMPLE_RATE);
741
+ const round = this.round;
737
742
  const probability = await this.model.process(
738
743
  frame.length === SILERO_FRAME_SAMPLES ? frame : fit(frame, SILERO_FRAME_SAMPLES)
739
744
  );
745
+ if (round !== this.round) break;
740
746
  this.onProbability(probability);
741
747
  }
742
748
  } catch (error) {
@@ -777,6 +783,7 @@ var SileroVAD = class extends VAD {
777
783
  this.emit(confirmed ? "StopSpeaking" : "CancelSpeaking");
778
784
  }
779
785
  resetState() {
786
+ this.round++;
780
787
  this.model?.reset();
781
788
  this.buffer = [];
782
789
  this.bufferLength = 0;
@@ -1481,6 +1488,9 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1481
1488
  this._isMuted = false;
1482
1489
  this._isPaused = false;
1483
1490
  this._isReconnecting = false;
1491
+ // From start() until the connection opens, the microphone included: opening
1492
+ // it can take a while, for the permission prompt or the browser itself
1493
+ this._isStartingCall = false;
1484
1494
  this.reconnectAttempt = 0;
1485
1495
  this.start = async (options) => {
1486
1496
  this.error = void 0;
@@ -1492,18 +1502,25 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1492
1502
  this._isMuted = false;
1493
1503
  this._isPaused = false;
1494
1504
  this._isReconnecting = false;
1505
+ this._isStartingCall = true;
1495
1506
  this.reconnectAttempt = 0;
1496
1507
  if (this.reconnectTimer) {
1497
1508
  clearTimeout(this.reconnectTimer);
1498
1509
  this.reconnectTimer = void 0;
1499
1510
  }
1511
+ this.notifyStateChange();
1500
1512
  if (!this.micRecorder || options?.vad) {
1501
1513
  await this.startMic({ vad: options?.vad });
1502
1514
  }
1503
1515
  await this.startWS();
1516
+ if (this.isWSStarted && this._isStartingCall) {
1517
+ this._isStartingCall = false;
1518
+ this.notifyStateChange();
1519
+ }
1504
1520
  };
1505
1521
  this.stop = async () => {
1506
1522
  this.partialAssistantMessage = "";
1523
+ this._isStartingCall = false;
1507
1524
  this._isProcessing = false;
1508
1525
  this._isMuted = false;
1509
1526
  this._isPaused = false;
@@ -1662,6 +1679,7 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1662
1679
  this.connectionTimer = void 0;
1663
1680
  }
1664
1681
  this._isReconnecting = false;
1682
+ this._isStartingCall = false;
1665
1683
  this.reconnectAttempt = 0;
1666
1684
  this.error = void 0;
1667
1685
  this.notifyStateChange();
@@ -1774,7 +1792,7 @@ var MicdropClient = class extends import_eventemitter37.EventEmitter {
1774
1792
  return (this.isWSStarted || this._isReconnecting) && (this.micRecorder?.state.isStarted || false);
1775
1793
  }
1776
1794
  get isStarting() {
1777
- return (this.isWSStarting || this.micRecorder?.state.isStarting || false) && !this._isReconnecting;
1795
+ return (this._isStartingCall || this.isWSStarting || this.micRecorder?.state.isStarting || false) && !this._isReconnecting;
1778
1796
  }
1779
1797
  get isReconnecting() {
1780
1798
  return this._isReconnecting;