Skip to main content

L3AC: A nerual audio codec with one quantizer

Project description

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

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

l3ac-1.0.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

l3ac-1.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file l3ac-1.0.tar.gz.

File metadata

  • Download URL: l3ac-1.0.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for l3ac-1.0.tar.gz
Algorithm Hash digest
SHA256 d596faf1e2dd177b3218cb24e5623de60bbf665047a3c603aa21cf84400cbde5
MD5 a39cf6438f2c428b0c584045202eb980
BLAKE2b-256 84eedba24a2924ce02f0233cf3ba6757e0c649251ce2aad92e4cae2220a2e189

See more details on using hashes here.

File details

Details for the file l3ac-1.0-py3-none-any.whl.

File metadata

  • Download URL: l3ac-1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for l3ac-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77be7b25d164cb00563ab5c8d33184b82466c9354323ac93000277ae225102ba
MD5 9237381ed6b5fd65a21d67d8f02d8e5e
BLAKE2b-256 94a46a6b42f327a2d406f5411c51769617d1c5f156eb94f4a341204687ced31e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page