Update index.html
Browse files- index.html +15 -15
index.html
CHANGED
@@ -76,12 +76,13 @@
|
|
76 |
<script>
|
77 |
document.addEventListener('DOMContentLoaded', () => {
|
78 |
const HF_SPACE_URL = "https://hamed744-ttspro.hf.space";
|
79 |
-
// *** مسیرهای صحیح
|
80 |
-
const
|
81 |
-
const GET_DATA_URL_BASE = `${HF_SPACE_URL}/queue/data`;
|
82 |
-
const FILE_URL_BASE = `${HF_SPACE_URL}/file=`;
|
83 |
|
84 |
-
|
|
|
85 |
|
86 |
const speakers = ["Achird", "Zubenelgenubi", "Vindemiatrix", "Sadachbia", "Sadaltager", "Sulafat", "Laomedeia", "Achernar", "Alnilam", "Schedar", "Gacrux", "Pulcherrima", "Umbriel", "Algieba", "Despina", "Erinome", "Algenib", "Rasalthgeti", "Orus", "Aoede", "Callirrhoe", "Autonoe", "Enceladus", "Iapetus", "Zephyr", "Puck", "Charon", "Kore", "Fenrir", "Leda"];
|
87 |
|
@@ -138,22 +139,22 @@
|
|
138 |
};
|
139 |
|
140 |
try {
|
141 |
-
// 1.
|
142 |
-
const
|
143 |
method: "POST",
|
144 |
headers: { "Content-Type": "application/json" },
|
145 |
body: JSON.stringify(payload)
|
146 |
});
|
147 |
|
148 |
-
if (!
|
149 |
-
|
150 |
-
|
151 |
}
|
152 |
|
153 |
-
console.log("
|
154 |
statusMessage.textContent = 'در انتظار نتیجه از سرور...';
|
155 |
|
156 |
-
// 2. گوش دادن
|
157 |
const dataResponse = await fetch(`${GET_DATA_URL_BASE}?session_hash=${sessionHash}`);
|
158 |
const reader = dataResponse.body.getReader();
|
159 |
const decoder = new TextDecoder();
|
@@ -166,7 +167,7 @@
|
|
166 |
|
167 |
buffer += decoder.decode(value, { stream: true });
|
168 |
const lines = buffer.split('\n');
|
169 |
-
buffer = lines.pop();
|
170 |
|
171 |
for (const line of lines) {
|
172 |
if (!line.startsWith('data:')) continue;
|
@@ -180,7 +181,6 @@
|
|
180 |
}
|
181 |
if (data.msg === 'process_completed') {
|
182 |
if (data.success && data.output.data && data.output.data[0] && (data.output.data[0].name || data.output.data[0].path)) {
|
183 |
-
// پشتیبانی از هر دو کلید name و path برای اطمینان
|
184 |
finalFilePath = data.output.data[0].name || data.output.data[0].path;
|
185 |
} else {
|
186 |
console.error("ساختار پیام موفقیت مورد انتظار نبود:", data);
|
@@ -202,7 +202,7 @@
|
|
202 |
audioPlayer.style.display = 'block';
|
203 |
audioPlayer.play();
|
204 |
} else {
|
205 |
-
throw new Error('فایل صوتی از سرور دریافت نشد.
|
206 |
}
|
207 |
|
208 |
} catch (error) {
|
|
|
76 |
<script>
|
77 |
document.addEventListener('DOMContentLoaded', () => {
|
78 |
const HF_SPACE_URL = "https://hamed744-ttspro.hf.space";
|
79 |
+
// *** مسیرهای صحیح با پیشوند /gradio_api/ بر اساس لاگها ***
|
80 |
+
const JOIN_QUEUE_URL = `${HF_SPACE_URL}/gradio_api/queue/join`;
|
81 |
+
const GET_DATA_URL_BASE = `${HF_SPACE_URL}/gradio_api/queue/data`;
|
82 |
+
const FILE_URL_BASE = `${HF_SPACE_URL}/gradio_api/file=`;
|
83 |
|
84 |
+
// fn_index ها معمولا از 0 شروع میشن، اما با توجه به لاگ های شما، از 1 استفاده می کنیم
|
85 |
+
const FN_INDEX = 1;
|
86 |
|
87 |
const speakers = ["Achird", "Zubenelgenubi", "Vindemiatrix", "Sadachbia", "Sadaltager", "Sulafat", "Laomedeia", "Achernar", "Alnilam", "Schedar", "Gacrux", "Pulcherrima", "Umbriel", "Algieba", "Despina", "Erinome", "Algenib", "Rasalthgeti", "Orus", "Aoede", "Callirrhoe", "Autonoe", "Enceladus", "Iapetus", "Zephyr", "Puck", "Charon", "Kore", "Fenrir", "Leda"];
|
88 |
|
|
|
139 |
};
|
140 |
|
141 |
try {
|
142 |
+
// 1. اتصال به صف
|
143 |
+
const joinQueueResponse = await fetch(JOIN_QUEUE_URL, {
|
144 |
method: "POST",
|
145 |
headers: { "Content-Type": "application/json" },
|
146 |
body: JSON.stringify(payload)
|
147 |
});
|
148 |
|
149 |
+
if (!joinQueueResponse.ok) {
|
150 |
+
const errorBody = await joinQueueResponse.text();
|
151 |
+
throw new Error(`خطا در اتصال به صف (${joinQueueResponse.status}): ${errorBody}`);
|
152 |
}
|
153 |
|
154 |
+
console.log("با موفقیت به صف متصل شد. در انتظار داده...");
|
155 |
statusMessage.textContent = 'در انتظار نتیجه از سرور...';
|
156 |
|
157 |
+
// 2. گوش دادن برای دریافت نتیجه
|
158 |
const dataResponse = await fetch(`${GET_DATA_URL_BASE}?session_hash=${sessionHash}`);
|
159 |
const reader = dataResponse.body.getReader();
|
160 |
const decoder = new TextDecoder();
|
|
|
167 |
|
168 |
buffer += decoder.decode(value, { stream: true });
|
169 |
const lines = buffer.split('\n');
|
170 |
+
buffer = lines.pop();
|
171 |
|
172 |
for (const line of lines) {
|
173 |
if (!line.startsWith('data:')) continue;
|
|
|
181 |
}
|
182 |
if (data.msg === 'process_completed') {
|
183 |
if (data.success && data.output.data && data.output.data[0] && (data.output.data[0].name || data.output.data[0].path)) {
|
|
|
184 |
finalFilePath = data.output.data[0].name || data.output.data[0].path;
|
185 |
} else {
|
186 |
console.error("ساختار پیام موفقیت مورد انتظار نبود:", data);
|
|
|
202 |
audioPlayer.style.display = 'block';
|
203 |
audioPlayer.play();
|
204 |
} else {
|
205 |
+
throw new Error('فایل صوتی از سرور دریافت نشد. کنسول را برای اطلاعات بیشتر بررسی کنید.');
|
206 |
}
|
207 |
|
208 |
} catch (error) {
|