fix(tts): show all provider errors instead of only the last one
When TTS conversion fails, the error message now includes failures from every provider in the fallback chain instead of only the last one tried. Previously, a timeout on the primary provider (e.g. ElevenLabs) would be masked by the final fallback's error (e.g. "edge: disabled"), making it impossible to diagnose the real issue. Before: "TTS conversion failed: edge: disabled" After: "TTS conversion failed: elevenlabs: timeout (30004ms); openai: no API key; edge: disabled"
This commit is contained in:
@@ -551,14 +551,14 @@ export async function textToSpeech(params: {
|
||||
const provider = overrideProvider ?? userProvider;
|
||||
const providers = resolveTtsProviderOrder(provider);
|
||||
|
||||
let lastError: string | undefined;
|
||||
const errors: string[] = [];
|
||||
|
||||
for (const provider of providers) {
|
||||
const providerStart = Date.now();
|
||||
try {
|
||||
if (provider === "edge") {
|
||||
if (!config.edge.enabled) {
|
||||
lastError = "edge: disabled";
|
||||
errors.push("edge: disabled");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ export async function textToSpeech(params: {
|
||||
|
||||
const apiKey = resolveTtsApiKey(config, provider);
|
||||
if (!apiKey) {
|
||||
lastError = `No API key for ${provider}`;
|
||||
errors.push(`${provider}: no API key`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -683,13 +683,13 @@ export async function textToSpeech(params: {
|
||||
voiceCompatible: output.voiceCompatible,
|
||||
};
|
||||
} catch (err) {
|
||||
lastError = formatTtsProviderError(provider, err);
|
||||
errors.push(formatTtsProviderError(provider, err));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: `TTS conversion failed: ${lastError || "no providers available"}`,
|
||||
error: `TTS conversion failed: ${errors.join("; ") || "no providers available"}`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -711,19 +711,19 @@ export async function textToSpeechTelephony(params: {
|
||||
const userProvider = getTtsProvider(config, prefsPath);
|
||||
const providers = resolveTtsProviderOrder(userProvider);
|
||||
|
||||
let lastError: string | undefined;
|
||||
const errors: string[] = [];
|
||||
|
||||
for (const provider of providers) {
|
||||
const providerStart = Date.now();
|
||||
try {
|
||||
if (provider === "edge") {
|
||||
lastError = "edge: unsupported for telephony";
|
||||
errors.push("edge: unsupported for telephony");
|
||||
continue;
|
||||
}
|
||||
|
||||
const apiKey = resolveTtsApiKey(config, provider);
|
||||
if (!apiKey) {
|
||||
lastError = `No API key for ${provider}`;
|
||||
errors.push(`${provider}: no API key`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -772,13 +772,13 @@ export async function textToSpeechTelephony(params: {
|
||||
sampleRate: output.sampleRate,
|
||||
};
|
||||
} catch (err) {
|
||||
lastError = formatTtsProviderError(provider, err);
|
||||
errors.push(formatTtsProviderError(provider, err));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: `TTS conversion failed: ${lastError || "no providers available"}`,
|
||||
error: `TTS conversion failed: ${errors.join("; ") || "no providers available"}`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user