Zum Inhalt springen
ModelAufgelistetExtern
Browse files

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".

ArtOtherVersionRevision e80e263CBewertung

Modellquelle

Art
Other
Dateigröße
15,2 KB–18,4 MB
Version
vRevision e80e263
Aktualisiert
22. Sept. 2026
Downloads
0
Quelle
Hugging Face

Quellenbeschreibung

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

Code

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_nameSample rate(Hz)tokens/sCodebook sizeBitrate(bps)
0k75bps16,00044.44117,649748.6
1k5bps16,00088.89117,6491497.3
3kbps16,000177.78117,6492994.5
6kbps16,000355.56117,6495989.0
12kbps16,000666.67250,04711954.6
12kbps_24khz24,000666.67250,04711954.6
24kbps_24khz24,0001333.33250,04723909.1

Quellen

1 Quelle
Hugging FacePrimärVersion e80e2630b238f283755e65e38b78f0fe809178ce
huggingface.co/zhai-lw/SQCodec/tree/e80e2630b238f283755e65e38b78f0fe809178ce

Verifiziert 5. Sept.

Download files

Modellartefakte

35 Artefakte

weights/0k75bps.v0/decoder.pt

pt · 18,3 MB · SHA-256 ecf72e74f871…77ab · Hugging Face

Download file

weights/0k75bps.v0/en_decoder.pt

pt · 17,7 MB · SHA-256 cc94ef19abb1…63a4 · Hugging Face

Download file

weights/0k75bps.v0/en_encoder.pt

pt · 18,4 MB · SHA-256 58722993c73b…9a6a · Hugging Face

Download file

weights/0k75bps.v0/encoder.pt

pt · 3,71 MB · SHA-256 f7608d2baf24…610e · Hugging Face

Download file

weights/0k75bps.v0/quantizer.pt

pt · 15,2 KB · SHA-256 843fdf73882d…b46a · Hugging Face

Download file

weights/12kbps_24khz.v0/decoder.pt

pt · 18,0 MB · SHA-256 d0c6880e4aae…81ec · Hugging Face

Download file

weights/12kbps_24khz.v0/en_decoder.pt

pt · 10,6 MB · SHA-256 ce4ea00350e0…e0fa · Hugging Face

Download file

weights/12kbps_24khz.v0/en_encoder.pt

pt · 10,6 MB · SHA-256 81a46027d79b…8c27 · Hugging Face

Download file

weights/12kbps_24khz.v0/encoder.pt

pt · 3,70 MB · SHA-256 e341818f8044…8e3c · Hugging Face

Download file

weights/12kbps_24khz.v0/quantizer.pt

pt · 15,2 KB · SHA-256 4464e5cbfc64…f078 · Hugging Face

Download file

weights/12kbps.v0/decoder.pt

pt · 18,0 MB · SHA-256 7643ace92b27…c9fe · Hugging Face

Download file

weights/12kbps.v0/en_decoder.pt

pt · 10,6 MB · SHA-256 74b3e827f99c…4324 · Hugging Face

Download file

weights/12kbps.v0/en_encoder.pt

pt · 10,6 MB · SHA-256 24a59403b571…f14b · Hugging Face

Download file

weights/12kbps.v0/encoder.pt

pt · 3,56 MB · SHA-256 b517270916ec…f41e · Hugging Face

Download file

weights/12kbps.v0/quantizer.pt

pt · 15,2 KB · SHA-256 a5c0491314af…eb17 · Hugging Face

Download file

weights/1k5bps.v0/decoder.pt

pt · 18,3 MB · SHA-256 4cdc140765cb…ae28 · Hugging Face

Download file

weights/1k5bps.v0/en_decoder.pt

pt · 17,7 MB · SHA-256 a878c99911e6…46ed · Hugging Face

Download file

weights/1k5bps.v0/en_encoder.pt

pt · 18,2 MB · SHA-256 00b3f347dd40…4f75 · Hugging Face

Download file

weights/1k5bps.v0/encoder.pt

pt · 3,64 MB · SHA-256 78c5230ad300…e4b5 · Hugging Face

Download file

weights/1k5bps.v0/quantizer.pt

pt · 15,2 KB · SHA-256 8a78fa1977a6…da19 · Hugging Face

Download file

weights/24kbps_24khz.v0/decoder.pt

pt · 18,0 MB · SHA-256 d34ba3a0cfa5…1ef2 · Hugging Face

Download file

weights/24kbps_24khz.v0/en_decoder.pt

pt · 10,6 MB · SHA-256 4c3531dd1ac1…1732 · Hugging Face

Download file

weights/24kbps_24khz.v0/en_encoder.pt

pt · 10,6 MB · SHA-256 85c181fdbdf9…eb4f · Hugging Face

Download file

weights/24kbps_24khz.v0/encoder.pt

pt · 3,49 MB · SHA-256 7c3fe0abb5e2…2f93 · Hugging Face

Download file

weights/24kbps_24khz.v0/quantizer.pt

pt · 15,2 KB · SHA-256 9d98726e6eaa…e703 · Hugging Face

Download file

weights/3kbps.v0/decoder.pt

pt · 18,3 MB · SHA-256 7b8cf52135ec…86e1 · Hugging Face

Download file

weights/3kbps.v0/en_decoder.pt

pt · 10,6 MB · SHA-256 be1f730b4e0e…c4b9 · Hugging Face

Download file

weights/3kbps.v0/en_encoder.pt

pt · 10,6 MB · SHA-256 696dd61295d1…5d2d · Hugging Face

Download file

weights/3kbps.v0/encoder.pt

pt · 3,64 MB · SHA-256 1ee15f2cef68…d404 · Hugging Face

Download file

weights/3kbps.v0/quantizer.pt

pt · 15,2 KB · SHA-256 d9b9cef09e41…2913 · Hugging Face

Download file

weights/6kbps.v0/decoder.pt

pt · 18,0 MB · SHA-256 ac88fa3bf697…aa63 · Hugging Face

Download file

weights/6kbps.v0/en_decoder.pt

pt · 10,6 MB · SHA-256 9fed228b1de5…6952 · Hugging Face

Download file

weights/6kbps.v0/en_encoder.pt

pt · 10,6 MB · SHA-256 f257762202e8…09c0 · Hugging Face

Download file

weights/6kbps.v0/encoder.pt

pt · 3,66 MB · SHA-256 13ba35cd5178…22a3 · Hugging Face

Download file

weights/6kbps.v0/quantizer.pt

pt · 15,2 KB · SHA-256 f6eb5f320682…6c6e · Hugging Face

Download file

Quellenauszüge

2 Auszüge

--- 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