@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.mjs CHANGED
@@ -587,6 +587,9 @@ var SileroVAD = class extends VAD {
587
587
  this.speechFrames = 0;
588
588
  this.silenceFrames = 0;
589
589
  this.processing = false;
590
+ // Bumped whenever the state is reset, so a window scored before that is
591
+ // dropped rather than reopening a turn
592
+ this.round = 0;
590
593
  this.onFrames = (frames, sampleRate) => {
591
594
  if (this._isPaused || !this.model) return;
592
595
  if (sampleRate !== this.bufferRate) {
@@ -624,6 +627,7 @@ var SileroVAD = class extends VAD {
624
627
  }
625
628
  this.model = await loadModel();
626
629
  this.resetState();
630
+ this.setStatus(0 /* Silence */);
627
631
  this.mic = mic;
628
632
  mic.on("Frames", this.onFrames);
629
633
  }
@@ -670,9 +674,11 @@ var SileroVAD = class extends VAD {
670
674
  this.buffer = rest.length ? [rest] : [];
671
675
  this.bufferLength = rest.length;
672
676
  const frame = resample(window, this.bufferRate, SILERO_SAMPLE_RATE);
677
+ const round = this.round;
673
678
  const probability = await this.model.process(
674
679
  frame.length === SILERO_FRAME_SAMPLES ? frame : fit(frame, SILERO_FRAME_SAMPLES)
675
680
  );
681
+ if (round !== this.round) break;
676
682
  this.onProbability(probability);
677
683
  }
678
684
  } catch (error) {
@@ -713,6 +719,7 @@ var SileroVAD = class extends VAD {
713
719
  this.emit(confirmed ? "StopSpeaking" : "CancelSpeaking");
714
720
  }
715
721
  resetState() {
722
+ this.round++;
716
723
  this.model?.reset();
717
724
  this.buffer = [];
718
725
  this.bufferLength = 0;
@@ -1417,6 +1424,9 @@ var MicdropClient = class extends EventEmitter7 {
1417
1424
  this._isMuted = false;
1418
1425
  this._isPaused = false;
1419
1426
  this._isReconnecting = false;
1427
+ // From start() until the connection opens, the microphone included: opening
1428
+ // it can take a while, for the permission prompt or the browser itself
1429
+ this._isStartingCall = false;
1420
1430
  this.reconnectAttempt = 0;
1421
1431
  this.start = async (options) => {
1422
1432
  this.error = void 0;
@@ -1428,18 +1438,25 @@ var MicdropClient = class extends EventEmitter7 {
1428
1438
  this._isMuted = false;
1429
1439
  this._isPaused = false;
1430
1440
  this._isReconnecting = false;
1441
+ this._isStartingCall = true;
1431
1442
  this.reconnectAttempt = 0;
1432
1443
  if (this.reconnectTimer) {
1433
1444
  clearTimeout(this.reconnectTimer);
1434
1445
  this.reconnectTimer = void 0;
1435
1446
  }
1447
+ this.notifyStateChange();
1436
1448
  if (!this.micRecorder || options?.vad) {
1437
1449
  await this.startMic({ vad: options?.vad });
1438
1450
  }
1439
1451
  await this.startWS();
1452
+ if (this.isWSStarted && this._isStartingCall) {
1453
+ this._isStartingCall = false;
1454
+ this.notifyStateChange();
1455
+ }
1440
1456
  };
1441
1457
  this.stop = async () => {
1442
1458
  this.partialAssistantMessage = "";
1459
+ this._isStartingCall = false;
1443
1460
  this._isProcessing = false;
1444
1461
  this._isMuted = false;
1445
1462
  this._isPaused = false;
@@ -1598,6 +1615,7 @@ var MicdropClient = class extends EventEmitter7 {
1598
1615
  this.connectionTimer = void 0;
1599
1616
  }
1600
1617
  this._isReconnecting = false;
1618
+ this._isStartingCall = false;
1601
1619
  this.reconnectAttempt = 0;
1602
1620
  this.error = void 0;
1603
1621
  this.notifyStateChange();
@@ -1710,7 +1728,7 @@ var MicdropClient = class extends EventEmitter7 {
1710
1728
  return (this.isWSStarted || this._isReconnecting) && (this.micRecorder?.state.isStarted || false);
1711
1729
  }
1712
1730
  get isStarting() {
1713
- return (this.isWSStarting || this.micRecorder?.state.isStarting || false) && !this._isReconnecting;
1731
+ return (this._isStartingCall || this.isWSStarting || this.micRecorder?.state.isStarting || false) && !this._isReconnecting;
1714
1732
  }
1715
1733
  get isReconnecting() {
1716
1734
  return this._isReconnecting;