Spaces:
Runtime error
Runtime error
Upload gen_samples.py with huggingface_hub
Browse files- gen_samples.py +10 -5
gen_samples.py
CHANGED
|
@@ -32,11 +32,16 @@ def load_ref_audio(ref_path):
|
|
| 32 |
return wav
|
| 33 |
|
| 34 |
def encode_ref(codec, wav):
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def generate_clone(model, codec, ref_tokens, ref_text, gen_text, out_path):
|
| 42 |
"""Generate voice clone using the Conversation API correctly."""
|
|
|
|
| 32 |
return wav
|
| 33 |
|
| 34 |
def encode_ref(codec, wav):
|
| 35 |
+
"""Encode reference audio outside inference mode."""
|
| 36 |
+
import torch
|
| 37 |
+
# Exit inference mode temporarily for codec (it needs autograd for some ops)
|
| 38 |
+
wav_clone = wav.clone().detach().to(DEVICE).requires_grad_(False)
|
| 39 |
+
# Use torch.no_grad context instead of inference_mode
|
| 40 |
+
with torch.no_grad():
|
| 41 |
+
with torch.amp.autocast(device_type="cuda", dtype=DTYPE):
|
| 42 |
+
enc = codec.encode(wav_clone.unsqueeze(0))
|
| 43 |
+
tokens = enc[0] if isinstance(enc, tuple) else enc
|
| 44 |
+
return tokens.detach().cpu().numpy()
|
| 45 |
|
| 46 |
def generate_clone(model, codec, ref_tokens, ref_text, gen_text, out_path):
|
| 47 |
"""Generate voice clone using the Conversation API correctly."""
|