File size: 9,445 Bytes
57d3c68 2ad4fb2 57d3c68 5c814ce fce6546 2ad4fb2 1ac4aa5 2ad4fb2 5c814ce 57d3c68 f181f24 9ec7e3c 2ad4fb2 b62123b 2ad4fb2 5c814ce 2ad4fb2 9ec7e3c |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
---
license: llama3.2
language:
- en
base_model:
- canopylabs/orpheus-3b-0.1-ft
pipeline_tag: text-to-speech
library_name: transformers
tags:
- Voice:Luna
- Female
- Radio
- 3B
---

# **Llama-3B-Mono-Luna**
> Llama-3B-Mono-Luna is a Llama-based Speech-LLM designed for high-quality, empathetic text-to-speech generation. This model has been fine-tuned to deliver human-like speech synthesis, achieving exceptional clarity, expressiveness, and real-time streaming performance. The model has been fine-tuned from mono audio of a female voice named 'Luna' with a radio essence using the base model `canopylabs/orpheus-3b-0.1-ft`.
> [!Important]
> In some cases, the results may be inconsistent, particularly when handling complex speech transformations.
<audio controls src="https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/Ye-Sonj51hDfi9IjUhl0B.wav"></audio>
<audio controls src="https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/OjMAZNjpip7tHu6T3_Rjm.wav"></audio>
[ paralinguistic emotions soft]
<audio controls src="https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/08Vb3CE8Ifi6jwpzI7Yuv.wav"></audio>
## **Model Details**
- **Base Model:** `canopylabs/orpheus-3b-0.1-ft`
- **Languages Supported:** English
- **License:** Llama 3.2
- **Model Version:** N/A
---
## **Paralinguistic Elements**
The model can generate speech with the following emotions:
| Elements | Elements | Elements |
|------------|------------|------------|
| laugh | chuckle | sigh |
| sniffle | groan | yawn |
| gasp | uhm | giggles & more |
---
## **Run with Transformers 🤗**
```python
from huggingface_hub import notebook_login, HfApi
notebook_login()
```
### **Install Dependencies**
```python
%%capture
!pip install snac accelerate
!pip install transformers
!pip install gradio
```
## **Usage**
```py
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import gradio as gr
from snac import SNAC
def redistribute_codes(row):
"""
Convert a sequence of token codes into an audio waveform using SNAC.
The code assumes each 7 tokens represent one group of instructions.
"""
row_length = row.size(0)
new_length = (row_length // 7) * 7
trimmed_row = row[:new_length]
code_list = [t - 128266 for t in trimmed_row]
layer_1, layer_2, layer_3 = [], [], []
for i in range((len(code_list) + 1) // 7):
layer_1.append(code_list[7 * i][None])
layer_2.append(code_list[7 * i + 1][None] - 4096)
layer_3.append(code_list[7 * i + 2][None] - (2 * 4096))
layer_3.append(code_list[7 * i + 3][None] - (3 * 4096))
layer_2.append(code_list[7 * i + 4][None] - (4 * 4096))
layer_3.append(code_list[7 * i + 5][None] - (5 * 4096))
layer_3.append(code_list[7 * i + 6][None] - (6 * 4096))
with torch.no_grad():
codes = [
torch.concat(layer_1),
torch.concat(layer_2),
torch.concat(layer_3)
]
for i in range(len(codes)):
codes[i][codes[i] < 0] = 0
codes[i] = codes[i][None]
audio_hat = snac_model.decode(codes)
return audio_hat.cpu()[0, 0]
# Load the SNAC model for audio decoding
snac_model = SNAC.from_pretrained("hubertsiuzdak/snac_24khz").to("cuda")
# Load the single-speaker language model
tokenizer = AutoTokenizer.from_pretrained('prithivMLmods/Llama-3B-Mono-Luna')
model = AutoModelForCausalLM.from_pretrained(
'prithivMLmods/Llama-3B-Mono-Luna', torch_dtype=torch.bfloat16
).cuda()
def generate_audio(text, temperature, top_p, max_new_tokens):
"""
Given input text, generate speech audio.
"""
speaker = "Luna"
prompt = f'<custom_token_3><|begin_of_text|>{speaker}: {text}<|eot_id|><custom_token_4><custom_token_5><custom_token_1>'
input_ids = tokenizer(prompt, add_special_tokens=False, return_tensors='pt').to('cuda')
with torch.no_grad():
generated_ids = model.generate(
**input_ids,
max_new_tokens=max_new_tokens,
do_sample=True,
temperature=temperature,
top_p=top_p,
repetition_penalty=1.1,
num_return_sequences=1,
eos_token_id=128258,
)
row = generated_ids[0, input_ids['input_ids'].shape[1]:]
y_tensor = redistribute_codes(row)
y_np = y_tensor.detach().cpu().numpy()
return (24000, y_np)
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("# Llama-3B-Mono-Luna - Single Speaker Audio Generation")
gr.Markdown("Generate speech audio using the `prithivMLmods/Llama-3B-Mono-Luna` model.")
with gr.Row():
text_input = gr.Textbox(lines=4, label="Input Text")
with gr.Row():
temp_slider = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=0.9, label="Temperature")
top_p_slider = gr.Slider(minimum=0.1, maximum=1.0, step=0.05, value=0.8, label="Top-p")
tokens_slider = gr.Slider(minimum=100, maximum=2000, step=50, value=1200, label="Max New Tokens")
output_audio = gr.Audio(type="numpy", label="Generated Audio")
generate_button = gr.Button("Generate Audio")
generate_button.click(
fn=generate_audio,
inputs=[text_input, temp_slider, top_p_slider, tokens_slider],
outputs=output_audio
)
if __name__ == "__main__":
demo.launch()
```
[ or ]
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import gradio as gr
from snac import SNAC
def redistribute_codes(row):
"""
Convert a sequence of token codes into an audio waveform using SNAC.
The code assumes each 7 tokens represent one group of instructions.
"""
row_length = row.size(0)
new_length = (row_length // 7) * 7
trimmed_row = row[:new_length]
code_list = [t - 128266 for t in trimmed_row]
layer_1, layer_2, layer_3 = [], [], []
for i in range((len(code_list) + 1) // 7):
layer_1.append(code_list[7 * i][None])
layer_2.append(code_list[7 * i + 1][None] - 4096)
layer_3.append(code_list[7 * i + 2][None] - (2 * 4096))
layer_3.append(code_list[7 * i + 3][None] - (3 * 4096))
layer_2.append(code_list[7 * i + 4][None] - (4 * 4096))
layer_3.append(code_list[7 * i + 5][None] - (5 * 4096))
layer_3.append(code_list[7 * i + 6][None] - (6 * 4096))
with torch.no_grad():
codes = [
torch.concat(layer_1),
torch.concat(layer_2),
torch.concat(layer_3)
]
for i in range(len(codes)):
codes[i][codes[i] < 0] = 0
codes[i] = codes[i][None]
audio_hat = snac_model.decode(codes)
return audio_hat.cpu()[0, 0]
# Load the SNAC model for audio decoding
snac_model = SNAC.from_pretrained("hubertsiuzdak/snac_24khz").to("cuda")
# Load the single-speaker language model
tokenizer = AutoTokenizer.from_pretrained('prithivMLmods/Llama-3B-Mono-Luna')
model = AutoModelForCausalLM.from_pretrained(
'prithivMLmods/Llama-3B-Mono-Luna', torch_dtype=torch.bfloat16
).cuda()
def generate_audio(text, temperature, top_p, max_new_tokens):
"""
Given input text, generate speech audio.
"""
prompt = f'<custom_token_3><|begin_of_text|>{text}<|eot_id|><custom_token_4><custom_token_5><custom_token_1>'
input_ids = tokenizer(prompt, add_special_tokens=False, return_tensors='pt').to('cuda')
with torch.no_grad():
generated_ids = model.generate(
**input_ids,
max_new_tokens=max_new_tokens,
do_sample=True,
temperature=temperature,
top_p=top_p,
repetition_penalty=1.1,
num_return_sequences=1,
eos_token_id=128258,
)
row = generated_ids[0, input_ids['input_ids'].shape[1]:]
y_tensor = redistribute_codes(row)
y_np = y_tensor.detach().cpu().numpy()
return (24000, y_np)
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("# Llama-3B-Mono-Luna - Single Speaker Audio Generation")
gr.Markdown("Generate speech audio using the `prithivMLmods/Llama-3B-Mono-Luna` model.")
with gr.Row():
text_input = gr.Textbox(lines=4, label="Input Text")
with gr.Row():
temp_slider = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=0.9, label="Temperature")
top_p_slider = gr.Slider(minimum=0.1, maximum=1.0, step=0.05, value=0.8, label="Top-p")
tokens_slider = gr.Slider(minimum=100, maximum=2000, step=50, value=1200, label="Max New Tokens")
output_audio = gr.Audio(type="numpy", label="Generated Audio")
generate_button = gr.Button("Generate Audio")
generate_button.click(
fn=generate_audio,
inputs=[text_input, temp_slider, top_p_slider, tokens_slider],
outputs=output_audio
)
if __name__ == "__main__":
demo.launch()
```
---
## **Intended Use**
- Designed for high-quality, single-speaker text-to-speech generation.
- Ideal for applications requiring human-like speech synthesis.
- Supports a range of emotions for expressive speech output.
- Suitable for AI voice assistants, storytelling, and accessibility applications. |