Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -233,92 +233,111 @@ def clone_voice_api(text_to_speak, reference_audio_url, exaggeration=0.6, cfg_pa
|
|
233 |
|
234 |
temp_audio_path = None
|
235 |
try:
|
236 |
-
print(f"API
|
237 |
-
print(f"
|
238 |
-
print(f"
|
239 |
-
print(f"
|
240 |
-
print(f"
|
241 |
-
|
242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
print("Processing base64 audio data...")
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
print("Processing HTTP audio URL...")
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
|
|
278 |
else:
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
raise ValueError(f"Failed to obtain a valid audio file path from input: {reference_audio_url}")
|
289 |
-
|
290 |
-
print(f"Calling core clone_voice function with audio path: {temp_audio_path}")
|
291 |
audio_output, status = clone_voice(text_to_speak, temp_audio_path, exaggeration, cfg_pace, random_seed, temperature)
|
292 |
-
|
|
|
|
|
|
|
293 |
|
294 |
-
#
|
295 |
-
if temp_audio_path and
|
296 |
-
(reference_audio_url.startswith('data:audio') or reference_audio_url.startswith('http')):
|
297 |
try:
|
298 |
os.unlink(temp_audio_path)
|
299 |
print(f"Cleaned up temporary file: {temp_audio_path}")
|
300 |
-
except Exception as
|
301 |
-
print(f"
|
302 |
-
|
303 |
return audio_output, status
|
304 |
-
|
305 |
except Exception as e:
|
306 |
-
print(f"
|
307 |
-
|
|
|
|
|
308 |
traceback.print_exc()
|
309 |
-
|
310 |
-
#
|
311 |
-
if temp_audio_path and
|
312 |
-
(reference_audio_url.startswith('data:audio') or reference_audio_url.startswith('http')):
|
313 |
try:
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
print(f"Failed to clean up temp file {temp_audio_path} after error: {e_clean}")
|
319 |
return None, f"API Error: {str(e)}"
|
320 |
|
321 |
-
|
322 |
def main():
|
323 |
print("Starting Advanced Gradio interface...")
|
324 |
|
|
|
233 |
|
234 |
temp_audio_path = None
|
235 |
try:
|
236 |
+
print(f"=== API CALL DEBUG ===")
|
237 |
+
print(f"Text: {text_to_speak}")
|
238 |
+
print(f"Audio URL type: {type(reference_audio_url)}")
|
239 |
+
print(f"Audio URL length: {len(str(reference_audio_url)) if reference_audio_url else 0}")
|
240 |
+
print(f"Audio URL preview: {str(reference_audio_url)[:100]}...")
|
241 |
+
print(f"Parameters: exag={exaggeration}, cfg={cfg_pace}, seed={random_seed}, temp={temperature}")
|
242 |
+
|
243 |
+
# Validate inputs
|
244 |
+
if not text_to_speak or text_to_speak.strip() == "":
|
245 |
+
return None, "Error: Please enter some text to speak."
|
246 |
+
|
247 |
+
if not reference_audio_url:
|
248 |
+
return None, "Error: Please provide reference audio."
|
249 |
+
|
250 |
+
print("Processing audio data...")
|
251 |
+
|
252 |
+
if reference_audio_url.startswith('data:audio'):
|
253 |
print("Processing base64 audio data...")
|
254 |
+
try:
|
255 |
+
header, encoded = reference_audio_url.split(',', 1)
|
256 |
+
print(f"Header: {header}")
|
257 |
+
print(f"Encoded data length: {len(encoded)}")
|
258 |
+
|
259 |
+
audio_data = base64.b64decode(encoded)
|
260 |
+
print(f"Decoded audio data size: {len(audio_data)} bytes")
|
261 |
+
|
262 |
+
if 'mp3' in header:
|
263 |
+
ext = '.mp3'
|
264 |
+
elif 'wav' in header:
|
265 |
+
ext = '.wav'
|
266 |
+
else:
|
267 |
+
ext = '.wav'
|
268 |
+
|
269 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as temp_file:
|
270 |
+
temp_file.write(audio_data)
|
271 |
+
temp_audio_path = temp_file.name
|
272 |
+
|
273 |
+
print(f"Created temporary audio file: {temp_audio_path}")
|
274 |
+
print(f"File exists: {os.path.exists(temp_audio_path)}")
|
275 |
+
print(f"File size: {os.path.getsize(temp_audio_path)} bytes")
|
276 |
+
|
277 |
+
except Exception as audio_error:
|
278 |
+
print(f"Audio processing error: {audio_error}")
|
279 |
+
return None, f"Error processing audio data: {str(audio_error)}"
|
280 |
+
|
281 |
+
elif reference_audio_url.startswith('http'):
|
282 |
print("Processing HTTP audio URL...")
|
283 |
+
try:
|
284 |
+
response = requests.get(reference_audio_url)
|
285 |
+
response.raise_for_status()
|
286 |
+
if reference_audio_url.endswith('.mp3'):
|
287 |
+
ext = '.mp3'
|
288 |
+
elif reference_audio_url.endswith('.wav'):
|
289 |
+
ext = '.wav'
|
290 |
+
else:
|
291 |
+
ext = '.wav'
|
292 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as temp_file:
|
293 |
+
temp_file.write(response.content)
|
294 |
+
temp_audio_path = temp_file.name
|
295 |
+
print(f"Downloaded audio to: {temp_audio_path}")
|
296 |
+
except Exception as download_error:
|
297 |
+
print(f"Download error: {download_error}")
|
298 |
+
return None, f"Error downloading audio: {str(download_error)}"
|
299 |
else:
|
300 |
+
print("Using direct file path...")
|
301 |
+
temp_audio_path = reference_audio_url
|
302 |
+
|
303 |
+
print(f"Calling clone_voice with:")
|
304 |
+
print(f" Text: {text_to_speak}")
|
305 |
+
print(f" Audio path: {temp_audio_path}")
|
306 |
+
print(f" Parameters: {exaggeration}, {cfg_pace}, {random_seed}, {temperature}")
|
307 |
+
|
308 |
+
# Call the main function
|
|
|
|
|
|
|
309 |
audio_output, status = clone_voice(text_to_speak, temp_audio_path, exaggeration, cfg_pace, random_seed, temperature)
|
310 |
+
|
311 |
+
print(f"clone_voice returned:")
|
312 |
+
print(f" Audio output type: {type(audio_output)}")
|
313 |
+
print(f" Status: {status}")
|
314 |
|
315 |
+
# Cleanup
|
316 |
+
if temp_audio_path and temp_audio_path != reference_audio_url:
|
|
|
317 |
try:
|
318 |
os.unlink(temp_audio_path)
|
319 |
print(f"Cleaned up temporary file: {temp_audio_path}")
|
320 |
+
except Exception as cleanup_error:
|
321 |
+
print(f"Cleanup error: {cleanup_error}")
|
322 |
+
|
323 |
return audio_output, status
|
324 |
+
|
325 |
except Exception as e:
|
326 |
+
print(f"=== CRITICAL ERROR ===")
|
327 |
+
print(f"Error type: {type(e)}")
|
328 |
+
print(f"Error message: {str(e)}")
|
329 |
+
import traceback
|
330 |
traceback.print_exc()
|
331 |
+
|
332 |
+
# Cleanup on error
|
333 |
+
if temp_audio_path and temp_audio_path != reference_audio_url:
|
|
|
334 |
try:
|
335 |
+
os.unlink(temp_audio_path)
|
336 |
+
except:
|
337 |
+
pass
|
338 |
+
|
|
|
339 |
return None, f"API Error: {str(e)}"
|
340 |
|
|
|
341 |
def main():
|
342 |
print("Starting Advanced Gradio interface...")
|
343 |
|