Revert "feat: switch to client-side fetch for Fish Audio API to bypass server network restrictions"

This reverts commit dedb37e22b.
This commit is contained in:
2026-08-01 17:49:57 +08:00
parent dedb37e22b
commit 038662c15e
3 changed files with 52 additions and 127 deletions
+5 -53
View File
@@ -322,51 +322,6 @@
.replaceAll("'", "'");
}
async function _generateTTSLocal(text, reference_id) {
try {
// Client-side fetch to use local browser's proxy
const fishRes = await fetch('https://api.fish.audio/v1/tts', {
method: 'POST',
headers: {
'Authorization': 'Bearer 233f3a9bcc204b20a1979d59d33cc649',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: text,
reference_id: reference_id,
model: TTS_MODEL,
format: "wav"
})
});
if (!fishRes.ok) {
let msg = 'Fish Audio API Error';
try { msg = await fishRes.text(); } catch(e){}
throw new Error(`[${fishRes.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();
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 err;
}
}
async function composeTempBroadcast() {
const text = document.getElementById("tb_text").value.trim();
if (!text) {
@@ -376,18 +331,15 @@
document.getElementById("btn_publish").disabled = true;
document.getElementById("btn_compose").disabled = true;
document.getElementById("build_badge").textContent = "合成中…";
setStatus("合成临时广播中(1/2: 生成语音)…");
setStatus("合成临时广播中…");
try {
// 1. 本地生成 TTS 并上传获得临时文件名
const ttsData = await _generateTTSLocal(text, ZH_REFERENCE_ID);
setStatus("合成临时广播中(2/2: 服务端混音)…");
// 2. 告诉服务端进行混音合并
const resp = await fetch("/api/temp-broadcast/build", {
const resp = await fetch("/api/temp-broadcast/compose", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
contentTempName: ttsData.tempName,
text,
reference_id: ZH_REFERENCE_ID,
model: TTS_MODEL,
prefixName: "lsts"
})
});