Opera10 commited on
Commit
05f5717
·
verified ·
1 Parent(s): 783fcae

Update services/api.ts

Browse files
Files changed (1) hide show
  1. services/api.ts +4 -24
services/api.ts CHANGED
@@ -147,32 +147,12 @@ const generateBaseTTS = async (text: string, speakerId: string = "Algieba"): Pro
147
  const response = await fetch(`${TTS_BASE_URL}/api/generate`, {
148
  method: 'POST',
149
  headers: { 'Content-Type': 'application/json' },
150
- body: JSON.stringify({ text, speaker: speakerId, temperature: 0.9, subscriptionStatus: 'paid', fingerprint: 'admin_bypass' })
151
  });
152
  if (!response.ok) throw new Error(`TTS Generation failed`);
153
- const data = await response.json();
154
- const jobId = data.job_id;
155
-
156
- return new Promise((resolve, reject) => {
157
- const pollInterval = setInterval(async () => {
158
- try {
159
- const statusRes = await fetch(`${TTS_BASE_URL}/api/check_status`, {
160
- method: 'POST',
161
- headers: { 'Content-Type': 'application/json' },
162
- body: JSON.stringify({ job_id: jobId })
163
- });
164
- const statusData = await statusRes.json();
165
- if (statusData.status === 'completed' && statusData.proxy_url) {
166
- clearInterval(pollInterval);
167
- const audioRes = await fetch(`${TTS_BASE_URL}${statusData.proxy_url}`);
168
- resolve(await audioRes.blob());
169
- } else if (statusData.status === 'failed') {
170
- clearInterval(pollInterval);
171
- reject(new Error("TTS failed"));
172
- }
173
- } catch (e) { clearInterval(pollInterval); reject(e); }
174
- }, 3000);
175
- });
176
  };
177
 
178
  export const fetchRefAudioAsFile = async (url: string, filename: string): Promise<File> => {
 
147
  const response = await fetch(`${TTS_BASE_URL}/api/generate`, {
148
  method: 'POST',
149
  headers: { 'Content-Type': 'application/json' },
150
+ body: JSON.stringify({ text, speaker: speakerId, temperature: 0.9 })
151
  });
152
  if (!response.ok) throw new Error(`TTS Generation failed`);
153
+
154
+ // دریافت مستقیم فایل صوتی به صورت باینری (Blob) بدون نیاز به انتظار در صف و بررسی مداوم وضعیت کار
155
+ return await response.blob();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  };
157
 
158
  export const fetchRefAudioAsFile = async (url: string, filename: string): Promise<File> => {