@absolutejs/voice 0.0.22-beta.552 → 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.
@@ -894,6 +894,28 @@ export type CreateVoiceSessionOptions<TContext = unknown, TSession extends Voice
894
894
  };
895
895
  redact?: import("./redaction").VoiceTranscriptRedactor;
896
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;
897
919
  assistantMode?: import("./assistantMode").VoiceAssistantMode;
898
920
  modalities?: ReadonlyArray<"audio" | "text">;
899
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({
@@ -24562,6 +24606,8 @@ var createTwilioMediaStreamBridge = (socket, options) => {
24562
24606
  sttFallback: resolveSTTFallbackConfig(options.sttFallback),
24563
24607
  sttLifecycle: options.sttLifecycle ?? runtimePreset.sttLifecycle,
24564
24608
  ...options.semanticTurnDetector ? { semanticTurnDetector: options.semanticTurnDetector } : {},
24609
+ ...options.fillerPhrases ? { fillerPhrases: options.fillerPhrases } : {},
24610
+ ...options.fillerDelayMs !== undefined ? { fillerDelayMs: options.fillerDelayMs } : {},
24565
24611
  trace: options.trace,
24566
24612
  tts: options.tts,
24567
24613
  turnDetection
@@ -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({
@@ -13098,6 +13142,8 @@ var createTwilioMediaStreamBridge = (socket, options) => {
13098
13142
  sttFallback: resolveSTTFallbackConfig(options.sttFallback),
13099
13143
  sttLifecycle: options.sttLifecycle ?? runtimePreset.sttLifecycle,
13100
13144
  ...options.semanticTurnDetector ? { semanticTurnDetector: options.semanticTurnDetector } : {},
13145
+ ...options.fillerPhrases ? { fillerPhrases: options.fillerPhrases } : {},
13146
+ ...options.fillerDelayMs !== undefined ? { fillerDelayMs: options.fillerDelayMs } : {},
13101
13147
  trace: options.trace,
13102
13148
  tts: options.tts,
13103
13149
  turnDetection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.552",
3
+ "version": "0.0.22-beta.553",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",