@absolutejs/voice 0.0.22-beta.551 → 0.0.22-beta.553

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.
@@ -516,6 +516,18 @@ export type VoiceSessionHandle<TContext = unknown, TSession extends VoiceSession
516
516
  }) => Promise<void>;
517
517
  close: (reason?: string) => Promise<void>;
518
518
  snapshot: () => Promise<TSession>;
519
+ /**
520
+ * Mutate the live turn-detection config for this session — useful when a
521
+ * tool call wants to dial silenceMs up ("the caller asked for more time")
522
+ * or down. The change takes effect on the NEXT silence-timer schedule, so
523
+ * an in-flight commit isn't cancelled. Returns the merged config so the
524
+ * caller can confirm.
525
+ */
526
+ setTurnDetection: (patch: Partial<VoiceTurnDetectionConfig>) => Promise<{
527
+ silenceMs: number;
528
+ speechThreshold: number;
529
+ transcriptStabilityMs: number;
530
+ }>;
519
531
  };
520
532
  export type VoiceRouteResult<TResult = unknown> = {
521
533
  complete?: boolean;
@@ -882,6 +894,28 @@ export type CreateVoiceSessionOptions<TContext = unknown, TSession extends Voice
882
894
  };
883
895
  redact?: import("./redaction").VoiceTranscriptRedactor;
884
896
  semanticTurnDetector?: import("./semanticTurn").VoiceSemanticTurnDetector;
897
+ /**
898
+ * Pre-rendered filler phrases the runtime plays in the gap between
899
+ * user-turn-commit and real assistant audio (typically 800-1500ms). The
900
+ * caller hears something within ~150-300ms of stopping speaking, so the
901
+ * LLM/TTS latency feels like the bot thinking instead of dead air. Boardy's
902
+ * killer UX feature.
903
+ *
904
+ * Behavior:
905
+ * - After a turn commits, a timer fires at `fillerDelayMs` (default
906
+ * 250ms). At that point, if the real assistant audio for this turn
907
+ * hasn't started flowing yet, a random phrase is rendered via the
908
+ * configured `tts` adapter and pushed to the socket.
909
+ * - When the real assistant audio's first chunk arrives, any in-flight
910
+ * filler is cancelled (`cancelActiveTTS` clears the carrier buffer).
911
+ * - Cooldown protects against double-fillers per turn.
912
+ *
913
+ * Set `fillerPhrases: []` (or omit) to disable. Reasonable defaults if
914
+ * you enable: `["Hmm.", "Got it.", "Right.", "Mm-hm.", "Let me think.", "Okay."]`.
915
+ */
916
+ fillerPhrases?: ReadonlyArray<string>;
917
+ /** Milliseconds after turn-commit before the filler fires. Default 250ms — short enough to feel instant, long enough to skip if the LLM is very fast. */
918
+ fillerDelayMs?: number;
885
919
  assistantMode?: import("./assistantMode").VoiceAssistantMode;
886
920
  modalities?: ReadonlyArray<"audio" | "text">;
887
921
  prosody?: VoiceTTSProsody;
package/dist/index.js CHANGED
@@ -3870,6 +3870,11 @@ var createVoiceSession = (options) => {
3870
3870
  let adapterGenerationCounter = 0;
3871
3871
  let activeAdapterGeneration = 0;
3872
3872
  let activeTTSTurnId;
3873
+ let fillerTimer = null;
3874
+ let fillerActive = false;
3875
+ let fillerToken = 0;
3876
+ const fillerPhrases = (options.fillerPhrases ?? []).filter((p) => typeof p === "string" && p.trim().length > 0);
3877
+ const fillerDelayMs = options.fillerDelayMs ?? 250;
3873
3878
  const currentTurnAudio = [];
3874
3879
  const pendingUserAttachments = [];
3875
3880
  let fallbackAttemptsForCurrentTurn = 0;
@@ -5268,6 +5273,36 @@ var createVoiceSession = (options) => {
5268
5273
  }
5269
5274
  const injectedInstruction = liveOpsControl?.injectedInstruction?.trim();
5270
5275
  const ttsStreamer = options.tts ? createTurnTTSStreamer(turn, session) : undefined;
5276
+ if (fillerPhrases.length > 0 && options.tts && !ttsStreamer) {}
5277
+ if (fillerPhrases.length > 0 && options.tts) {
5278
+ fillerToken += 1;
5279
+ const myToken = fillerToken;
5280
+ if (fillerTimer)
5281
+ clearTimeout(fillerTimer);
5282
+ fillerTimer = setTimeout(() => {
5283
+ fillerTimer = null;
5284
+ if (myToken !== fillerToken)
5285
+ return;
5286
+ if (activeTTSTurnId === turn.id)
5287
+ return;
5288
+ const phrase = fillerPhrases[Math.floor(Math.random() * fillerPhrases.length)] ?? "";
5289
+ if (!phrase)
5290
+ return;
5291
+ runSerial("filler.send", async () => {
5292
+ if (myToken !== fillerToken || activeTTSTurnId === turn.id)
5293
+ return;
5294
+ const adapterSession = await ensureTTSSession();
5295
+ if (!adapterSession)
5296
+ return;
5297
+ fillerActive = true;
5298
+ try {
5299
+ await adapterSession.send(phrase);
5300
+ } catch {
5301
+ fillerActive = false;
5302
+ }
5303
+ });
5304
+ }, fillerDelayMs);
5305
+ }
5271
5306
  const committedOutput = await options.route.onTurn({
5272
5307
  api,
5273
5308
  context: options.context,
@@ -5348,6 +5383,15 @@ var createVoiceSession = (options) => {
5348
5383
  try {
5349
5384
  const activeTTSSession = await ensureTTSSession();
5350
5385
  if (activeTTSSession) {
5386
+ fillerToken += 1;
5387
+ if (fillerTimer) {
5388
+ clearTimeout(fillerTimer);
5389
+ fillerTimer = null;
5390
+ }
5391
+ if (fillerActive) {
5392
+ await cancelActiveTTS("filler-superseded").catch(() => {});
5393
+ fillerActive = false;
5394
+ }
5351
5395
  const ttsStartedAt = Date.now();
5352
5396
  activeTTSTurnId = turn.id;
5353
5397
  await appendTurnLatencyStage({
@@ -5904,6 +5948,22 @@ var createVoiceSession = (options) => {
5904
5948
  snapshot: async () => runSerial("api.snapshot", async () => readSession()),
5905
5949
  transfer: async (input) => runSerial("api.transfer", async () => {
5906
5950
  await transferInternal(input);
5951
+ }),
5952
+ setTurnDetection: async (patch) => runSerial("api.setTurnDetection", async () => {
5953
+ if (patch.silenceMs !== undefined && Number.isFinite(patch.silenceMs)) {
5954
+ turnDetection.silenceMs = Math.max(300, Math.min(15000, Math.round(patch.silenceMs)));
5955
+ }
5956
+ if (patch.speechThreshold !== undefined && Number.isFinite(patch.speechThreshold)) {
5957
+ turnDetection.speechThreshold = Math.max(0, Math.min(1, patch.speechThreshold));
5958
+ }
5959
+ if (patch.transcriptStabilityMs !== undefined && Number.isFinite(patch.transcriptStabilityMs)) {
5960
+ turnDetection.transcriptStabilityMs = Math.max(0, Math.min(5000, Math.round(patch.transcriptStabilityMs)));
5961
+ }
5962
+ return {
5963
+ silenceMs: turnDetection.silenceMs,
5964
+ speechThreshold: turnDetection.speechThreshold,
5965
+ transcriptStabilityMs: turnDetection.transcriptStabilityMs
5966
+ };
5907
5967
  })
5908
5968
  };
5909
5969
  return api;
@@ -24546,6 +24606,8 @@ var createTwilioMediaStreamBridge = (socket, options) => {
24546
24606
  sttFallback: resolveSTTFallbackConfig(options.sttFallback),
24547
24607
  sttLifecycle: options.sttLifecycle ?? runtimePreset.sttLifecycle,
24548
24608
  ...options.semanticTurnDetector ? { semanticTurnDetector: options.semanticTurnDetector } : {},
24609
+ ...options.fillerPhrases ? { fillerPhrases: options.fillerPhrases } : {},
24610
+ ...options.fillerDelayMs !== undefined ? { fillerDelayMs: options.fillerDelayMs } : {},
24549
24611
  trace: options.trace,
24550
24612
  tts: options.tts,
24551
24613
  turnDetection
@@ -43024,6 +43086,11 @@ var createContractApi = (session) => ({
43024
43086
  markNoAnswer: async () => {},
43025
43087
  markVoicemail: async () => {},
43026
43088
  receiveAudio: async () => {},
43089
+ setTurnDetection: async () => ({
43090
+ silenceMs: 0,
43091
+ speechThreshold: 0,
43092
+ transcriptStabilityMs: 0
43093
+ }),
43027
43094
  snapshot: async () => session,
43028
43095
  transfer: async () => {}
43029
43096
  });
@@ -123,6 +123,15 @@ export type TwilioMediaStreamBridgeOptions<TContext = unknown, TSession extends
123
123
  * snappy responses on clear-cut answers. See VoiceSemanticTurnDetector.
124
124
  */
125
125
  semanticTurnDetector?: import("../core/semanticTurn").VoiceSemanticTurnDetector;
126
+ /**
127
+ * Pre-rendered filler phrases ("Hmm.", "Got it.", "Let me think.") played
128
+ * in the gap between user-turn-commit and real assistant audio. Boardy's
129
+ * "the pause is character, not lag" pattern. See CreateVoiceSessionOptions
130
+ * for full semantics.
131
+ */
132
+ fillerPhrases?: ReadonlyArray<string>;
133
+ /** Milliseconds after turn-commit before the filler fires. Default 250ms. */
134
+ fillerDelayMs?: number;
126
135
  };
127
136
  export type TwilioMediaStreamBridge = {
128
137
  close: (reason?: string) => Promise<void>;
@@ -5687,6 +5687,11 @@ var createVoiceSession = (options) => {
5687
5687
  let adapterGenerationCounter = 0;
5688
5688
  let activeAdapterGeneration = 0;
5689
5689
  let activeTTSTurnId;
5690
+ let fillerTimer = null;
5691
+ let fillerActive = false;
5692
+ let fillerToken = 0;
5693
+ const fillerPhrases = (options.fillerPhrases ?? []).filter((p) => typeof p === "string" && p.trim().length > 0);
5694
+ const fillerDelayMs = options.fillerDelayMs ?? 250;
5690
5695
  const currentTurnAudio = [];
5691
5696
  const pendingUserAttachments = [];
5692
5697
  let fallbackAttemptsForCurrentTurn = 0;
@@ -7085,6 +7090,36 @@ var createVoiceSession = (options) => {
7085
7090
  }
7086
7091
  const injectedInstruction = liveOpsControl?.injectedInstruction?.trim();
7087
7092
  const ttsStreamer = options.tts ? createTurnTTSStreamer(turn, session) : undefined;
7093
+ if (fillerPhrases.length > 0 && options.tts && !ttsStreamer) {}
7094
+ if (fillerPhrases.length > 0 && options.tts) {
7095
+ fillerToken += 1;
7096
+ const myToken = fillerToken;
7097
+ if (fillerTimer)
7098
+ clearTimeout(fillerTimer);
7099
+ fillerTimer = setTimeout(() => {
7100
+ fillerTimer = null;
7101
+ if (myToken !== fillerToken)
7102
+ return;
7103
+ if (activeTTSTurnId === turn.id)
7104
+ return;
7105
+ const phrase = fillerPhrases[Math.floor(Math.random() * fillerPhrases.length)] ?? "";
7106
+ if (!phrase)
7107
+ return;
7108
+ runSerial("filler.send", async () => {
7109
+ if (myToken !== fillerToken || activeTTSTurnId === turn.id)
7110
+ return;
7111
+ const adapterSession = await ensureTTSSession();
7112
+ if (!adapterSession)
7113
+ return;
7114
+ fillerActive = true;
7115
+ try {
7116
+ await adapterSession.send(phrase);
7117
+ } catch {
7118
+ fillerActive = false;
7119
+ }
7120
+ });
7121
+ }, fillerDelayMs);
7122
+ }
7088
7123
  const committedOutput = await options.route.onTurn({
7089
7124
  api,
7090
7125
  context: options.context,
@@ -7165,6 +7200,15 @@ var createVoiceSession = (options) => {
7165
7200
  try {
7166
7201
  const activeTTSSession = await ensureTTSSession();
7167
7202
  if (activeTTSSession) {
7203
+ fillerToken += 1;
7204
+ if (fillerTimer) {
7205
+ clearTimeout(fillerTimer);
7206
+ fillerTimer = null;
7207
+ }
7208
+ if (fillerActive) {
7209
+ await cancelActiveTTS("filler-superseded").catch(() => {});
7210
+ fillerActive = false;
7211
+ }
7168
7212
  const ttsStartedAt = Date.now();
7169
7213
  activeTTSTurnId = turn.id;
7170
7214
  await appendTurnLatencyStage({
@@ -7721,6 +7765,22 @@ var createVoiceSession = (options) => {
7721
7765
  snapshot: async () => runSerial("api.snapshot", async () => readSession()),
7722
7766
  transfer: async (input) => runSerial("api.transfer", async () => {
7723
7767
  await transferInternal(input);
7768
+ }),
7769
+ setTurnDetection: async (patch) => runSerial("api.setTurnDetection", async () => {
7770
+ if (patch.silenceMs !== undefined && Number.isFinite(patch.silenceMs)) {
7771
+ turnDetection.silenceMs = Math.max(300, Math.min(15000, Math.round(patch.silenceMs)));
7772
+ }
7773
+ if (patch.speechThreshold !== undefined && Number.isFinite(patch.speechThreshold)) {
7774
+ turnDetection.speechThreshold = Math.max(0, Math.min(1, patch.speechThreshold));
7775
+ }
7776
+ if (patch.transcriptStabilityMs !== undefined && Number.isFinite(patch.transcriptStabilityMs)) {
7777
+ turnDetection.transcriptStabilityMs = Math.max(0, Math.min(5000, Math.round(patch.transcriptStabilityMs)));
7778
+ }
7779
+ return {
7780
+ silenceMs: turnDetection.silenceMs,
7781
+ speechThreshold: turnDetection.speechThreshold,
7782
+ transcriptStabilityMs: turnDetection.transcriptStabilityMs
7783
+ };
7724
7784
  })
7725
7785
  };
7726
7786
  return api;
@@ -13082,6 +13142,8 @@ var createTwilioMediaStreamBridge = (socket, options) => {
13082
13142
  sttFallback: resolveSTTFallbackConfig(options.sttFallback),
13083
13143
  sttLifecycle: options.sttLifecycle ?? runtimePreset.sttLifecycle,
13084
13144
  ...options.semanticTurnDetector ? { semanticTurnDetector: options.semanticTurnDetector } : {},
13145
+ ...options.fillerPhrases ? { fillerPhrases: options.fillerPhrases } : {},
13146
+ ...options.fillerDelayMs !== undefined ? { fillerDelayMs: options.fillerDelayMs } : {},
13085
13147
  trace: options.trace,
13086
13148
  tts: options.tts,
13087
13149
  turnDetection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.551",
3
+ "version": "0.0.22-beta.553",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",