fix: surface VOICEVOX errors via toast (401/503/network)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
40efd9b8e3
commit
ef35f18223
10
index.html
10
index.html
|
|
@ -676,7 +676,11 @@ async function tryVoicevox(text) {
|
||||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` },
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` },
|
||||||
body: JSON.stringify({ text: preprocessText(text), speaker: ttsSpeaker }),
|
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());
|
const buf = await ctx.decodeAudioData(await res.arrayBuffer());
|
||||||
if (!isPlaying) return true;
|
if (!isPlaying) return true;
|
||||||
|
|
@ -713,7 +717,9 @@ async function speak(text) {
|
||||||
stopAudio();
|
stopAudio();
|
||||||
|
|
||||||
let vvOk = false;
|
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 (!isPlaying) return;
|
||||||
if (vvOk) {
|
if (vvOk) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue