@todoforai/voiceloop 0.1.23 → 0.1.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/voiceloop",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "Fast, interruptible browser voice agent: VAD → STT → LLM → TTS with real barge-in, echo filtering, streaming first-sentence TTS and tap-to-seek. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -380,7 +380,7 @@ export class StreamingTTS implements VoiceTTS {
380
380
  * talks to ElevenLabs directly and is dev-only. `headers` authenticate proxy requests
381
381
  * (e.g. { 'X-API-Key': ... }) and are never sent on a direct ElevenLabs call. */
382
382
  export class ElevenLabsTTS extends StreamingTTS {
383
- constructor(options?: { ttsUrl?: string; apiKey?: string; voiceId?: string; modelId?: string; format?: string; headers?: Record<string, string> });
383
+ constructor(options?: { ttsUrl?: string; apiKey?: string; voiceId?: string; modelId?: string; format?: string; headers?: Record<string, string>; languageCode?: string });
384
384
  warm(): Promise<void>;
385
385
  }
386
386
 
@@ -19,10 +19,13 @@ const EL_API = 'https://api.elevenlabs.io/v1/text-to-speech';
19
19
 
20
20
  export class ElevenLabsTTS extends StreamingTTS {
21
21
  constructor({ ttsUrl, apiKey, voiceId = 'JBFqnCBsd6RMkjVDRZzb' /* George */,
22
- modelId = 'eleven_flash_v2_5', format = 'mp3_44100_64', headers = {} } = {}) {
22
+ modelId = 'eleven_flash_v2_5', format = 'mp3_44100_64', headers = {}, languageCode = '' } = {}) {
23
23
  super(voiceId);
24
24
  if (!ttsUrl && !apiKey) throw new Error('ElevenLabsTTS needs ttsUrl (backend proxy) or apiKey (direct, dev only)');
25
25
  this.ttsUrl = ttsUrl; this.apiKey = apiKey; this.modelId = modelId; this.format = format;
26
+ // ISO 639-1 ('hu'). Without it Flash auto-detects per SENTENCE — short clips get misread as
27
+ // English and spoken with English phonetics. Base code only; '' = let the model guess.
28
+ this.languageCode = String(languageCode || '').split(/[-_]/)[0].toLowerCase();
26
29
  this.headers = headers; // proxy-path auth (X-API-Key etc.) — never sent to ElevenLabs directly
27
30
  }
28
31
 
@@ -58,8 +61,11 @@ export class ElevenLabsTTS extends StreamingTTS {
58
61
  method: 'POST',
59
62
  headers: { 'Content-Type': 'application/json', ...(direct ? { 'xi-api-key': this.apiKey } : this.headers) },
60
63
  // The proxy form carries voice/model/format in the body so one backend route serves any voice.
61
- body: JSON.stringify(direct ? { text, model_id: this.modelId }
62
- : { text, voice_id: this.voiceId, model_id: this.modelId, output_format: this.format }),
64
+ body: JSON.stringify({
65
+ text, model_id: this.modelId,
66
+ ...(this.languageCode ? { language_code: this.languageCode } : {}),
67
+ ...(direct ? {} : { voice_id: this.voiceId, output_format: this.format }),
68
+ }),
63
69
  signal,
64
70
  });
65
71
  if (!res.ok) throw new Error(`ElevenLabs TTS ${res.status}: ${(await res.text().catch(() => '')).slice(0, 200)}`);
@@ -979,6 +979,11 @@ export class VoiceAgent {
979
979
  // so it could only ever become a stuck spinner — drop it. The outcome chunk still lands.
980
980
  if (finalized || !item.id || known) continue;
981
981
  accept(item).announced = true;
982
+ // While the cursor is live the answer is only published on playback ticks, so the host's
983
+ // copy may lag the tokens generated just before this call. Publish the exact answer at
984
+ // the boundary FIRST: a host that splits the reply around its calls (text → chip → text
985
+ // after the result) then cuts at the model's real position, not a frame-old one.
986
+ if (self._cursorLive) self.onEvent({ type: 'assistant', text: self._replyText, full: answer, final: false, turn });
982
987
  self.onEvent({ type: 'tool', name: item.tool, id: item.id, args: item.args, running: true });
983
988
  continue;
984
989
  }