Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -40,30 +40,40 @@ pip install -r XY_Tokenizer/requirements.txt
|
|
| 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
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
```
|
|
|
|
| 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 os
|
| 44 |
import torchaudio
|
| 45 |
+
from transformers import AutoModelForCausalLM
|
| 46 |
+
from transformers.models.moss_ttsd.processor_moss_ttsd import MossTTSDProcessor
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
processor = MossTTSDProcessor.from_pretrained(
|
| 50 |
+
"fnlp/MOSS-TTSD-v0.5",
|
| 51 |
+
codec_path="gaoyang07/XY_Tokenizer",
|
| 52 |
+
trust_remote_code=True
|
| 53 |
+
)
|
| 54 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
+
"fnlp/MOSS-TTSD-v0.5",
|
| 56 |
+
trust_remote_code=True
|
| 57 |
+
).eval()
|
| 58 |
+
|
| 59 |
+
data = [{
|
| 60 |
+
"base_path": "./examples",
|
| 61 |
+
"text": "[S1]单元009,你到底能不能好好工作?我劝你一句,这个时代,不跟上AI浪潮,就会被彻底淘汰![S2]这个嘛,那我得先问问硅基之主",
|
| 62 |
+
"system_prompt": "你是一个根据文本生成对应音频的语音合成器。",
|
| 63 |
+
"prompt_text": "[S1]嘎子,你听叔的,你听叔的,其实你跟所有人PK,有的时候我也在看,我也在看,无非两,两件事,一个是面子,不想输。[S2]你别说,那天潘老师有一个徒弟开直播,给我开专场,潘老师一徒弟开直播给我开专场,给我一顿骂。",
|
| 64 |
+
"prompt_audio": "panchangjiang_gazi.wav",
|
| 65 |
+
}]
|
| 66 |
+
|
| 67 |
+
# Try to use the ExtractorIterator as an iterator
|
| 68 |
+
print("Trying iterator approach...", flush=True)
|
| 69 |
+
inputs = processor(data)
|
| 70 |
+
token_ids = model.generate(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])
|
| 71 |
+
text, audios = processor.batch_decode(token_ids)
|
| 72 |
+
|
| 73 |
+
if not os.path.exists("outputs/"):
|
| 74 |
+
os.mkdir("outputs/")
|
| 75 |
+
for i, data in enumerate(audios):
|
| 76 |
+
for j, fragment in enumerate(data):
|
| 77 |
+
print(f"Saving audio_{i}_{j}.wav...", flush=True)
|
| 78 |
+
torchaudio.save(f"outputs/audio_{i}_{j}.wav", fragment.cpu(), 24000)
|
| 79 |
```
|