Generate default voice from silence on startup; fix voice fallback priority
Browse files- scripts/omni_o_call.py +27 -2
scripts/omni_o_call.py
CHANGED
|
@@ -160,8 +160,13 @@ def register_voice(name, value, group='manual'):
|
|
| 160 |
|
| 161 |
def voice_args(name):
|
| 162 |
if not name or name == 'default':
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
return {}
|
| 166 |
if name in V:
|
| 167 |
v = V[name]
|
|
@@ -501,6 +506,26 @@ def init_model(args):
|
|
| 501 |
if speaker not in V or fn == CLONE_FILE:
|
| 502 |
register_voice(speaker, v, group=group)
|
| 503 |
if V: print(f'Loaded {len(V)} voices')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
|
| 505 |
print('Warmup...')
|
| 506 |
with torch.no_grad():
|
|
|
|
| 160 |
|
| 161 |
def voice_args(name):
|
| 162 |
if not name or name == 'default':
|
| 163 |
+
if 'default' in V:
|
| 164 |
+
name = 'default'
|
| 165 |
+
elif VOICES_BUILTIN:
|
| 166 |
+
name = VOICES_BUILTIN[0]
|
| 167 |
+
elif V:
|
| 168 |
+
name = list(V.keys())[0]
|
| 169 |
+
else:
|
| 170 |
return {}
|
| 171 |
if name in V:
|
| 172 |
v = V[name]
|
|
|
|
| 506 |
if speaker not in V or fn == CLONE_FILE:
|
| 507 |
register_voice(speaker, v, group=group)
|
| 508 |
if V: print(f'Loaded {len(V)} voices')
|
| 509 |
+
if not V and M.get('campplus') and M.get('mimi'):
|
| 510 |
+
try:
|
| 511 |
+
silence_24k = np.zeros(24000, dtype=np.float32)
|
| 512 |
+
w24 = torch.tensor(silence_24k)
|
| 513 |
+
w16 = torch.tensor(np.zeros(16000, dtype=np.float32))
|
| 514 |
+
mimi_dev = next(M['mimi'].parameters()).device
|
| 515 |
+
mimi_dtype = torch.float16 if mimi_dev.type != 'cpu' else torch.float32
|
| 516 |
+
with torch.inference_mode():
|
| 517 |
+
t = w24.unsqueeze(0).unsqueeze(0).to(device=mimi_dev, dtype=mimi_dtype)
|
| 518 |
+
codes = M['mimi'].encode(t).audio_codes
|
| 519 |
+
ref_codes = codes[0, :8, :1].cpu()
|
| 520 |
+
with torch.no_grad():
|
| 521 |
+
mel = M['mel_fn'](w16.unsqueeze(0).to(M['device']))
|
| 522 |
+
feat = mel.clamp(min=1e-10).log().transpose(1, 2)
|
| 523 |
+
feat = feat - feat.mean(dim=1, keepdim=True)
|
| 524 |
+
spk_emb = M['campplus'](feat).squeeze(0).cpu()
|
| 525 |
+
register_voice('default', {'ref_codes': ref_codes, 'spk_emb': spk_emb}, group='builtin')
|
| 526 |
+
print('Generated default voice from silence')
|
| 527 |
+
except Exception as e:
|
| 528 |
+
print(f'Default voice generation failed: {e}')
|
| 529 |
|
| 530 |
print('Warmup...')
|
| 531 |
with torch.no_grad():
|