l3ac


Namel3ac JSON
Version 1.0 PyPI version JSON
download
home_pageNone
SummaryL3AC: A nerual audio codec with one quantizer
upload_time2025-08-15 12:24:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords artificial intelligence audio codec deep learning pytorch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://arxiv.org/abs/2504.04949)

[Model Weights](https://huggingface.co/zhai-lw/L3AC)


<figure class="image">
  <img src="./bubble_chart.svg" alt="Comparison of various audio codec">
  <figcaption>Comparison of various audio codec</figcaption>
</figure>

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

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "l3ac",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "artificial intelligence, audio codec, deep learning, pytorch",
    "author": null,
    "author_email": "Linwei Zhai <zhai_lw@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/84/ee/dba24a2924ce02f0233cf3ba6757e0c649251ce2aad92e4cae2220a2e189/l3ac-1.0.tar.gz",
    "platform": null,
    "description": "# L3AC\n\nThis repository contains the implementation of L3AC, a lightweight audio codec based on a single quantizer,\nintroduced in the paper titled \"L3AC: Towards a Lightweight and Lossless Audio Codec\".\n\n[Paper](https://arxiv.org/abs/2504.04949)\n\n[Model Weights](https://huggingface.co/zhai-lw/L3AC)\n\n\n<figure class=\"image\">\n  <img src=\"./bubble_chart.svg\" alt=\"Comparison of various audio codec\">\n  <figcaption>Comparison of various audio codec</figcaption>\n</figure>\n\n## install\n\n```\npip install l3ac\n```\n\n### demo\n\nFirstly, make sure you have installed the librosa package to load the example audio file. You can install it using pip:\n\n```\npip install librosa\n```\n\nThen, you can use the following code to load a sample audio file, encode it using the L3AC model, and decode it back\nto audio. The code also calculates the mean squared error (MSE) between the original and generated audio.\n\n```python\nimport librosa\nimport torch\nimport l3ac\n\nall_models = l3ac.list_models()\nprint(f\"Available models: {all_models}\")\n\nMODEL_USED = '1kbps'\ncodec = l3ac.get_model(MODEL_USED)\nprint(f\"loaded codec({MODEL_USED}) and codec sample rate: {codec.config.sample_rate}\")\n\nsample_audio, sample_rate = librosa.load(librosa.example(\"libri1\"))\nsample_audio = sample_audio[None, :]\nprint(f\"loaded sample audio and audio sample_rate :{sample_rate}\")\n\nsample_audio = librosa.resample(sample_audio, orig_sr=sample_rate, target_sr=codec.config.sample_rate)\n\ncodec.network.cuda()\ncodec.network.eval()\nwith torch.inference_mode():\n    audio_in = torch.tensor(sample_audio, dtype=torch.float32, device='cuda')\n    _, audio_length = audio_in.shape\n    print(f\"{audio_in.shape=}\")\n    q_feature, indices = codec.encode_audio(audio_in)\n    audio_out = codec.decode_audio(q_feature)  # or\n    # audio_out = codec.decode_audio(indices=indices['indices'])\n    generated_audio = audio_out[:, :audio_length].detach().cpu().numpy()\n\nmse = ((sample_audio - generated_audio) ** 2).mean().item()\nprint(f\"codec({MODEL_USED}) mse: {mse}\")\n```\n\n### available models\n\n| config_name | Sample rate(Hz) | tokens/s | Codebook size | Bitrate(bps) |\n|-------------|-----------------|----------|---------------|--------------|\n| 0k75bps     | 16,000          | 44.44    | 117,649       | 748.6        |\n| 1kbps       | 16,000          | 59.26    | 117,649       | 998.2        |\n| 1k5bps      | 16,000          | 88.89    | 117,649       | 1497.3       |\n| 3kbps       | 16,000          | 166.67   | 250,047       | 2988.6       |\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "L3AC: A nerual audio codec with one quantizer",
    "version": "1.0",
    "project_urls": {
        "DOWNLOAD": "https://huggingface.co/zhai-lw/L3AC",
        "Documentation": "https://github.com/zhai-lw/L3AC#readme",
        "Issues": "https://github.com/zhai-lw/L3AC/issues",
        "Repository": "https://github.com/zhai-lw/L3AC.git"
    },
    "split_keywords": [
        "artificial intelligence",
        " audio codec",
        " deep learning",
        " pytorch"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "94a46a6b42f327a2d406f5411c51769617d1c5f156eb94f4a341204687ced31e",
                "md5": "9237381ed6b5fd65a21d67d8f02d8e5e",
                "sha256": "77be7b25d164cb00563ab5c8d33184b82466c9354323ac93000277ae225102ba"
            },
            "downloads": -1,
            "filename": "l3ac-1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9237381ed6b5fd65a21d67d8f02d8e5e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 21952,
            "upload_time": "2025-08-15T12:24:50",
            "upload_time_iso_8601": "2025-08-15T12:24:50.415292Z",
            "url": "https://files.pythonhosted.org/packages/94/a4/6a6b42f327a2d406f5411c51769617d1c5f156eb94f4a341204687ced31e/l3ac-1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "84eedba24a2924ce02f0233cf3ba6757e0c649251ce2aad92e4cae2220a2e189",
                "md5": "a39cf6438f2c428b0c584045202eb980",
                "sha256": "d596faf1e2dd177b3218cb24e5623de60bbf665047a3c603aa21cf84400cbde5"
            },
            "downloads": -1,
            "filename": "l3ac-1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a39cf6438f2c428b0c584045202eb980",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 25724,
            "upload_time": "2025-08-15T12:24:49",
            "upload_time_iso_8601": "2025-08-15T12:24:49.011632Z",
            "url": "https://files.pythonhosted.org/packages/84/ee/dba24a2924ce02f0233cf3ba6757e0c649251ce2aad92e4cae2220a2e189/l3ac-1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-15 12:24:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zhai-lw",
    "github_project": "L3AC#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "l3ac"
}
        
Elapsed time: 0.71214s