ttp-agent-sdk 2.48.11 → 2.48.14

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.
@@ -19,10 +19,23 @@ class AudioProcessor extends AudioWorkletProcessor {
19
19
  this.bufferIndex = 0;
20
20
 
21
21
  // VAD (Voice Activity Detection) parameters
22
- this.silenceThreshold = 0.02; // RMS threshold for voice detection (increased to reduce ambient noise sensitivity)
22
+ this.silenceThreshold = 0.02; // Base RMS threshold for voice detection (scaled by micSensitivity below)
23
23
  this.VOICE_FRAMES_REQUIRED = 2; // Require 2 consecutive frames above threshold before activating
24
24
  this.minVoiceDuration = 100; // ms - minimum speech duration
25
25
  this.pauseThreshold = 3000; // ms - longer pause before processing
26
+
27
+ // Mic sensitivity: user/agent-adjustable multiplier on the VAD energy gate.
28
+ // 1.0 = default; 2.0 = twice as sensitive (half the RMS floor); 0.5 = half as
29
+ // sensitive (double the floor — only close/loud speech triggers, e.g. TV in the room).
30
+ this.micSensitivity = (typeof this.config.micSensitivity === 'number' && this.config.micSensitivity > 0)
31
+ ? this.config.micSensitivity : 1.0;
32
+ // While agent audio plays, the gate rises by this factor (stricter barge-in: background
33
+ // TV/chatter must not interrupt playback). The SDK main thread tracks playback state.
34
+ this.playbackActive = false;
35
+ this.PLAYBACK_GATE_FACTOR = 1.6;
36
+ // Hysteresis: once voice is active the floor drops, so a borderline signal isn't
37
+ // chopped on every frame (quiet speech tails stay under the trigger level).
38
+ this.HYSTERESIS_FACTOR = 0.75;
26
39
 
27
40
  // VAD state
28
41
  this.isVoiceActive = false;
@@ -75,6 +88,18 @@ class AudioProcessor extends AudioWorkletProcessor {
75
88
  // iOS: bypass client VAD - always send. Desktop: keep VAD (saves bandwidth, reduces noise).
76
89
  this.isCurrentlyStreaming = data.enabled && (data.bypassVad === true);
77
90
  break;
91
+
92
+ case 'setMicSensitivity': {
93
+ const v = Number(data && data.value);
94
+ if (isFinite(v) && v > 0) {
95
+ this.micSensitivity = Math.max(0.25, Math.min(4.0, v));
96
+ }
97
+ break;
98
+ }
99
+
100
+ case 'setPlaybackActive':
101
+ this.playbackActive = !!(data && data.active);
102
+ break;
78
103
 
79
104
  case 'flush':
80
105
  this.flushBuffer();
@@ -157,9 +182,16 @@ class AudioProcessor extends AudioWorkletProcessor {
157
182
  const highFreqRatio = highFreqCount / this.bufferSize;
158
183
 
159
184
  const currentTime = Date.now();
160
-
185
+
186
+ // Effective VAD floor: base threshold scaled by the mic-sensitivity multiplier,
187
+ // raised during agent playback (stricter barge-in), lowered while voice is
188
+ // already active (hysteresis, so speech tails aren't clipped).
189
+ let effectiveThreshold = this.silenceThreshold / this.micSensitivity;
190
+ if (this.playbackActive) effectiveThreshold *= this.PLAYBACK_GATE_FACTOR;
191
+ if (this.isVoiceActive) effectiveThreshold *= this.HYSTERESIS_FACTOR;
192
+
161
193
  // VAD with reduced sensitivity - require consecutive frames above threshold
162
- let hasVoice = rms > this.silenceThreshold;
194
+ let hasVoice = rms > effectiveThreshold;
163
195
  // Calculate time since last voice detection
164
196
  const timeSinceLastVoice = currentTime - this.lastVoiceTime;
165
197
 
package/dist/index.html CHANGED
@@ -23,7 +23,7 @@
23
23
  <img src="https://talktopc.com/logo192.png" alt="TTP Logo" style="width: 40px; height: 40px; border-radius: 8px;">
24
24
  <div>
25
25
  <h1 style="margin: 0; font-size: 1.4rem;">TTP Agent SDK</h1>
26
- <p class="version" style="margin: 0;">v2.48.6</p>
26
+ <p class="version" style="margin: 0;">v2.48.13</p>
27
27
  </div>
28
28
  </div>
29
29
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttp-agent-sdk",
3
- "version": "2.48.11",
3
+ "version": "2.48.14",
4
4
  "description": "Comprehensive Voice Agent SDK with Customizable Widget - Real-time audio, WebSocket communication, React components, and extensive customization options",
5
5
  "main": "dist/agent-widget.js",
6
6
  "module": "dist/agent-widget.esm.js",