Update model card with paper metadata, authors, and tags
#1
by nielsr HF Staff - opened
README.md
CHANGED
|
@@ -1,18 +1,27 @@
|
|
| 1 |
---
|
| 2 |
-
pipeline_tag: text-to-speech
|
| 3 |
datasets:
|
| 4 |
- facebook/multilingual_librispeech
|
| 5 |
language:
|
| 6 |
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
---
|
|
|
|
| 8 |
# FlexiCodec: A Dynamic Neural Audio Codec for Low Frame Rates
|
| 9 |
|
| 10 |
-
[](https://flexicodec.github.io/)
|
| 11 |
[](https://arxiv.org/abs/2510.00981)
|
|
|
|
|
|
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
## Abstract
|
| 15 |
Neural audio codecs are foundational to speech language models. It is expected to have a low frame rate and decoupled semantic and acoustic information. A lower frame rate codec can reduce the computational cost of speech language models by shortening the sequence length. Recent studies have developed 12.5Hz low-frame-rate audio codecs, but even lower frame rate codecs remain underexplored. We find that a major challenge for very low frame rate tokens is missing semantic information. This paper introduces FlexiCodec to address this limitation. FlexiCodec improves semantic preservation with a dynamic frame rate approach and introduces a novel architecture featuring an ASR feature-assisted dual stream encoding and Transformer bottlenecks. With dynamic frame rates, it uses less frames at information-sparse regions through adaptively merging semantically similar frames. A dynamic frame rate also allows FlexiCodec to support inference-time controllable frame rates between 3Hz and 12.5Hz. Experiments on 6.25Hz, 8.3Hz and 12.5Hz average frame rates confirm that FlexiCodec excels over baseline systems in semantic information preservation and delivers a high audio reconstruction quality. We also validate the effectiveness of FlexiCodec in language model-based TTS.
|
|
|
|
| 16 |

|
| 17 |
|
| 18 |
## Installation
|
|
@@ -21,11 +30,8 @@ git clone https://github.com/amphionspace/FlexiCodec.git
|
|
| 21 |
cd FlexiCodec
|
| 22 |
pip install -r requirements.txt
|
| 23 |
```
|
| 24 |
-
<!-- # pip install -e . -->
|
| 25 |
-
|
| 26 |
-
## FlexiCodec
|
| 27 |
-
Code is available under [`flexicodec/modeling_flexicodec.py`](flexicodec/modeling_flexicodec.py).
|
| 28 |
|
|
|
|
| 29 |
To run inference (automatically downloads checkpoint from huggingface):
|
| 30 |
```python
|
| 31 |
import torch
|
|
@@ -55,17 +61,9 @@ print(f"This sample avg frame rate: {encoded_output['token_lengths'].shape[-1] /
|
|
| 55 |
```
|
| 56 |
|
| 57 |
Notes:
|
| 58 |
-
- You may tune the `num_quantizers
|
| 59 |
-
|
| 60 |
-
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
- Batched input is supported. You can directly pass audios shaped [B,T] to the script above, but the audio length information will be unavailable.
|
| 64 |
-
To resolve this, you can additionally pass an `audio_lens` parameter to `encode_flexicodec`, and you can crop the output for each audio in `encoded_output[speech_token_len]`.
|
| 65 |
-
|
| 66 |
-
- If you want to use the above code elsewhere, you might want to add `sys.path.append('/path/to/FlexiCodec')` to find the code.
|
| 67 |
-
|
| 68 |
-
- To extract continuous features from the semantic tokens, use:
|
| 69 |
```python
|
| 70 |
feat = model_dict['model'].get_semantic_feature(encoded_output['semantic_codes'])
|
| 71 |
```
|
|
@@ -77,68 +75,8 @@ sudo apt install espeak-ng
|
|
| 77 |
pip install cached_path phonemizer openai-whisper
|
| 78 |
```
|
| 79 |
|
| 80 |
-
###
|
| 81 |
-
The
|
| 82 |
-
To run NAR TTS inference using FlexiCodec-Voicebox:
|
| 83 |
-
|
| 84 |
-
```python
|
| 85 |
-
import torch
|
| 86 |
-
import torchaudio
|
| 87 |
-
from flexicodec.nar_tts.inference_voicebox import (
|
| 88 |
-
prepare_voicebox_model,
|
| 89 |
-
infer_voicebox_tts
|
| 90 |
-
)
|
| 91 |
-
import cached_path
|
| 92 |
-
# Prepare model (loads model and vocoder)
|
| 93 |
-
checkpoint_path = cached_path('hf://jiaqili3/flexicodec/nartts.safetensors')
|
| 94 |
-
model_dict = prepare_voicebox_model(checkpoint_path)
|
| 95 |
-
|
| 96 |
-
# Option 1: Inference with audio file paths
|
| 97 |
-
gt_audio_path = "audio_examples/61-70968-0000_gt.wav" # Target content. Example GT audio
|
| 98 |
-
ref_audio_path = "audio_examples/61-70968-0000_ref.wav" # Reference voice/style.
|
| 99 |
-
|
| 100 |
-
output_audio, output_sr = infer_voicebox_tts(
|
| 101 |
-
model_dict=model_dict,
|
| 102 |
-
gt_audio_path=gt_audio_path,
|
| 103 |
-
ref_audio_path=ref_audio_path,
|
| 104 |
-
n_timesteps=15, # Number of diffusion steps (default: 15)
|
| 105 |
-
cfg=2.0, # Classifier-free guidance scale (default: 2.0)
|
| 106 |
-
rescale_cfg=0.75, # CFG rescaling factor (default: 0.75)
|
| 107 |
-
merging_threshold=1.0 # Merging threshold for frame rate control (default: 1.0, max: 1.0)
|
| 108 |
-
)
|
| 109 |
-
|
| 110 |
-
# Save output
|
| 111 |
-
torchaudio.save("output.wav", output_audio.unsqueeze(0) if output_audio.dim() == 1 else output_audio, output_sr)
|
| 112 |
-
|
| 113 |
-
# Option 2: Inference with audio tensors
|
| 114 |
-
gt_audio, gt_sr = torchaudio.load("path/to/ground_truth.wav")
|
| 115 |
-
ref_audio, ref_sr = torchaudio.load("path/to/reference.wav")
|
| 116 |
-
|
| 117 |
-
output_audio, output_sr = infer_voicebox_tts(
|
| 118 |
-
model_dict=model_dict,
|
| 119 |
-
gt_audio=gt_audio,
|
| 120 |
-
ref_audio=ref_audio,
|
| 121 |
-
gt_sample_rate=gt_sr,
|
| 122 |
-
ref_sample_rate=ref_sr,
|
| 123 |
-
n_timesteps=15,
|
| 124 |
-
cfg=2.0,
|
| 125 |
-
rescale_cfg=0.75,
|
| 126 |
-
merging_threshold=1.0
|
| 127 |
-
)
|
| 128 |
-
```
|
| 129 |
-
|
| 130 |
-
**Notes:**
|
| 131 |
-
- The model automatically detects and uses CUDA, MPS (Apple Silicon), or CPU devices
|
| 132 |
-
- Ground truth audio (`gt_audio`) determines the semantic content of the output
|
| 133 |
-
- Reference audio (`ref_audio`) determines the voice/style characteristics
|
| 134 |
-
- Output sample rate is typically 16000 Hz or 24000 Hz depending on the model configuration
|
| 135 |
-
- You can reuse `model_dict` for multiple inference calls to avoid reloading the model
|
| 136 |
-
- `merging_threshold` controls FlexiCodec's dynamic frame rate: lower values (e.g., 0.87, 0.91) enable merging for lower average frame rates, while 1.0 disables merging (standard 12.5Hz)
|
| 137 |
-
|
| 138 |
-
### FlexiCodec-based AR+NAR TTS Inference
|
| 139 |
-
The AR+NAR TTS system generates speech tokens from text using an autoregressive transformer model, and then uses the Voicebox NAR system to decode the tokens into audio.
|
| 140 |
-
|
| 141 |
-
To perform complete text-to-speech with both AR generation and NAR decoding:
|
| 142 |
|
| 143 |
```python
|
| 144 |
import torch
|
|
@@ -146,7 +84,7 @@ import torchaudio
|
|
| 146 |
from flexicodec.ar_tts.inference_tts import tts_synthesize
|
| 147 |
from flexicodec.ar_tts.modeling_artts import prepare_artts_model
|
| 148 |
from flexicodec.nar_tts.inference_voicebox import prepare_voicebox_model
|
| 149 |
-
import cached_path
|
| 150 |
|
| 151 |
# Prepare both AR and NAR models
|
| 152 |
ar_checkpoint = cached_path('hf://jiaqili3/flexicodec/artts.safetensors')
|
|
@@ -156,46 +94,26 @@ ar_model_dict = prepare_artts_model(ar_checkpoint)
|
|
| 156 |
nar_model_dict = prepare_voicebox_model(nar_checkpoint)
|
| 157 |
|
| 158 |
# Full TTS synthesis
|
| 159 |
-
output_audio, output_sr = tts_synthesize(
|
| 160 |
ar_model_dict=ar_model_dict,
|
| 161 |
nar_model_dict=nar_model_dict,
|
| 162 |
-
text="Hello, this is a complete text
|
| 163 |
language="en",
|
| 164 |
-
ref_audio_path="audio_examples/
|
| 165 |
-
ref_text="
|
| 166 |
-
merging_threshold=0.91, #
|
| 167 |
-
|
| 168 |
-
top_k=25,
|
| 169 |
-
temperature=1.0,
|
| 170 |
-
predict_duration=True,
|
| 171 |
-
duration_top_k=1,
|
| 172 |
-
n_timesteps=15, # NAR diffusion steps
|
| 173 |
-
cfg=2.0, # NAR classifier-free guidance
|
| 174 |
-
rescale_cfg=0.75, # NAR CFG rescaling
|
| 175 |
-
use_nar=True, # Set to False for AR-only decoding
|
| 176 |
)
|
| 177 |
|
| 178 |
# Save output
|
| 179 |
torchaudio.save("output.wav", output_audio.unsqueeze(0) if output_audio.dim() == 1 else output_audio, output_sr)
|
| 180 |
```
|
| 181 |
|
| 182 |
-
**Notes:**
|
| 183 |
-
- `tts_synthesize` performs the full pipeline: AR generation + NAR decoding to audio
|
| 184 |
-
- Reference audio (`ref_audio_path`) provides the voice/style characteristics
|
| 185 |
-
- Reference text (`ref_text`) is optional and can help with prosody alignment
|
| 186 |
-
- Set `use_nar=False` in `tts_synthesize` to use AR-only decoding (faster but lower quality)
|
| 187 |
-
|
| 188 |
-
### Training reference implementations
|
| 189 |
-
Inside `flexicodec/ar_tts/modeling_artts.py` and `flexicodec/nar_tts/modeling_voicebox.py` there are `training_forward` methods that receive audios and prepared sensevoice-small input "FBank" features. (`dl_output` dictionary containing `x` (the [`feature_extractor`](flexicodec/infer.py#L50) output), `x_lens` (length of each x before padding), `audio` (the 16khz audio tensor)).
|
| 190 |
-
Training can be replicated by passing the same data to the `training_forward` methods.
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
## Acknowledgements & Citation
|
| 195 |
- Our codebase setup is based on [DualCodec](https://github.com/jiaqili3/DualCodec)
|
| 196 |
- We thank the [Mimi Codec](https://github.com/kyutai-labs/moshi) for transformer implementations
|
| 197 |
|
| 198 |
-
If you find our works useful, please consider citing
|
| 199 |
```biblatex
|
| 200 |
@article{li2025flexicodec,
|
| 201 |
title={FlexiCodec: A Dynamic Neural Audio Codec for Low Frame Rates},
|
|
@@ -203,11 +121,4 @@ If you find our works useful, please consider citing as:
|
|
| 203 |
journal={arXiv preprint arXiv:2510.00981},
|
| 204 |
year={2025}
|
| 205 |
}
|
| 206 |
-
|
| 207 |
-
@article{li2025dualcodec,
|
| 208 |
-
title={Dualcodec: A low-frame-rate, semantically-enhanced neural audio codec for speech generation},
|
| 209 |
-
author={Li, Jiaqi and Lin, Xiaolong and Li, Zhekai and Huang, Shixi and Wang, Yuancheng and Wang, Chaoren and Zhan, Zhenpeng and Wu, Zhizheng},
|
| 210 |
-
journal={Interspeech 2025},
|
| 211 |
-
year={2025}
|
| 212 |
-
}
|
| 213 |
```
|
|
|
|
| 1 |
---
|
|
|
|
| 2 |
datasets:
|
| 3 |
- facebook/multilingual_librispeech
|
| 4 |
language:
|
| 5 |
- en
|
| 6 |
+
pipeline_tag: text-to-speech
|
| 7 |
+
tags:
|
| 8 |
+
- audio-codec
|
| 9 |
+
- neural-audio-codec
|
| 10 |
---
|
| 11 |
+
|
| 12 |
# FlexiCodec: A Dynamic Neural Audio Codec for Low Frame Rates
|
| 13 |
|
|
|
|
| 14 |
[](https://arxiv.org/abs/2510.00981)
|
| 15 |
+
[](https://flexicodec.github.io/)
|
| 16 |
+
[](https://openreview.net/forum?id=kYkfCs4ZAH)
|
| 17 |
|
| 18 |
+
This is the official Hugging Face repository for **FlexiCodec**, a dynamic neural audio codec designed for speech language models.
|
| 19 |
+
|
| 20 |
+
**Authors:** Jiaqi Li, Yao Qian, Yuxuan Hu, Leying Zhang, Xiaofei Wang, Heng Lu, Manthan Thakker, Jinyu Li, Sheng Zhao, Zhizheng Wu.
|
| 21 |
|
| 22 |
## Abstract
|
| 23 |
Neural audio codecs are foundational to speech language models. It is expected to have a low frame rate and decoupled semantic and acoustic information. A lower frame rate codec can reduce the computational cost of speech language models by shortening the sequence length. Recent studies have developed 12.5Hz low-frame-rate audio codecs, but even lower frame rate codecs remain underexplored. We find that a major challenge for very low frame rate tokens is missing semantic information. This paper introduces FlexiCodec to address this limitation. FlexiCodec improves semantic preservation with a dynamic frame rate approach and introduces a novel architecture featuring an ASR feature-assisted dual stream encoding and Transformer bottlenecks. With dynamic frame rates, it uses less frames at information-sparse regions through adaptively merging semantically similar frames. A dynamic frame rate also allows FlexiCodec to support inference-time controllable frame rates between 3Hz and 12.5Hz. Experiments on 6.25Hz, 8.3Hz and 12.5Hz average frame rates confirm that FlexiCodec excels over baseline systems in semantic information preservation and delivers a high audio reconstruction quality. We also validate the effectiveness of FlexiCodec in language model-based TTS.
|
| 24 |
+
|
| 25 |

|
| 26 |
|
| 27 |
## Installation
|
|
|
|
| 30 |
cd FlexiCodec
|
| 31 |
pip install -r requirements.txt
|
| 32 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
## FlexiCodec Usage
|
| 35 |
To run inference (automatically downloads checkpoint from huggingface):
|
| 36 |
```python
|
| 37 |
import torch
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
Notes:
|
| 64 |
+
- You may tune the `num_quantizers` (max 24) and `merging_threshold` (max 1.0) parameters. Setting `merging_threshold=1.0` results in a standard 12.5Hz neural audio codec.
|
| 65 |
+
- Batched input is supported. You can pass audios shaped `[B, T]`, but audio length information will be unavailable unless you pass an `audio_lens` parameter to `encode_flexicodec`.
|
| 66 |
+
- To extract continuous features from the semantic tokens:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
```python
|
| 68 |
feat = model_dict['model'].get_semantic_feature(encoded_output['semantic_codes'])
|
| 69 |
```
|
|
|
|
| 75 |
pip install cached_path phonemizer openai-whisper
|
| 76 |
```
|
| 77 |
|
| 78 |
+
### AR+NAR TTS Inference
|
| 79 |
+
The AR+NAR TTS system generates speech tokens from text and then uses the Voicebox NAR system to decode them into audio.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
```python
|
| 82 |
import torch
|
|
|
|
| 84 |
from flexicodec.ar_tts.inference_tts import tts_synthesize
|
| 85 |
from flexicodec.ar_tts.modeling_artts import prepare_artts_model
|
| 86 |
from flexicodec.nar_tts.inference_voicebox import prepare_voicebox_model
|
| 87 |
+
from cached_path import cached_path
|
| 88 |
|
| 89 |
# Prepare both AR and NAR models
|
| 90 |
ar_checkpoint = cached_path('hf://jiaqili3/flexicodec/artts.safetensors')
|
|
|
|
| 94 |
nar_model_dict = prepare_voicebox_model(nar_checkpoint)
|
| 95 |
|
| 96 |
# Full TTS synthesis
|
| 97 |
+
output_audio, output_sr, duration_classes = tts_synthesize(
|
| 98 |
ar_model_dict=ar_model_dict,
|
| 99 |
nar_model_dict=nar_model_dict,
|
| 100 |
+
text="Hello, this is a complete text to speech example.",
|
| 101 |
language="en",
|
| 102 |
+
ref_audio_path="./audio_examples/1089-134686-0030.flac", # Reference voice
|
| 103 |
+
ref_text="be ware of making that mistake", # Optional reference text
|
| 104 |
+
merging_threshold=0.91, # 0.91 for ~8.3Hz, 0.86 for ~6.25Hz
|
| 105 |
+
use_nar=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
)
|
| 107 |
|
| 108 |
# Save output
|
| 109 |
torchaudio.save("output.wav", output_audio.unsqueeze(0) if output_audio.dim() == 1 else output_audio, output_sr)
|
| 110 |
```
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
## Acknowledgements & Citation
|
| 113 |
- Our codebase setup is based on [DualCodec](https://github.com/jiaqili3/DualCodec)
|
| 114 |
- We thank the [Mimi Codec](https://github.com/kyutai-labs/moshi) for transformer implementations
|
| 115 |
|
| 116 |
+
If you find our works useful, please consider citing:
|
| 117 |
```biblatex
|
| 118 |
@article{li2025flexicodec,
|
| 119 |
title={FlexiCodec: A Dynamic Neural Audio Codec for Low Frame Rates},
|
|
|
|
| 121 |
journal={arXiv preprint arXiv:2510.00981},
|
| 122 |
year={2025}
|
| 123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
```
|