@7ots/cli 0.1.13 → 0.1.15

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/cli/lib/brain.mjs CHANGED
@@ -18,6 +18,7 @@ import { createLLM } from '../../server/llm.mjs';
18
18
  import { env, loadConfig, ORQUESTA_URL } from './config.mjs';
19
19
  import { characterPrompt, integrationsPrompt } from './integrations.mjs';
20
20
  import { ensureHome, PET_PORT } from './paths.mjs';
21
+ import { SPEECH_TAGS_PROMPT } from '../../src/voice/tags.js';
21
22
 
22
23
  // Started from a desktop launcher or autostart, the daemon gets a bare PATH (/usr/bin:/bin) and can't find
23
24
  // CLIs installed per user (claude lives in ~/.local/bin): add the usual places before looking for them.
@@ -47,6 +48,9 @@ export function detectClis() {
47
48
  }
48
49
 
49
50
  /** System prompt shared by every brain. */
51
+ /** Voices that perform speech tags: xAI, and ElevenLabs on its v3 model. */
52
+ export const expressiveVoice = (v = {}) => v.kind === 'grok' || (v.kind === 'elevenlabs' && /v3/.test(v.providers?.elevenlabs?.model || ''));
53
+
50
54
  export function petSystem(identity, { lang, role = 'pet' } = {}) {
51
55
  const L = LANG_NAME[lang || identity.language] || 'English';
52
56
  const base = identityPrompt(identity, 'en');
@@ -64,8 +68,9 @@ export function petSystem(identity, { lang, role = 'pet' } = {}) {
64
68
  } catch {}
65
69
  const sheet = characterPrompt(config.character);
66
70
  const tools = role === 'assistant' ? integrationsPrompt(config) : '';
71
+ const tone = config.voice?.expressive && expressiveVoice(config.voice) ? `\n${SPEECH_TAGS_PROMPT}` : '';
67
72
  // 'auto': the language the human just wrote in (they may switch from the ot's usual one)
68
- return `${base}${sheet ? `\n${sheet}` : ''}\n${job}${tools ? `\n${tools}` : ''}\n${lang === 'auto' ? 'Always answer in the language your human writes in.' : `Always answer in ${L}.`}`;
73
+ return `${base}${sheet ? `\n${sheet}` : ''}\n${job}${tools ? `\n${tools}` : ''}${tone}\n${lang === 'auto' ? 'Always answer in the language your human writes in.' : `Always answer in ${L}.`}`;
69
74
  }
70
75
 
71
76
  function runCli({ cli, model, command }, prompt, timeoutMs, files) {
@@ -65,6 +65,7 @@ import { defineIdentity, GROK_VOICES, OPENAI_VOICES, TTS_MODELS } from '../../sr
65
65
  import { normalizeMod, normalizeMods, MAX_MODS } from '../../src/character/mods.js';
66
66
  import { MOD_CATALOG } from '../../src/character/mods/index.js';
67
67
  import { DANCES } from '../../src/character/motion.js';
68
+ import { stripSpeechTags } from '../../src/voice/tags.js';
68
69
 
69
70
  /** Mods importados en este pet (~/.7ots/mods/library.json), normalizados. */
70
71
  // scenes between ots on the same desktop (pet/electron/director.cjs plays them)
@@ -131,6 +132,10 @@ const uiLangOf = (c, fallback) => [process.env.SEVENOTS_LANG, c.lang, String(pro
131
132
  const brainLabel = (b = {}) => (b.kind === 'cli' ? `${b.cli}${b.model ? ` · ${b.model}` : ''}` : b.kind === 'api' ? `${b.provider || 'api'}${b.model ? ` · ${b.model}` : ''}` : b.kind || 'lines');
132
133
 
133
134
  const GAP = { 0: Infinity, 1: 10 * 60_000, 2: 90_000, 3: 20_000 }; // minimum silence between spontaneous lines
135
+ // "important" ones (agent finished / waiting / a new session) obey the annoyance level too: 0 = never a word on its own
136
+ const IMPORTANT_GAP = { 0: Infinity, 1: 5 * 60_000, 2: 60_000, 3: 15_000 };
137
+ const HELLO_GAP = 30 * 60_000; // every new agent session says "start": one hello per half hour is plenty
138
+ const CHAT_QUIET = 90_000; // while you talk to it, no small talk on top of the conversation
134
139
  const CHATTY = { 0: 0, 1: 0.02, 2: 0.12, 3: 0.35 }; // chance to comment a routine event (tool, ok, prompt)
135
140
  const IDLE = { 0: Infinity, 1: 60 * 60_000, 2: 20 * 60_000, 3: 5 * 60_000 }; // idle chatter every…
136
141
 
@@ -172,6 +177,8 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
172
177
  const activity = []; // what happened lately, for the window's feed
173
178
  let thinking = false;
174
179
  let lastSpoke = 0;
180
+ let lastHello = 0;
181
+ let chatUntil = 0;
175
182
  let lastIdle = Date.now();
176
183
  let viewSet = null; // 2D/3D changed in the settings since start: pages that (re)connect pick it up too
177
184
 
@@ -227,11 +234,13 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
227
234
 
228
235
  async function speak(kind, vars = {}, situation = '', { force = false, gesture = null } = {}) {
229
236
  const now = Date.now();
230
- if (!force && (pet.asleep || now - lastSpoke < GAP[annoy])) {
237
+ const quiet = now < chatUntil || (kind === 'hello' && now - lastHello < HELLO_GAP) || (force ? now - lastSpoke < IMPORTANT_GAP[annoy] : pet.asleep || now - lastSpoke < GAP[annoy]);
238
+ if (quiet) {
231
239
  broadcast({ gesture });
232
240
  return;
233
241
  }
234
242
  lastSpoke = now;
243
+ if (kind === 'hello') lastHello = now;
235
244
  let text = '';
236
245
  if (brain.kind !== 'lines' && situation && !thinking) {
237
246
  thinking = true;
@@ -253,7 +262,8 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
253
262
  history.push(text);
254
263
  if (history.length > 6) history.shift();
255
264
  pet.lastTalk = now;
256
- broadcast({ say: text, gesture, thinking: false });
265
+ if (Date.now() < chatUntil) return broadcast({ thinking: false }); // you started talking to it while it thought
266
+ broadcast({ say: text, gesture, thinking: false, ambient: true });
257
267
  }
258
268
 
259
269
  const SITUATION = {
@@ -422,12 +432,12 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
422
432
  log,
423
433
  onSeen: (row) => {
424
434
  broadcast({ seen: row });
425
- if (!row.say || pet.asleep || Date.now() - lastSpoke < GAP[annoy] || Math.random() >= CHATTY[annoy]) return;
435
+ if (!row.say || pet.asleep || Date.now() < chatUntil || Date.now() - lastSpoke < GAP[annoy] || Math.random() >= CHATTY[annoy]) return;
426
436
  lastSpoke = Date.now();
427
437
  pet.lastTalk = lastSpoke;
428
438
  history.push(row.say);
429
439
  if (history.length > 6) history.shift();
430
- broadcast({ say: row.say, gesture: 'point' });
440
+ broadcast({ say: row.say, gesture: 'point', ambient: true });
431
441
  },
432
442
  });
433
443
 
@@ -690,7 +700,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
690
700
  if (['none', 'browser'].includes(kind)) return json(501, { error: 'browser voice' });
691
701
  try {
692
702
  if (kind === 'local') {
693
- const { audio, contentType } = await synthesizeLocal(String(data.text || '').slice(0, 600), { lang });
703
+ const { audio, contentType } = await synthesizeLocal(stripSpeechTags(data.text).slice(0, 600), { lang });
694
704
  return res.writeHead(200, { 'Content-Type': contentType }).end(audio);
695
705
  }
696
706
  const { synthesize } = await import('../../server/tts.mjs');
@@ -721,9 +731,11 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
721
731
  if (p === '/ask') {
722
732
  const text = String(data.text || '').trim().slice(0, 800);
723
733
  if (!text) return json(400, { error: 'text' });
734
+ chatUntil = Date.now() + CHAT_QUIET;
724
735
  broadcast({ thinking: true, activity: track({ type: 'prompt', text }) });
725
736
  const r = await assistant.ask(text);
726
737
  lastSpoke = Date.now();
738
+ chatUntil = Date.now() + CHAT_QUIET;
727
739
  broadcast({ thinking: false, stir: pet.asleep, say: r.reply, gesture: r.actions.length ? 'nod' : null, point: r.actions.some((a) => a.type === 'open') ? 'browser' : null });
728
740
  return json(200, r);
729
741
  }
@@ -827,7 +839,7 @@ export function startPetServer({ port = PET_PORT, log = () => {} } = {}) {
827
839
  let mods = normalizeMods(ch.mods);
828
840
  if (data.remove) mods = mods.filter((m) => m.id !== data.remove);
829
841
  if (data.add || data.mod) {
830
- const m = data.add ? MOD_CATALOG.find((c) => c.id === data.add) : data.mod;
842
+ const m = data.add ? MOD_CATALOG.find((c) => c.id === data.add) || modLibrary().find((c) => c.id === data.add) : data.mod; // catalog, or one imported earlier
831
843
  const n = m && normalizeMod(m);
832
844
  if (!n) return [400, { error: 'mod' }];
833
845
  if (!mods.some((x) => x.id === n.id) && mods.length >= MAX_MODS) return [400, { error: 'maxMods' }];
@@ -1095,9 +1107,11 @@ ${keys.map((k) => FIELDS[k]).join('\n')}`;
1095
1107
  if (d.screen?.every !== undefined) next.screen.every = Math.max(1, Math.min(60, Math.round(Number(d.screen.every)) || 5));
1096
1108
  let reload = false;
1097
1109
  if (d.voice) {
1098
- if (!['none', 'browser', 'local', 'elevenlabs', 'openai', 'apuchat', 'grok', 'fish'].includes(d.voice.kind)) return 'voice';
1099
- reload = d.voice.kind !== next.voice.kind;
1100
- next.voice = { ...next.voice, kind: d.voice.kind };
1110
+ const vk = d.voice.kind ?? next.voice.kind;
1111
+ if (!['none', 'browser', 'local', 'elevenlabs', 'openai', 'apuchat', 'grok', 'fish'].includes(vk)) return 'voice';
1112
+ reload = vk !== next.voice.kind;
1113
+ next.voice = { ...next.voice, kind: vk };
1114
+ if (d.voice.expressive !== undefined) next.voice.expressive = !!d.voice.expressive;
1101
1115
  // each provider's own voice, model and style ({ elevenlabs: { voiceId, model }, openai: { voiceId, model, style } … })
1102
1116
  const pv = d.voice.providers;
1103
1117
  if (pv && typeof pv === 'object') {
package/cli/pet/pet.html CHANGED
@@ -564,13 +564,24 @@
564
564
  if (typeof ch.speak !== 'function') return; // older character bundle
565
565
  lip = ch.speak(text, { durationMs: ms || 500 + text.length * 60 });
566
566
  }
567
- async function speak(text) {
567
+ // one voice at a time: a new line cuts the one playing (small talk never cuts a reply: see the say message)
568
+ const hush = () => {
569
+ if (speak.cur) speak.cur.onended = speak.cur.onerror = null, speak.cur.pause(), (speak.cur = null), talk(false);
570
+ if ('speechSynthesis' in window) speechSynthesis.cancel();
571
+ };
572
+ async function speak(text, reply = false) {
568
573
  if (BOOT.voice?.kind === 'none') return;
574
+ hush();
575
+ const turn = (speak.turn = (speak.turn || 0) + 1);
569
576
  if (BOOT.voice?.kind && BOOT.voice.kind !== 'browser') {
570
577
  try {
571
578
  const r = await post('/tts', { text });
572
579
  if (r.ok) {
573
- const audio = new Audio(URL.createObjectURL(await r.blob()));
580
+ const blob = await r.blob();
581
+ if (turn !== speak.turn) return; // a newer line arrived while this one was synthesizing
582
+ const audio = new Audio(URL.createObjectURL(blob));
583
+ speak.cur = audio;
584
+ speak.reply = reply;
574
585
  audio.onplay = () => {
575
586
  // real audio drives the mouth when possible, else text-timed visemes
576
587
  try {
@@ -579,18 +590,18 @@
579
590
  const an = ctx.createAnalyser();
580
591
  src.connect(an);
581
592
  an.connect(ctx.destination);
582
- const stop = ch.lipsync?.(an, { text });
593
+ const stop = ch.lipsync?.(an, { text: clean(text) });
583
594
  if (stop) return void (lip = { stop });
584
595
  } catch {}
585
- talk(true, text, (audio.duration || 0) * 1000);
596
+ talk(true, clean(text), (audio.duration || 0) * 1000);
586
597
  };
587
- audio.onended = audio.onerror = () => talk(false);
598
+ audio.onended = audio.onerror = () => ((speak.cur = null), talk(false));
588
599
  return await audio.play();
589
600
  }
590
601
  } catch {}
591
602
  }
592
- if (!('speechSynthesis' in window)) return;
593
- const u = new SpeechSynthesisUtterance(text);
603
+ if (turn !== speak.turn || !('speechSynthesis' in window)) return;
604
+ const u = new SpeechSynthesisUtterance(clean(text));
594
605
  u.lang = id.voice?.lang || lang;
595
606
  u.rate = id.voice?.rate || 1;
596
607
  u.pitch = id.voice?.pitch || 1;
@@ -631,13 +642,17 @@
631
642
  }
632
643
  ch.gesture(Math.random() < 0.5 ? 'nod' : 'wiggle');
633
644
  }
634
- function say(text, withFace = false) {
645
+ // speech tags ([laugh], <whisper>…: settings → Voice → expressions) go to the voice, never to the bubble (as src/voice/tags.js)
646
+ const clean = (t) => String(t ?? '').replace(/<\/?(loud|soft|whisper|fast|slow|singing)>/gi, '').replace(/\s*\[(pause|long-pause|laugh|cry|mouth-click|breath|sigh)\]\s*/gi, ' ').replace(/\s{2,}/g, ' ').trim();
647
+ function say(raw, withFace = false, ambient = false) {
648
+ if (ambient && speak.cur && speak.reply) return; // small talk waits for the answer to finish
649
+ const text = clean(raw);
635
650
  showBubble(document.createTextNode(text), Math.max(4500, text.length * 90));
636
651
  talk(true, text); // the mouth moves with the words even without a voice; a real voice re-syncs it
637
652
  clearTimeout(say.t);
638
653
  say.t = setTimeout(() => talk(false), 500 + text.length * 60);
639
654
  if (withFace) react(text);
640
- speak(text);
655
+ speak(raw, !ambient);
641
656
  }
642
657
  // It asks before acting for you (Orquesta…): Approve / Reject in the bubble, answered on POST /approve.
643
658
  let asking = null;
@@ -727,7 +742,7 @@
727
742
  if (m.gesture) ch.gesture(m.gesture);
728
743
  if (m.morph) ch.morph?.(m.morph);
729
744
  if (m.effect) ch.effect?.(m.effect);
730
- if (m.say) say(m.say, !m.gesture);
745
+ if (m.say) say(m.say, !m.gesture, !!m.ambient);
731
746
  if (m.dance) dance(m.dance);
732
747
  if (m.entrance) entrance(m.entrance);
733
748
  if (m.point && desktop) window.__goal = m.point; // the desktop shell walks it over there
@@ -258,6 +258,7 @@
258
258
  <section aria-labelledby="hVoice">
259
259
  <h2 id="hVoice" data-t="voiceH"></h2>
260
260
  <p class="hint" data-t="voiceHint"></p>
261
+ <div id="vExpr"></div>
261
262
  <div class="opts" id="voices"></div>
262
263
  <div class="row">
263
264
  <button class="primary" id="saveVoice" data-t="save"></button>
@@ -376,7 +377,7 @@
376
377
  accH: 'Your 7ots account', accHint: 'Connect it to pick which of your ots lives on this computer, and bring its look, voice and personality from 7ots.com.',
377
378
  connect: 'Connect with 7ots.com', connecting: 'Waiting for you in the browser…', openAgain: 'Didn’t open? Open the page', signedAs: 'Connected as {who}', logout: 'Disconnect', noOts: 'No ots in your account yet.', newOt: 'Create one on 7ots.com',
378
379
  useThis: 'Use this one', current: 'On this computer', switching: 'Switching…', resync: 'Sync again', restarting: 'Restarting with {name}…', heroH: 'Bring your ots home', heroP: 'Sign in once and choose which of your ots lives on this computer.', perkLook: 'Look', perkVoice: 'Voice', perkMind: 'Personality', heroNote: 'Opens 7ots.com in your browser: press Connect there and come back.', cancel: 'Cancel', connectedAs: 'Connected as', yourOts: 'Your ots', slow: 'Taking a while… still restarting.', card: 'Card', invite: 'Also on this computer', dismiss: 'Turn off', visiting: 'Also active', maxOts: 'Two at a time for now',
379
- voiceH: 'Voice', voiceHint: 'How it speaks out loud, and how it hears you (🎙️ in its menu or Ctrl+Alt+Space).',
380
+ voiceH: 'Voice', vExpr: 'Expressions', vExprHint: 'It picks its own tone: laughs, sighs, whispers, a sad or excited voice. Works with Grok (xAI) and ElevenLabs v3; other voices just skip them.', voiceHint: 'How it speaks out loud, and how it hears you (🎙️ in its menu or Ctrl+Alt+Space).',
380
381
  vnone: 'Silent', vnoneD: 'Only speech bubbles.', vbrowser: 'System voice', vbrowserD: 'The browser’s speech synthesis. Often has no voices on Linux.',
381
382
  vlocal: 'Local voice (Piper)', vlocalD: 'Runs on this computer, free and private. Picks Spanish or English per line.', vlocalNo: 'not installed (7ots voice install)',
382
383
  velevenlabs: 'ElevenLabs', velevenlabsD: 'Natural cloud voices, with your key.', vopenai: 'OpenAI', vopenaiD: 'OpenAI text-to-speech, with your key.',
@@ -410,7 +411,7 @@
410
411
  accH: 'Tu cuenta 7ots', accHint: 'Conéctala para elegir cuál de tus ots vive en este computador, y traer su aspecto, voz y personalidad desde 7ots.com.',
411
412
  connect: 'Conectar con 7ots.com', connecting: 'Esperándote en el navegador…', openAgain: '¿No se abrió? Abrir la página', signedAs: 'Conectado como {who}', logout: 'Desconectar', noOts: 'Todavía no hay ots en tu cuenta.', newOt: 'Crea uno en 7ots.com',
412
413
  useThis: 'Usar este', current: 'En este computador', switching: 'Cambiando…', resync: 'Sincronizar', restarting: 'Reiniciando con {name}…', heroH: 'Trae a tus ots a casa', heroP: 'Inicia sesión una vez y elige cuál de tus ots vive en este computador.', perkLook: 'Aspecto', perkVoice: 'Voz', perkMind: 'Personalidad', heroNote: 'Abre 7ots.com en tu navegador: aprieta Conectar ahí y vuelve.', cancel: 'Cancelar', connectedAs: 'Conectado como', yourOts: 'Tus ots', slow: 'Está tardando… sigue reiniciando.', card: 'Tarjeta', invite: 'Activar también aquí', dismiss: 'Desactivar', visiting: 'También activo', maxOts: 'Por ahora, dos a la vez',
413
- voiceH: 'Voz', voiceHint: 'Cómo habla en voz alta, y cómo te escucha (🎙️ en su menú o Ctrl+Alt+Espacio).',
414
+ voiceH: 'Voz', vExpr: 'Expresiones', vExprHint: 'Elige su propio tono: risas, suspiros, susurros, voz triste o emocionada. Funciona con Grok (xAI) y ElevenLabs v3; las otras voces las omiten.', voiceHint: 'Cómo habla en voz alta, y cómo te escucha (🎙️ en su menú o Ctrl+Alt+Espacio).',
414
415
  vnone: 'Mudo', vnoneD: 'Solo globos de texto.', vbrowser: 'Voz del sistema', vbrowserD: 'La síntesis del navegador. En Linux suele no tener voces.',
415
416
  vlocal: 'Voz local (Piper)', vlocalD: 'Corre en este computador, gratis y privada. Elige español o inglés por frase.', vlocalNo: 'no instalada (7ots voice install)',
416
417
  velevenlabs: 'ElevenLabs', velevenlabsD: 'Voces naturales en la nube, con tu key.', vopenai: 'OpenAI', vopenaiD: 'Texto a voz de OpenAI, con tu key.',
@@ -444,7 +445,7 @@
444
445
  accH: 'Sua conta 7ots', accHint: 'Conecte para escolher qual dos seus ots vive neste computador, e trazer visual, voz e personalidade do 7ots.com.',
445
446
  connect: 'Conectar com 7ots.com', connecting: 'Esperando você no navegador…', openAgain: 'Não abriu? Abrir a página', signedAs: 'Conectado como {who}', logout: 'Desconectar', noOts: 'Ainda não há ots na sua conta.', newOt: 'Crie um no 7ots.com',
446
447
  useThis: 'Usar este', current: 'Neste computador', switching: 'Trocando…', resync: 'Sincronizar', restarting: 'Reiniciando com {name}…', heroH: 'Traga seus ots para casa', heroP: 'Entre uma vez e escolha qual dos seus ots vive neste computador.', perkLook: 'Visual', perkVoice: 'Voz', perkMind: 'Personalidade', heroNote: 'Abre o 7ots.com no navegador: aperte Conectar lá e volte.', cancel: 'Cancelar', connectedAs: 'Conectado como', yourOts: 'Seus ots', slow: 'Está demorando… ainda reiniciando.', card: 'Carta', invite: 'Ativar também aqui', dismiss: 'Desativar', visiting: 'Também ativo', maxOts: 'Por enquanto, dois de cada vez',
447
- voiceH: 'Voz', voiceHint: 'Como ele fala em voz alta, e como te ouve (🎙️ no menu ou Ctrl+Alt+Espaço).',
448
+ voiceH: 'Voz', vExpr: 'Expressões', vExprHint: 'Escolhe o próprio tom: risadas, suspiros, sussurros, voz triste ou animada. Funciona com Grok (xAI) e ElevenLabs v3; as outras vozes as ignoram.', voiceHint: 'Como ele fala em voz alta, e como te ouve (🎙️ no menu ou Ctrl+Alt+Espaço).',
448
449
  vnone: 'Mudo', vnoneD: 'Só balões de texto.', vbrowser: 'Voz do sistema', vbrowserD: 'A síntese do navegador. No Linux costuma não ter vozes.',
449
450
  vlocal: 'Voz local (Piper)', vlocalD: 'Roda neste computador, grátis e privada. Escolhe espanhol ou inglês por frase.', vlocalNo: 'não instalada (7ots voice install)',
450
451
  velevenlabs: 'ElevenLabs', velevenlabsD: 'Vozes naturais na nuvem, com sua key.', vopenai: 'OpenAI', vopenaiD: 'Texto para voz da OpenAI, com sua key.',
@@ -1068,6 +1069,11 @@
1068
1069
  opt('grok', [vkey('XAI_API_KEY', 'xAI ' + t('key'), S.voices.keys.grok), vconf('grok')]),
1069
1070
  opt('fish', [vkey('FISH_API_KEY', 'Fish Audio ' + t('key'), S.voices.keys.fish), vconf('fish')]),
1070
1071
  );
1072
+ // expressions: the brain picks the tone and marks it with speech tags the voice performs
1073
+ const ex = el('input', { type: 'checkbox', checked: !!S.config.voice?.expressive });
1074
+ const exMsg = el('span', { className: 'msg', role: 'status' });
1075
+ ex.addEventListener('change', () => save({ voice: { expressive: ex.checked } }, exMsg));
1076
+ $('#vExpr').replaceChildren(el('label', { className: 'chip' }, ex, t('vExpr')), ' ', el('small', { textContent: t('vExprHint') }), exMsg);
1071
1077
  const stt = { local: t('sttLocal'), openai: 'OpenAI', elevenlabs: 'ElevenLabs' }[S.stt] || t('sttNone');
1072
1078
  $('#stt').replaceChildren(t('sttNow'), ' ', el('b', { textContent: stt }));
1073
1079
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@7ots/cli",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "7ots.com — your AI companion with a face of its own: a desktop pet that watches over your coding agent (Claude Code and shell hooks), a personal assistant (reminders, alerts, notes, opens sites, sees your screen if allowed) and a reproducible identity (face, personality, voice) for any agent — in apuchat meet calls, Orquesta projects or your own server.",
5
5
  "homepage": "https://7ots.com",
6
6
  "repository": {
package/server/tts.mjs CHANGED
@@ -28,6 +28,7 @@
28
28
 
29
29
  import { OPENAI_VOICES } from './identity.mjs';
30
30
  import { i18nError } from './i18n.mjs';
31
+ import { speechTagsFor } from '../src/voice/tags.js';
31
32
 
32
33
  const PROVIDERS = ['apuchat', 'elevenlabs', 'grok', 'fish', 'openai'];
33
34
  const TIMEOUT_MS = 20_000;
@@ -57,7 +58,7 @@ export function openaiTtsKey(env = process.env) {
57
58
 
58
59
  export async function synthesize({ text, voice = {}, env = process.env }) {
59
60
  const provider = PROVIDERS.includes(voice.provider) ? voice.provider : voice.provider === 'browser' ? 'none' : ttsProvider(env);
60
- const input = String(text || '').slice(0, 1500);
61
+ const input = speechTagsFor(text, provider, voice.model || (provider === 'elevenlabs' ? env.ELEVENLABS_MODEL : '')).slice(0, 1500);
61
62
  if (!input) throw i18nError(400, 'server.tts.empty');
62
63
 
63
64
  if (provider === 'apuchat') {
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Speech tags: the brain marks tone ("expressions" in settings → Voice) and the voice performs it.
3
+ * xAI reads them as is; ElevenLabs v3 gets its own audio tags; every other voice (and the bubble) gets clean text.
4
+ */
5
+ const INLINE = /\s*\[(pause|long-pause|laugh|cry|mouth-click|breath|sigh)\]\s*/gi;
6
+ const WRAP = /<\/?(loud|soft|whisper|fast|slow|singing)>/gi;
7
+
8
+ export function stripSpeechTags(text) {
9
+ return String(text ?? '').replace(WRAP, '').replace(INLINE, ' ').replace(/\s{2,}/g, ' ').trim();
10
+ }
11
+
12
+ const EL_INLINE = { laugh: '[laughs]', cry: '[crying]', sigh: '[sighs]', breath: '[exhales]', pause: '…', 'long-pause': '… …', 'mouth-click': '' };
13
+ const EL_WRAP = { whisper: '[whispers]', soft: '[softly]', loud: '[shouting]', slow: '[slowly]', fast: '[quickly]', singing: '[sings]' };
14
+
15
+ /** The text a provider should get: tags kept (xAI), translated (ElevenLabs v3) or removed. */
16
+ export function speechTagsFor(text, provider, model = '') {
17
+ if (provider === 'grok') return String(text ?? '');
18
+ if (provider === 'elevenlabs' && /v3/.test(model)) {
19
+ return String(text ?? '')
20
+ .replace(/<(loud|soft|whisper|fast|slow|singing)>/gi, (_, t) => `${EL_WRAP[t.toLowerCase()]} `)
21
+ .replace(/<\/(loud|soft|whisper|fast|slow|singing)>/gi, '')
22
+ .replace(/\[(pause|long-pause|laugh|cry|mouth-click|breath|sigh)\]/gi, (_, t) => EL_INLINE[t.toLowerCase()])
23
+ .replace(/\s{2,}/g, ' ')
24
+ .trim();
25
+ }
26
+ return stripSpeechTags(text);
27
+ }
28
+
29
+ export const SPEECH_TAGS_PROMPT =
30
+ 'Your words are spoken aloud by an expressive voice, and you choose the tone. When it fits (not in every line) add: [laugh], [sigh], [cry], [breath] or [pause] where the sound goes, or wrap words in <whisper>…</whisper>, <soft>…</soft>, <loud>…</loud>, <slow>…</slow> or <fast>…</fast>. Sad news sounds soft and slow, a joke gets a laugh. No other brackets or angle brackets.';