Registry / ai-ml / snac
library1.2.1pypypi✓ verified 83d ago

Multi-Scale Neural Audio Codec for audio compression, supporting 24 kHz, 32 kHz, and 44 kHz sampling rates. This is a PyTorch-based library for encoding audio into discrete codes (suitable for language modeling) and decoding back to waveform. Current version 1.2.1 has a stable API with `encode` and `decode` methods.

pip install snac
INSTALL
IMPORT
SIG · SNAC
S
snac
ai-mlpythonv1.2.1
Install
69.3s avg
Import
6835ms
Disk
4890MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 81.2s
py 3.11
✕ build_error
✓ 73.7s
py 3.12
✕ build_error
✓ 62.9s
py 3.13
✕ build_error
✓ 59.2s
py 3.9
✕ build_error
✕ timeout
4890MB installed
● package 4890MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SNAC
from snac import SNAC

Load a pretrained model, encode audio to discrete codes, and decode back to audio.

import torch from snac import SNAC model = SNAC.from_pretrained("hubertsiuzdak/snac_24khz") audio = torch.randn(1, 1, 24000) # 1 second of 24 kHz audio codes = model.encode(audio) print("Codes shape:", codes.shape) reconstructed = model.decode(codes) print("Audio shape:", reconstructed.shape)
snac --version
Debug
Known issues
gotchaThe `encode` method returns a list of tensors (one per layer) in version <1.2.0, but returns a single stacked tensor in 1.2.0+. Check your version and adjust code accordingly.
fix
Upgrade to >=1.2.0 or use `codes = model.encode(audio)` and handle list.
affects: <1.2.0
deprecatedLoading models from a local filepath was broken in 1.2.0 and fixed in 1.2.1. If you use `SNAC.from_pretrained('./local_model')`, ensure version >=1.2.1.
fix
Upgrade to 1.2.1 or use a Hugging Face model ID.
affects: 1.2.0
gotchaThe model expects audio resampled to the model's sample rate (24kHz, 32kHz, or 44kHz). Failure to resample will produce garbled output.
fix
Resample input audio to match the model's sample rate before encoding.
affects: all
breakingVersion 1.0.0 introduced a completely new architecture and model zoo. Models from v0.x (if they existed) are incompatible.
fix
Use only v1.x models and upgrade to latest version.
affects: <1.0.0
Errors
Common errors & fixes
ImportError: cannot import name 'SNAC' from 'snac'
SNAC was not installed correctly or an incompatible version is installed.
fix
Ensure you installed the correct package: `pip install snac`. Check that you are not shadowing the package with a local file named snac.py.
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0!
The model is on one device, but the input tensor is on another.
fix
Move the model and input to the same device: `model = model.to('cuda'); audio = audio.to('cuda')`.
OSError: Can't load tokenizer for 'hubertsiuzdak/snac_24khz'
The model name is incorrect or the model is not publicly accessible.
fix
Use a valid Hugging Face model ID (e.g., 'hubertsiuzdak/snac_24khz', 'hubertsiuzdak/snac_32khz', 'hubertsiuzdak/snac_44khz') or ensure your network can access huggingface.co.
Upgrade
Version history
1.2.1latest on PyPI · released Sep 11, 2024
Audit
Dependencies
torchrequiredRequired for tensor operations and model inference.
Agent activity
20 hits · last 30 days
node
17
OpenAI (training)
1
Resources
snac — pip install snac · libregistry