Skip to main content

L3AC

This repository contains the implementation of L3AC, a lightweight audio codec based on a single quantizer, introduced in the paper titled "L3AC: Towards a Lightweight and Lossless Audio Codec".

Paper

Model Weights

Comparison of various audio codec
Comparison of various audio codec

install

pip install l3ac

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

all_models = l3ac.list_models()
print(f"Available models: {all_models}")

MODEL_USED = '1kbps'
codec = l3ac.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['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
1kbps 16,000 59.26 117,649 998.2
1k5bps 16,000 88.89 117,649 1497.3
3kbps 16,000 166.67 250,047 2988.6

Metadata

Release files for l3ac 1.0

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

Source distribution (sdist)

Source distribution for l3ac 1.0
File Size Uploaded Provenance Actions
l3ac-1.0.tar.gz 25.7 kB Without provenance Details for l3ac-1.0.tar.gz

Built distribution (wheel)

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

Total release size: 47.7 kB

Release files / l3ac-1.0.tar.gz

Download URL l3ac-1.0.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d596faf1e2dd177b3218cb24e5623de60bbf665047a3c603aa21cf84400cbde5
BLAKE2b-256 checksum
How to use checksums
84eedba24a2924ce02f0233cf3ba6757e0c649251ce2aad92e4cae2220a2e189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release files / l3ac-1.0-py3-none-any.whl

Download URL l3ac-1.0-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77be7b25d164cb00563ab5c8d33184b82466c9354323ac93000277ae225102ba
BLAKE2b-256 checksum
How to use checksums
94a46a6b42f327a2d406f5411c51769617d1c5f156eb94f4a341204687ced31e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Security for l3ac 1.0

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

1.0 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