agentgui 1.0.222 → 1.0.223

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.
Files changed (2) hide show
  1. package/lib/speech.js +39 -5
  2. package/package.json +1 -1
package/lib/speech.js CHANGED
@@ -27,6 +27,12 @@ const POCKET_TTS_VOICES = [
27
27
  ];
28
28
 
29
29
  const PREDEFINED_IDS = new Set(POCKET_TTS_VOICES.filter(v => v.id !== 'default').map(v => v.id));
30
+ const FALLBACK_VOICE = 'cosette';
31
+
32
+ function isVoiceCloningError(err) {
33
+ const msg = (err.message || err.stderr || String(err)).toLowerCase();
34
+ return msg.includes('voice cloning') || msg.includes('could not download the weights');
35
+ }
30
36
  const POCKET_PORT = 8787;
31
37
 
32
38
  const needsPatch = !serverTTS.getVoices(EXTRA_VOICE_DIRS).some(v => v.id === 'alba' && !v.isCustom);
@@ -79,11 +85,19 @@ function getSTT() {
79
85
  return serverSTT.getSTT();
80
86
  }
81
87
 
82
- function synthesize(text, voiceId) {
83
- if (needsPatch && voiceId && PREDEFINED_IDS.has(voiceId)) {
84
- return synthesizeDirect(text, voiceId);
88
+ async function synthesize(text, voiceId) {
89
+ try {
90
+ if (needsPatch && voiceId && PREDEFINED_IDS.has(voiceId)) {
91
+ return await synthesizeDirect(text, voiceId);
92
+ }
93
+ return await serverTTS.synthesize(text, voiceId, EXTRA_VOICE_DIRS);
94
+ } catch (err) {
95
+ if (isVoiceCloningError(err) && voiceId && !PREDEFINED_IDS.has(voiceId)) {
96
+ console.log(`[TTS] Voice cloning failed for "${voiceId}", falling back to ${FALLBACK_VOICE}`);
97
+ return synthesize(text, FALLBACK_VOICE);
98
+ }
99
+ throw err;
85
100
  }
86
- return serverTTS.synthesize(text, voiceId, EXTRA_VOICE_DIRS);
87
101
  }
88
102
 
89
103
  function synthesizeStream(text, voiceId) {
@@ -95,7 +109,27 @@ function synthesizeStream(text, voiceId) {
95
109
  }
96
110
  })();
97
111
  }
98
- return serverTTS.synthesizeStream(text, voiceId, EXTRA_VOICE_DIRS);
112
+ return synthesizeStreamWithFallback(text, voiceId);
113
+ }
114
+
115
+ function synthesizeStreamWithFallback(text, voiceId) {
116
+ let fellBack = false;
117
+ const upstream = serverTTS.synthesizeStream(text, voiceId, EXTRA_VOICE_DIRS);
118
+ return (async function* () {
119
+ try {
120
+ for await (const chunk of upstream) {
121
+ yield chunk;
122
+ }
123
+ } catch (err) {
124
+ if (!fellBack && isVoiceCloningError(err) && voiceId && !PREDEFINED_IDS.has(voiceId)) {
125
+ fellBack = true;
126
+ console.log(`[TTS] Voice cloning failed for "${voiceId}", falling back to ${FALLBACK_VOICE}`);
127
+ yield* synthesizeStream(text, FALLBACK_VOICE);
128
+ } else {
129
+ throw err;
130
+ }
131
+ }
132
+ })();
99
133
  }
100
134
 
101
135
  function getVoices() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.222",
3
+ "version": "1.0.223",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "server.js",