Views
No views yet
hubertsiuzdak/snac_24khz. The code
space is therefore identical to the base model, so this checkpoint is a drop-in decoder
replacement: any SNAC code24khz` decode here with no retraining and no re-tokenizing.| Base | `hubertsiuzdak/snac |
| Output | 24 kHz, mono |
| Codebooks | 3 hierarchical levels, 4096 entries each |
| Frame layout | 7 tokens / ine) |
| Parameters | ~19.8 M |
| Fine-tuned | decoder only |
pip install snac torch sound1import torch, soundfile as s
2from snac import SNAC
3
4device = "cuda" if torch.cud
5model = SNAC.from_pretrained("nullHawk/snac-24khz-hindi-hp").eval().to(device)
6
7wav, sr = sf.read("input.wavt be 24 kHz (resample first if
8not)
9audio = torch.from_numpy(wavce) # shape [1, 1, T]
10
11with torch.inference_mode():
12 codes = model.encode(aud LongTensors (coarse -> fine)
13 recon = model.decode(codes) # [1, 1, T'] waveform
14
15sf.write("recon.wav", recon[1import torch
2
3def decode_snac_tokens(ids,
4 """ids : flat list of
5 offset: subtract your LLM's SNAC base id (use 0 if ids are already in [0, 4096)).
6"""
7 ids = [(t - offset) % 40
8 frames = len(ids) // 7
9 l1, l2, l3 = [], [], []
10 for i in range(frames):
11 s = ids[i * 7:(i + 1) * 7]
12 l1.append(s[0])
13 l2 += [s[1], s[4]]
14 l3 += [s[2], s[3], s
15 dev = next(model.parameters()).device
16 codes = [torch.tensor(x,)[None] for x in (l1, l2, l3)]
17 with torch.inference_mode():
18 z_q = model.quantize
19 audio = model.decoder(z_q)[0, 0].cpu().numpy()
20 return audio[2048:] ms decoder warm-up1# offset = the SNAC base tokg. 128266 for maya1 / Orpheus).
2wav = decode_snac_tokens(token_ids, model, offset=128266)
3import soundfile as sf
4sf.write("tts.wav", wav, 24000)