Update app.py
Browse files
app.py
CHANGED
|
@@ -78,25 +78,34 @@ def clone_and_speak(text):
|
|
| 78 |
unique_filename = f"voice_output_{uuid.uuid4().hex[:8]}.wav"
|
| 79 |
print(f"🔊 Rendering voice cloning track for text: '{text}'")
|
| 80 |
|
| 81 |
-
#
|
| 82 |
-
|
| 83 |
ref_file=voice_file,
|
| 84 |
ref_text=auto_reference_text,
|
| 85 |
-
gen_text=text
|
| 86 |
-
n_timesteps=10, # Drastically speeds up synthesis step count
|
| 87 |
-
speed=1.1 # Compresses wave calculations slightly for speed
|
| 88 |
)
|
| 89 |
|
| 90 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
if hasattr(audio_data, "cpu"):
|
| 92 |
audio_data = audio_data.cpu().numpy()
|
| 93 |
elif hasattr(audio_data, "numpy"):
|
| 94 |
audio_data = audio_data.numpy()
|
| 95 |
|
| 96 |
-
#
|
| 97 |
audio_data = np.squeeze(audio_data)
|
| 98 |
|
| 99 |
-
# Write
|
| 100 |
sf.write(unique_filename, audio_data, sample_rate, format='WAV')
|
| 101 |
|
| 102 |
if os.path.exists(unique_filename) and os.path.getsize(unique_filename) > 0:
|
|
|
|
| 78 |
unique_filename = f"voice_output_{uuid.uuid4().hex[:8]}.wav"
|
| 79 |
print(f"🔊 Rendering voice cloning track for text: '{text}'")
|
| 80 |
|
| 81 |
+
# Invoke inference engine
|
| 82 |
+
result = f5tts.infer(
|
| 83 |
ref_file=voice_file,
|
| 84 |
ref_text=auto_reference_text,
|
| 85 |
+
gen_text=text
|
|
|
|
|
|
|
| 86 |
)
|
| 87 |
|
| 88 |
+
# CRITICAL FIX: Dynamically detect and unpack tuple structures regardless of package version variations
|
| 89 |
+
if isinstance(result, tuple):
|
| 90 |
+
if len(result) == 2:
|
| 91 |
+
audio_data, sample_rate = result
|
| 92 |
+
elif len(result) >= 3:
|
| 93 |
+
audio_data, sample_rate = result[0], result[1]
|
| 94 |
+
else:
|
| 95 |
+
audio_data, sample_rate = result[0], 24000
|
| 96 |
+
else:
|
| 97 |
+
audio_data, sample_rate = result, 24000
|
| 98 |
+
|
| 99 |
+
# Convert Torch tensors safely to standard numpy array structures
|
| 100 |
if hasattr(audio_data, "cpu"):
|
| 101 |
audio_data = audio_data.cpu().numpy()
|
| 102 |
elif hasattr(audio_data, "numpy"):
|
| 103 |
audio_data = audio_data.numpy()
|
| 104 |
|
| 105 |
+
# Flatten structural multi-dimensional arrays safely for soundfile
|
| 106 |
audio_data = np.squeeze(audio_data)
|
| 107 |
|
| 108 |
+
# Write clean output wave file natively
|
| 109 |
sf.write(unique_filename, audio_data, sample_rate, format='WAV')
|
| 110 |
|
| 111 |
if os.path.exists(unique_filename) and os.path.getsize(unique_filename) > 0:
|