Skip to main content

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

Model Weights

Comparison of various audio codec
Comparison of various 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}")

Metadata

Release files for sq_codec 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sq_codec 0.0.1
File Size Uploaded Provenance Actions
sq_codec-0.0.1.tar.gz 21.8 kB Without provenance Details for sq_codec-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sq_codec 0.0.1
File Interpreter ABI Platform Actions
sq_codec-0.0.1-py3-none-any.whl Python 3 none any Details for sq_codec-0.0.1-py3-none-any.whl

Total release size: 47.0 kB

Release files / sq_codec-0.0.1.tar.gz

Download URL sq_codec-0.0.1.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5fb71975b1a2d50b4a1cb5fd548251eca70bb1878fb1e9fd045d340a9db0e132
BLAKE2b-256 checksum
How to use checksums
c5e7be2ca225a0c59cc6c603a7c0699f720ac3e2416e207ed3d1e7abc6e41240
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / sq_codec-0.0.1-py3-none-any.whl

Download URL sq_codec-0.0.1-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96afb3d16f7c6399e65d7447f4191c14cb91b9f7fca1223c5529944f3fe92258
BLAKE2b-256 checksum
How to use checksums
d18c41254c45a2e503540274c5a85e3f3693b7f703f5ad5c6acbeee4c75b7d3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for sq_codec 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page