Revert TTS generation to backend with fixed local proxy 127.0.0.1:7890

This commit is contained in:
2026-08-01 18:25:50 +08:00
parent c76538e4bd
commit 2741b2d321
3 changed files with 26 additions and 66 deletions
+9 -29
View File
@@ -858,44 +858,24 @@
async function _generateSingleTTS(text, reference_id) {
try {
// Fetch directly from frontend to use the local browser's network
const fishRes = await fetch('https://api.fish.audio/v1/tts', {
const res = await fetch('/api/tts/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer 233f3a9bcc204b20a1979d59d33cc649',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: text,
reference_id: reference_id,
model: TTS_MODEL,
format: "wav"
})
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text, reference_id, model: TTS_MODEL })
});
if (!fishRes.ok) {
let msg = 'Fish Audio API Error';
try { msg = await fishRes.text(); } catch(e){}
throw new Error(`[${fishRes.status}] ${msg}`);
if (!res.ok) {
let msg = '服务器返回错误';
try { const errData = await res.json(); msg = errData.message || msg; } catch(e){}
throw new Error(`[${res.status}] ${msg}`);
}
const audioBlob = await fishRes.blob();
// Upload the blob to the server as a temporary file
const formData = new FormData();
formData.append('audio', audioBlob, 'temp.wav');
const uploadRes = await fetch('/api/tts/upload_temp', {
method: 'POST',
body: formData
});
const data = await uploadRes.json();
const data = await res.json();
if (!data.success) throw new Error(data.message);
return data;
} catch (err) {
if (err.name === 'TypeError' && err.message === 'Failed to fetch') {
throw new Error('网络跨域拦截(CORS)或连接失败。请确保你的浏览器已安装并开启 CORS Unblock 插件!');
throw new Error('网络连接失败。请确保你的服务器代理正常!');
}
throw err;
}