File size: 1,435 Bytes
1150afc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
library_name: transformers
license: other
tags:
  - audio
  - audio-codec
  - pytorch
  - bfloat16
---

# Liquid Codec BF16

## Remote-code loading

The repository includes the codec configuration and model implementation, so it can be loaded with `AutoModel`:

```python
import torch
from transformers import AutoModel

codec = AutoModel.from_pretrained(
    "LiquidAI/Liquid-Codec",
    trust_remote_code=True,
    dtype=torch.bfloat16,
    device_map="cuda",
)
waveform = torch.randn(1, 24_000 * 3, device="cuda")  # 24 kHz
codes = codec.encode(waveform).audio_codes
reconstructed = codec.decode(codes).audio_values
```

## Native loading and streaming

```python
import torch
from transformers import LiquidCodecModel, LiquidCodecStreamingCache

codec = LiquidCodecModel.from_pretrained("LiquidAI/Liquid-Codec", dtype=torch.bfloat16, device_map="cuda")

waveform = torch.randn(1, 24_000 * 3, device="cuda")  # 24 kHz
codes = codec.encode(waveform).audio_codes  # (1, 12, 38)
reconstructed = codec.decode(codes).audio_values  # (1, 38 * 1920), float32

# streaming synthesis: every chunk returns the samples that no later frame changes any more
cache = LiquidCodecStreamingCache(codec.config)
chunks = [codec.decode(codes[..., i : i + 1], cache, finalize=False).audio_values for i in range(codes.shape[-1])]
chunks.append(codec.decode(codes[..., :0], cache, finalize=True).audio_values)
streamed = torch.cat(chunks, dim=-1)
```