From 2741b2d321fe8cf92603d5fd4965d900ad436f40 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 1 Aug 2026 18:25:50 +0800 Subject: [PATCH] Revert TTS generation to backend with fixed local proxy 127.0.0.1:7890 --- CloudServer/public/generator.html | 38 +++++++-------------------- CloudServer/public/tempbroadcast.html | 38 +++++++-------------------- CloudServer/server.js | 16 +++++------ 3 files changed, 26 insertions(+), 66 deletions(-) diff --git a/CloudServer/public/generator.html b/CloudServer/public/generator.html index e8a7359..118464f 100644 --- a/CloudServer/public/generator.html +++ b/CloudServer/public/generator.html @@ -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; } diff --git a/CloudServer/public/tempbroadcast.html b/CloudServer/public/tempbroadcast.html index 74eddc7..2adfbe3 100644 --- a/CloudServer/public/tempbroadcast.html +++ b/CloudServer/public/tempbroadcast.html @@ -324,44 +324,24 @@ async function _generateTTSLocal(text, reference_id) { try { - // Client-side fetch to use 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; } diff --git a/CloudServer/server.js b/CloudServer/server.js index b68cfb6..c7cada8 100644 --- a/CloudServer/server.js +++ b/CloudServer/server.js @@ -2423,7 +2423,7 @@ function requestDirect(urlStr, options) { async function generateTtsWavToTemp(text, reference_id, model = DEFAULT_TTS_MODEL) { let proxyUrl = process.env.HTTP_PROXY || process.env.http_proxy || process.env.HTTPS_PROXY || process.env.https_proxy || process.env.ALL_PROXY || process.env.all_proxy; - if (!proxyUrl && os.platform() === 'win32') { + if (!proxyUrl) { proxyUrl = 'http://127.0.0.1:7890'; } @@ -2512,21 +2512,21 @@ app.post('/api/tts/generate', express.json(), async (req, res) => { body: requestBody }; - // Always try to use local proxy first if we are on a Windows machine - if (!proxyUrl && os.platform() === 'win32') { + // Always try to use proxy + if (!proxyUrl) { proxyUrl = 'http://127.0.0.1:7890'; } let response; try { response = proxyUrl - ? await requestViaProxy('https://fishaudio.fse-media.group/v1/tts', options, proxyUrl) - : await requestDirect('https://fishaudio.fse-media.group/v1/tts', options); + ? await requestViaProxy('https://api.fish.audio/v1/tts', options, proxyUrl) + : await requestDirect('https://api.fish.audio/v1/tts', options); } catch (e) { - // Fallback for Windows if local proxy fails - if (os.platform() === 'win32' && proxyUrl === 'http://127.0.0.1:7890') { + // Fallback if proxy fails + if (proxyUrl === 'http://127.0.0.1:7890') { console.log(`[TTS] Local proxy failed, attempting direct connection...`); - response = await requestDirect('https://fishaudio.fse-media.group/v1/tts', options); + response = await requestDirect('https://api.fish.audio/v1/tts', options); } else { throw e; }