SQCodec
This repository contains the implementation of SQCodec, a lightweight audio codec based on a single quantizer, introduced in the paper titled "One Quantizer is Enough: Toward a Lightweight Audio Codec".
Source du modèle
- Type
- Other
- Taille du fichier
- 15,2 KB–18,4 MB
- Version
- vRevision e80e263
- Mis à jour
- 22 sept. 2026
- Téléchargements
- 0
- Source
- Hugging Face
Description de la source
SQCodec
This repository contains the implementation of SQCodec, a lightweight audio codec based on a single quantizer, introduced in the paper titled "One Quantizer is Enough: Toward a Lightweight Audio Codec".
install
pip install sq_codec
demo
Firstly, make sure you have installed the librosa package to load the example audio file. You can install it using pip:
pip install librosa
Then, you can use the following code to load a sample audio file, encode it using the SQCodec model, and decode it back to audio. The code also calculates the mean squared error (MSE) between the original and generated audio.
import librosa
import torch
import sq_codec
all_models = sq_codec.list_models()
print(f"Available models: {all_models}")
MODEL_USED = '6kbps'
codec = sq_codec.get_model(MODEL_USED)
print(f"loaded codec({MODEL_USED}) and codec sample rate: {codec.config.sample_rate}")
sample_audio, sample_rate = librosa.load(librosa.example("libri1"))
sample_audio = sample_audio[None, :]
print(f"loaded sample audio and audio sample_rate :{sample_rate}")
sample_audio = librosa.resample(sample_audio, orig_sr=sample_rate, target_sr=codec.config.sample_rate)
codec.network.cuda()
codec.network.eval()
with torch.inference_mode():
audio_in = torch.tensor(sample_audio, dtype=torch.float32, device='cuda')
_, audio_length = audio_in.shape
print(f"{audio_in.shape=}")
q_feature, indices = codec.encode_audio(audio_in)
audio_out = codec.decode_audio(q_feature) # or
# audio_out = codec.decode_audio(indices=indices)
generated_audio = audio_out[:, :audio_length].detach().cpu().numpy()
mse = ((sample_audio - generated_audio) ** 2).mean().item()
print(f"codec({MODEL_USED}) mse: {mse}")
available models
| config_name | Sample rate(Hz) | tokens/s | Codebook size | Bitrate(bps) |
|---|---|---|---|---|
| 0k75bps | 16,000 | 44.44 | 117,649 | 748.6 |
| 1k5bps | 16,000 | 88.89 | 117,649 | 1497.3 |
| 3kbps | 16,000 | 177.78 | 117,649 | 2994.5 |
| 6kbps | 16,000 | 355.56 | 117,649 | 5989.0 |
| 12kbps | 16,000 | 666.67 | 250,047 | 11954.6 |
| 12kbps_24khz | 24,000 | 666.67 | 250,047 | 11954.6 |
| 24kbps_24khz | 24,000 | 1333.33 | 250,047 | 23909.1 |
Sources
1 source
Sources
1 sourceVérifié 5 sept.
Download files
Artefacts du modèle
35 artefacts
Artefacts du modèle
35 artefactsweights/0k75bps.v0/en_decoder.pt
pt · 17,7 MB · SHA-256 cc94ef19abb1…63a4 · Hugging Face
Download fileweights/0k75bps.v0/en_encoder.pt
pt · 18,4 MB · SHA-256 58722993c73b…9a6a · Hugging Face
Download fileweights/12kbps_24khz.v0/decoder.pt
pt · 18,0 MB · SHA-256 d0c6880e4aae…81ec · Hugging Face
Download fileweights/12kbps_24khz.v0/en_decoder.pt
pt · 10,6 MB · SHA-256 ce4ea00350e0…e0fa · Hugging Face
Download fileweights/12kbps_24khz.v0/en_encoder.pt
pt · 10,6 MB · SHA-256 81a46027d79b…8c27 · Hugging Face
Download fileweights/12kbps_24khz.v0/encoder.pt
pt · 3,70 MB · SHA-256 e341818f8044…8e3c · Hugging Face
Download fileweights/12kbps_24khz.v0/quantizer.pt
pt · 15,2 KB · SHA-256 4464e5cbfc64…f078 · Hugging Face
Download fileweights/24kbps_24khz.v0/decoder.pt
pt · 18,0 MB · SHA-256 d34ba3a0cfa5…1ef2 · Hugging Face
Download fileweights/24kbps_24khz.v0/en_decoder.pt
pt · 10,6 MB · SHA-256 4c3531dd1ac1…1732 · Hugging Face
Download fileweights/24kbps_24khz.v0/en_encoder.pt
pt · 10,6 MB · SHA-256 85c181fdbdf9…eb4f · Hugging Face
Download fileweights/24kbps_24khz.v0/encoder.pt
pt · 3,49 MB · SHA-256 7c3fe0abb5e2…2f93 · Hugging Face
Download fileweights/24kbps_24khz.v0/quantizer.pt
pt · 15,2 KB · SHA-256 9d98726e6eaa…e703 · Hugging Face
Download fileExtraits de sources
2 extraits
Extraits de sources
2 extraits--- license: mit pipeline_tag: audio-to-audio library_name: sq_codec --- # SQCodec This repository contains the implementation of SQCodec, a lightweight audio codec based on a single quantizer, introduced in the paper titled "One Quantizer is Enough: Toward a Lightweight Audio Codec". [Paper](https://arxiv.org/abs/2504.04949) [Code](https://github.com/zhai-lw/SQCodec) ## install ``` pip install sq_codec ``` ### demo Firstly, make sure you have installed the librosa package to load the example audio file. You can install it using pip: ``` pip install librosa ``` Then, you can use the following code to load a sample audio file, encode it using the SQCodec model, and decode it back to audio. The code also calculates the mean squared error (MSE) between the original and generated audio. ```python import librosa import torch import sq_codec all_models = sq_codec.list_models() print(f"Available models: {all_models}") MODEL_USED = '6kbps' codec = sq_codec.get_model(MODEL_USED) print(f"loaded codec({MODEL_USED}) and codec sample rate: {codec.config.sample_rate}") sample_audio, sample_rate = librosa.load(librosa.example("libri1")) sample_audio = sample_audio[None, :] print(f"loaded sample audio and audio sample_rate :{sample_rate}") sample_audio = librosa.resample(sample_audio, orig_sr=sample_rate, target_sr=codec.config.sample_rate) codec.network.cuda() codec.network.eval() with torch.inference_mode(): audio_in = torch.tensor(sample_audio, dtype=torch.float32, device='cuda') _, audio_length = audio_in.shape print(f"{audio_in.shape=}") q_feature, indices = codec.encode_audio(audio_in) audio_out = codec.decode_audio(q_feature) # or # audio_out = codec.decode_audio(indices=indices) generated_audio = audio_out[:, :audio_length].detach().cpu().numpy() mse = ((sample_audio - generated_audio) ** 2).mean().item() print(f"codec({MODEL_USED}) mse: {mse}") ``` ### available models | config_name | Sample rate(Hz) | tokens/s | Codebook size | Bitrate(bps) | |--------------|-----------------|----------|---------------|--------------| | 0k75bps | 16,000 | 44.44 | 117,649 | 748.6 | | 1k5bps | 16,000 | 88.89 | 117,649 | 1497.3 | | 3kbps | 16,000 | 177.78 | 117,649 | 2994.5 | | 6kbps | 16,000 | 355.56 | 117,649 | 5989.0 | | 12kbps | 16,000 | 666.67 | 250,047 | 11954.6 | | 12kbps_24khz | 24,000 | 666.67 | 250,047 | 11954.6 | | 24kbps_24khz | 24,000 | 1333....
Source context: 0 downloads · 1 likes · Pipeline audio-to-audio · Library sq_codec · Repo zhai-lw/SQCodec
