agentgui 1.0.223 → 1.0.224
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/lib/speech.js +5 -39
- package/package.json +1 -1
package/lib/speech.js
CHANGED
|
@@ -27,12 +27,6 @@ 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
|
-
}
|
|
36
30
|
const POCKET_PORT = 8787;
|
|
37
31
|
|
|
38
32
|
const needsPatch = !serverTTS.getVoices(EXTRA_VOICE_DIRS).some(v => v.id === 'alba' && !v.isCustom);
|
|
@@ -85,19 +79,11 @@ function getSTT() {
|
|
|
85
79
|
return serverSTT.getSTT();
|
|
86
80
|
}
|
|
87
81
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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;
|
|
82
|
+
function synthesize(text, voiceId) {
|
|
83
|
+
if (needsPatch && voiceId && PREDEFINED_IDS.has(voiceId)) {
|
|
84
|
+
return synthesizeDirect(text, voiceId);
|
|
100
85
|
}
|
|
86
|
+
return serverTTS.synthesize(text, voiceId, EXTRA_VOICE_DIRS);
|
|
101
87
|
}
|
|
102
88
|
|
|
103
89
|
function synthesizeStream(text, voiceId) {
|
|
@@ -109,27 +95,7 @@ function synthesizeStream(text, voiceId) {
|
|
|
109
95
|
}
|
|
110
96
|
})();
|
|
111
97
|
}
|
|
112
|
-
return
|
|
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
|
-
})();
|
|
98
|
+
return serverTTS.synthesizeStream(text, voiceId, EXTRA_VOICE_DIRS);
|
|
133
99
|
}
|
|
134
100
|
|
|
135
101
|
function getVoices() {
|