fix: surface VOICEVOX errors via toast (401/503/network)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
posimai 2026-03-22 16:48:36 +09:00
parent 40efd9b8e3
commit ef35f18223
1 changed files with 8 additions and 2 deletions

View File

@ -676,7 +676,11 @@ async function tryVoicevox(text) {
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` },
body: JSON.stringify({ text: preprocessText(text), speaker: ttsSpeaker }),
});
if (!res.ok) return false;
if (!res.ok) {
const msg = res.status === 401 ? 'APIキーが無効です' : res.status === 503 ? 'VOICEVOXが起動していません' : `サーバーエラー (${res.status})`;
if (currentIdx === 0 && typeof showToast === 'function') showToast('VOICEVOX: ' + msg);
return false;
}
const buf = await ctx.decodeAudioData(await res.arrayBuffer());
if (!isPlaying) return true;
@ -713,7 +717,9 @@ async function speak(text) {
stopAudio();
let vvOk = false;
try { vvOk = (await tryVoicevox(text)) === true; } catch(e) {}
try { vvOk = (await tryVoicevox(text)) === true; } catch(e) {
if (currentIdx === 0 && typeof showToast === 'function') showToast('VOICEVOX エラー: ' + (e.message || e));
}
if (!isPlaying) return;
if (vvOk) {