Upload all files from current directory
Browse files
README.md
CHANGED
|
@@ -1,70 +1,3 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
| 4 |
-
|
| 5 |
-
# **Introduction**
|
| 6 |
-
|
| 7 |
-
**`XY-Tokenizer`** is a speech codec that simultaneously models both semantic and acoustic aspects of speech, converting audio into discrete tokens and decoding them back to high-quality audio. It achieves efficient speech representation at only 1kbps with RVQ8 quantization at 12.5Hz frame rate.
|
| 8 |
-
|
| 9 |
-
- **Paper:** [Read on arXiv](https://arxiv.org/abs/2506.23325)
|
| 10 |
-
- **Source Code:**
|
| 11 |
-
- [GitHub Repo](https://github.com/OpenMOSS/MOSS-TTSD/tree/main/XY_Tokenizer)
|
| 12 |
-
- [Hugging Face Repo](https://huggingface.co/spaces/fnlp/MOSS-TTSD/tree/main/XY_Tokenizer)
|
| 13 |
-
|
| 14 |
-
## 📚 Related Project: **[MOSS-TTSD](https://huggingface.co/fnlp/MOSS-TTSD-v0.5)**
|
| 15 |
-
|
| 16 |
-
**`XY-Tokenizer`** serves as the underlying neural codec for **`MOSS-TTSD`**, our 1.7B Audio Language Model. \
|
| 17 |
-
Explore **`MOSS-TTSD`** for advanced text-to-speech and other audio generation tasks on [GitHub](https://github.com/OpenMOSS/MOSS-TTSD), [Blog](http://www.open-moss.com/en/moss-ttsd/), [博客](https://www.open-moss.com/cn/moss-ttsd/), and [Space Demo](https://huggingface.co/spaces/fnlp/MOSS-TTSD).
|
| 18 |
-
|
| 19 |
-
## ✨ Features
|
| 20 |
-
|
| 21 |
-
- **Dual-channel modeling**: Simultaneously captures semantic meaning and acoustic details
|
| 22 |
-
- **Efficient representation**: 1kbps bitrate with RVQ8 quantization at 12.5Hz
|
| 23 |
-
- **High-quality audio tokenization**: Convert speech to discrete tokens and back with minimal quality loss
|
| 24 |
-
- **Long audio support**: Process audio files longer than 30 seconds using chunking with overlap
|
| 25 |
-
- **Batch processing**: Efficiently process multiple audio files in batches
|
| 26 |
-
- **24kHz output**: Generate high-quality 24kHz audio output
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
## 🚀 Installation
|
| 30 |
-
|
| 31 |
-
```bash
|
| 32 |
-
git clone https://github.com/OpenMOSS/MOSS-TTSD.git
|
| 33 |
-
cd MOSS-TTSD
|
| 34 |
-
conda create -n xy_tokenizer python=3.10 -y && conda activate xy_tokenizer
|
| 35 |
-
pip install -r XY_Tokenizer/requirements.txt
|
| 36 |
-
```
|
| 37 |
-
|
| 38 |
-
## 💻 Quick Start
|
| 39 |
-
|
| 40 |
-
Here's how to use **`XY-Tokenizer`** with `transformers` to encode an audio file into discrete tokens and decode it back into a waveform.
|
| 41 |
-
|
| 42 |
-
```python
|
| 43 |
-
import torchaudio
|
| 44 |
-
from transformers import AutoFeatureExtractor, AutoModel
|
| 45 |
-
|
| 46 |
-
# 1. Load the feature extractor and the codec model
|
| 47 |
-
model_id = "fnlp/XY_Tokenizer_TTSD_V0"
|
| 48 |
-
feature_extractor = AutoFeatureExtractor.from_pretrained(model_id, trust_remote_code=True)
|
| 49 |
-
codec = AutoModel.from_pretrained(model_id, trust_remote_code=True).eval().to("cuda")
|
| 50 |
-
|
| 51 |
-
# 2. Load and preprocess the audio
|
| 52 |
-
# The model expects a 16kHz sample rate.
|
| 53 |
-
wav_form, sampling_rate = torchaudio.load("examples/m1.wav")
|
| 54 |
-
if sampling_rate != 16000:
|
| 55 |
-
wav_form = torchaudio.functional.resample(wav_form, orig_freq=sampling_rate, new_freq=16000)
|
| 56 |
-
|
| 57 |
-
# 3. Encode the audio into discrete codes
|
| 58 |
-
input_features = feature_extractor(wav_form, sampling_rate=16000, return_attention_mask=True, return_tensors="pt")
|
| 59 |
-
# The 'code' dictionary contains the discrete audio codes
|
| 60 |
-
code = codec.encode(input_features)
|
| 61 |
-
print(code)
|
| 62 |
-
|
| 63 |
-
# 4. Decode the codes back to an audio waveform
|
| 64 |
-
# The output is high-quality 24kHz audio.
|
| 65 |
-
output_wav = codec.decode(code["audio_codes"], overlap_seconds=10)
|
| 66 |
-
|
| 67 |
-
# 5. Save the reconstructed audio
|
| 68 |
-
for i, audio in enumerate(output_wav["audio_values"]):
|
| 69 |
-
torchaudio.save(f"audio_{i}.wav", audio.cpu(), 24000)
|
| 70 |
-
```
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|