Spaces:
Running
on
Zero
Running
on
Zero
AshwinSankar
commited on
Commit
•
6e09c19
1
Parent(s):
7f3b5bd
added demo
Browse files- README.md +6 -6
- app.py +425 -0
- requirements.txt +2 -0
README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
11 |
-
short_description:
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Parler-TTS Streaming
|
3 |
+
emoji: 📝
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.31.5
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
11 |
+
short_description: High-fidelity Text-To-Speech
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,425 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import os
|
3 |
+
import math
|
4 |
+
from queue import Queue
|
5 |
+
from threading import Thread
|
6 |
+
from typing import Optional
|
7 |
+
|
8 |
+
import numpy as np
|
9 |
+
import spaces
|
10 |
+
import gradio as gr
|
11 |
+
import torch
|
12 |
+
|
13 |
+
from parler_tts import ParlerTTSForConditionalGeneration, ParlerTTSStreamer
|
14 |
+
from pydub import AudioSegment
|
15 |
+
from transformers import AutoTokenizer, AutoFeatureExtractor, set_seed
|
16 |
+
|
17 |
+
device = "cuda:0" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
18 |
+
torch_dtype = torch.bfloat16 if device != "cpu" else torch.float32
|
19 |
+
|
20 |
+
repo_id = "ai4bharat/indic-parler-tts-pretrained"
|
21 |
+
jenny_repo_id = "ai4bharat/indic-parler-tts"
|
22 |
+
|
23 |
+
model = ParlerTTSForConditionalGeneration.from_pretrained(
|
24 |
+
repo_id, attn_implementation="eager", torch_dtype=torch_dtype, low_cpu_mem_usage=True
|
25 |
+
).to(device)
|
26 |
+
jenny_model = ParlerTTSForConditionalGeneration.from_pretrained(
|
27 |
+
jenny_repo_id, attn_implementation="eager", torch_dtype=torch_dtype, low_cpu_mem_usage=True
|
28 |
+
).to(device)
|
29 |
+
|
30 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id)
|
31 |
+
description_tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
|
32 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(repo_id)
|
33 |
+
|
34 |
+
SAMPLE_RATE = feature_extractor.sampling_rate
|
35 |
+
SEED = 42
|
36 |
+
|
37 |
+
default_text = "Please surprise me and speak in whatever voice you enjoy."
|
38 |
+
examples = [
|
39 |
+
[
|
40 |
+
"मुले बागेत खेळत आहेत आणि पक्षी किलबिलाट करत आहेत.",
|
41 |
+
"Sunita speaks slowly in a calm, moderate-pitched voice, delivering the news with a neutral tone. The recording is very high quality with no background noise.",
|
42 |
+
3.0
|
43 |
+
],
|
44 |
+
[
|
45 |
+
"ಉದ್ಯಾನದಲ್ಲಿ ಮಕ್ಕಳ ಆಟವಾಡುತ್ತಿದ್ದಾರೆ ಮತ್ತು ಪಕ್ಷಿಗಳು ಚಿಲಿಪಿಲಿ ಮಾಡುತ್ತಿವೆ.",
|
46 |
+
"Suresh speaks slowly in a low-pitched, calm voice, with a neutral tone, perfect for narration. The recording is very high quality with no background noise.",
|
47 |
+
3.0
|
48 |
+
],
|
49 |
+
[
|
50 |
+
"বাচ্চারা বাগানে খেলছে আর পাখি কিচিরমিচির করছে।",
|
51 |
+
"Aditi speaks at a moderate pace and pitch, with a clear, neutral tone and no emotional emphasis. The recording is very high quality with no background noise.",
|
52 |
+
3.0
|
53 |
+
],
|
54 |
+
[
|
55 |
+
"పిల్లలు తోటలో ఆడుకుంటున్నారు, పక్షుల కిలకిలరావాలు.",
|
56 |
+
"Prakash speaks slowly in a low-pitched, calm voice, with a neutral tone, perfect for narration. The recording is very high quality with no background noise.",
|
57 |
+
3.0
|
58 |
+
],
|
59 |
+
[
|
60 |
+
"పిల్లలు తోటలో ఆడుకుంటున్నారు, పక్షుల కిలకిలరావాలు.",
|
61 |
+
"Prakash speaks slowly in a low-pitched, calm voice, with a neutral tone, perfect for narration. The recording is very high quality with no background noise.",
|
62 |
+
3.0
|
63 |
+
],
|
64 |
+
[
|
65 |
+
"This is the best time of my life, Bartley,' she said happily",
|
66 |
+
"A male speaker with a low-pitched voice speaks with a British accent at a fast pace in a small, confined space with very clear audio and an animated tone.",
|
67 |
+
3.0
|
68 |
+
],
|
69 |
+
[
|
70 |
+
"Montrose also, after having experienced still more variety of good and bad fortune, threw down his arms, and retired out of the kingdom.",
|
71 |
+
"A female speaker with a slightly low-pitched, quite monotone voice speaks with an American accent at a slightly faster-than-average pace in a confined space with very clear audio.",
|
72 |
+
3.0
|
73 |
+
],
|
74 |
+
[
|
75 |
+
"बगीचे में बच्चे खेल रहे हैं और पक्षी चहचहा रहे हैं।",
|
76 |
+
"Rohit speaks with a slightly high-pitched voice delivering his words at a slightly slow pace in a small, confined space with a touch of background noise and a quite monotone tone.",
|
77 |
+
3.0
|
78 |
+
],
|
79 |
+
[
|
80 |
+
"കുട്ടികൾ പൂന്തോട്ടത്തിൽ കളിക്കുന്നു, പക്ഷികൾ ചിലയ്ക്കുന്നു.",
|
81 |
+
"Anjali speaks with a low-pitched voice delivering her words at a fast pace and an animated tone, in a very spacious environment, accompanied by noticeable background noise.",
|
82 |
+
3.0
|
83 |
+
],
|
84 |
+
[
|
85 |
+
"குழந்தைகள் தோட்டத்தில் விளையாடுகிறார்கள், பறவைகள் கிண்டல் செய்கின்றன.",
|
86 |
+
"Jaya speaks with a slightly low-pitched, quite monotone voice at a slightly faster-than-average pace in a confined space with very clear audio.",
|
87 |
+
3.0
|
88 |
+
]
|
89 |
+
]
|
90 |
+
|
91 |
+
|
92 |
+
jenny_examples = [
|
93 |
+
[
|
94 |
+
"मुले बागेत खेळत आहेत आणि पक्षी किलबिलाट करत आहेत.",
|
95 |
+
"Sunita speaks slowly in a calm, moderate-pitched voice, delivering the news with a neutral tone. The recording is very high quality with no background noise.",
|
96 |
+
3.0
|
97 |
+
],
|
98 |
+
[
|
99 |
+
"ಉದ್ಯಾನದಲ್ಲಿ ಮಕ್ಕಳ ಆಟವಾಡುತ್ತಿದ್ದಾರೆ ಮತ್ತು ಪಕ್ಷಿಗಳು ಚಿಲಿಪಿಲಿ ಮಾಡುತ್ತಿವೆ.",
|
100 |
+
"Suresh speaks slowly in a low-pitched, calm voice, with a neutral tone, perfect for narration. The recording is very high quality with no background noise.",
|
101 |
+
3.0
|
102 |
+
],
|
103 |
+
[
|
104 |
+
"বাচ্চারা বাগানে খেলছে আর পাখি কিচিরমিচির করছে।",
|
105 |
+
"Aditi speaks at a moderate pace and pitch, with a clear, neutral tone and no emotional emphasis. The recording is very high quality with no background noise.",
|
106 |
+
3.0
|
107 |
+
],
|
108 |
+
[
|
109 |
+
"పిల్లలు తోటలో ఆడుకుంటున్నారు, పక్షుల కిలకిలరావాలు.",
|
110 |
+
"Prakash speaks slowly in a low-pitched, calm voice, with a neutral tone, perfect for narration. The recording is very high quality with no background noise.",
|
111 |
+
3.0
|
112 |
+
],
|
113 |
+
[
|
114 |
+
"పిల్లలు తోటలో ఆడుకుంటున్నారు, పక్షుల కిలకిలరావాలు.",
|
115 |
+
"Prakash speaks slowly in a low-pitched, calm voice, with a neutral tone, perfect for narration. The recording is very high quality with no background noise.",
|
116 |
+
3.0
|
117 |
+
],
|
118 |
+
[
|
119 |
+
"This is the best time of my life, Bartley,' she said happily",
|
120 |
+
"A male speaker with a low-pitched voice speaks with a British accent at a fast pace in a small, confined space with very clear audio and an animated tone.",
|
121 |
+
3.0
|
122 |
+
],
|
123 |
+
[
|
124 |
+
"Montrose also, after having experienced still more variety of good and bad fortune, threw down his arms, and retired out of the kingdom.",
|
125 |
+
"A female speaker with a slightly low-pitched, quite monotone voice speaks with an American accent at a slightly faster-than-average pace in a confined space with very clear audio.",
|
126 |
+
3.0
|
127 |
+
],
|
128 |
+
[
|
129 |
+
"बगीचे में बच्चे खेल रहे हैं और पक्षी चहचहा रहे हैं।",
|
130 |
+
"Rohit speaks with a slightly high-pitched voice delivering his words at a slightly slow pace in a small, confined space with a touch of background noise and a quite monotone tone.",
|
131 |
+
3.0
|
132 |
+
],
|
133 |
+
[
|
134 |
+
"കുട്ടികൾ പൂന്തോട്ടത്തിൽ കളിക്കുന്നു, പക്ഷികൾ ചിലയ്ക്കുന്നു.",
|
135 |
+
"Anjali speaks with a low-pitched voice delivering her words at a fast pace and an animated tone, in a very spacious environment, accompanied by noticeable background noise.",
|
136 |
+
3.0
|
137 |
+
],
|
138 |
+
[
|
139 |
+
"குழந்தைகள் தோட்டத்தில் விளையாடுகிறார்கள், பறவைகள் கிண்டல் செய்கின்றன.",
|
140 |
+
"Jaya speaks with a slightly low-pitched, quite monotone voice at a slightly faster-than-average pace in a confined space with very clear audio.",
|
141 |
+
3.0
|
142 |
+
]
|
143 |
+
]
|
144 |
+
|
145 |
+
|
146 |
+
def numpy_to_mp3(audio_array, sampling_rate):
|
147 |
+
# Normalize audio_array if it's floating-point
|
148 |
+
if np.issubdtype(audio_array.dtype, np.floating):
|
149 |
+
max_val = np.max(np.abs(audio_array))
|
150 |
+
audio_array = (audio_array / max_val) * 32767 # Normalize to 16-bit range
|
151 |
+
audio_array = audio_array.astype(np.int16)
|
152 |
+
|
153 |
+
# Create an audio segment from the numpy array
|
154 |
+
audio_segment = AudioSegment(
|
155 |
+
audio_array.tobytes(),
|
156 |
+
frame_rate=sampling_rate,
|
157 |
+
sample_width=audio_array.dtype.itemsize,
|
158 |
+
channels=1
|
159 |
+
)
|
160 |
+
|
161 |
+
# Export the audio segment to MP3 bytes - use a high bitrate to maximise quality
|
162 |
+
mp3_io = io.BytesIO()
|
163 |
+
audio_segment.export(mp3_io, format="mp3", bitrate="320k")
|
164 |
+
|
165 |
+
# Get the MP3 bytes
|
166 |
+
mp3_bytes = mp3_io.getvalue()
|
167 |
+
mp3_io.close()
|
168 |
+
|
169 |
+
return mp3_bytes
|
170 |
+
|
171 |
+
sampling_rate = model.audio_encoder.config.sampling_rate
|
172 |
+
frame_rate = model.audio_encoder.config.frame_rate
|
173 |
+
|
174 |
+
# @spaces.GPU
|
175 |
+
# def generate_base(text, description, play_steps_in_s=2.0):
|
176 |
+
# play_steps = int(frame_rate * play_steps_in_s)
|
177 |
+
# streamer = ParlerTTSStreamer(model, device=device, play_steps=play_steps)
|
178 |
+
|
179 |
+
# inputs = description_tokenizer(description, return_tensors="pt").to(device)
|
180 |
+
# prompt = tokenizer(text, return_tensors="pt").to(device)
|
181 |
+
|
182 |
+
# generation_kwargs = dict(
|
183 |
+
# input_ids=inputs.input_ids,
|
184 |
+
# prompt_input_ids=prompt.input_ids,
|
185 |
+
# streamer=streamer,
|
186 |
+
# do_sample=True,
|
187 |
+
# temperature=1.0,
|
188 |
+
# min_new_tokens=10,
|
189 |
+
# )
|
190 |
+
|
191 |
+
# set_seed(SEED)
|
192 |
+
# thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
193 |
+
# thread.start()
|
194 |
+
|
195 |
+
# for new_audio in streamer:
|
196 |
+
# print(f"Sample of length: {round(new_audio.shape[0] / sampling_rate, 2)} seconds")
|
197 |
+
# yield numpy_to_mp3(new_audio, sampling_rate=sampling_rate)
|
198 |
+
|
199 |
+
@spaces.GPU
|
200 |
+
def generate_base(text, description, play_steps_in_s=2.0):
|
201 |
+
# Initialize variables
|
202 |
+
play_steps = int(frame_rate * play_steps_in_s)
|
203 |
+
chunk_size = 10 # Process 10 words at a time
|
204 |
+
|
205 |
+
# Tokenize the full text and description
|
206 |
+
inputs = description_tokenizer(description, return_tensors="pt").to(device)
|
207 |
+
|
208 |
+
# Split text into chunks of approximately 10 words
|
209 |
+
words = text.split()
|
210 |
+
chunks = [' '.join(words[i:i + chunk_size]) for i in range(0, len(words), chunk_size)]
|
211 |
+
|
212 |
+
all_audio = []
|
213 |
+
|
214 |
+
# Process each chunk
|
215 |
+
for chunk in chunks:
|
216 |
+
# Tokenize the chunk
|
217 |
+
prompt = tokenizer(chunk, return_tensors="pt").to(device)
|
218 |
+
|
219 |
+
# Generate audio for the chunk
|
220 |
+
generation = model.generate(
|
221 |
+
input_ids=inputs.input_ids,
|
222 |
+
attention_mask=inputs.attention_mask,
|
223 |
+
prompt_input_ids=prompt.input_ids,
|
224 |
+
prompt_attention_mask=prompt.attention_mask,
|
225 |
+
do_sample=True,
|
226 |
+
# temperature=1.0,
|
227 |
+
# min_new_tokens=10,
|
228 |
+
return_dict_in_generate=True
|
229 |
+
)
|
230 |
+
|
231 |
+
# Extract audio from generation
|
232 |
+
if hasattr(generation, 'sequences') and hasattr(generation, 'audios_length'):
|
233 |
+
audio = generation.sequences[0, :generation.audios_length[0]]
|
234 |
+
audio_np = audio.to(torch.float32).cpu().numpy().squeeze()
|
235 |
+
if len(audio_np.shape) > 1:
|
236 |
+
audio_np = audio_np.flatten()
|
237 |
+
all_audio.append(audio_np)
|
238 |
+
|
239 |
+
# Combine all audio chunks
|
240 |
+
combined_audio = np.concatenate(all_audio)
|
241 |
+
|
242 |
+
# Convert to expected format and yield
|
243 |
+
print(f"Sample of length: {round(combined_audio.shape[0] / sampling_rate, 2)} seconds")
|
244 |
+
yield numpy_to_mp3(combined_audio, sampling_rate=sampling_rate)
|
245 |
+
|
246 |
+
# @spaces.GPU
|
247 |
+
# def generate_jenny(text, description, play_steps_in_s=2.0):
|
248 |
+
# play_steps = int(frame_rate * play_steps_in_s)
|
249 |
+
# streamer = ParlerTTSStreamer(jenny_model, device=device, play_steps=play_steps)
|
250 |
+
|
251 |
+
# inputs = description_tokenizer(description, return_tensors="pt").to(device)
|
252 |
+
# prompt = tokenizer(text, return_tensors="pt").to(device)
|
253 |
+
|
254 |
+
# generation_kwargs = dict(
|
255 |
+
# input_ids=inputs.input_ids,
|
256 |
+
# prompt_input_ids=prompt.input_ids,
|
257 |
+
# streamer=streamer,
|
258 |
+
# do_sample=True,
|
259 |
+
# temperature=1.0,
|
260 |
+
# min_new_tokens=10,
|
261 |
+
# )
|
262 |
+
|
263 |
+
# set_seed(SEED)
|
264 |
+
# thread = Thread(target=jenny_model.generate, kwargs=generation_kwargs)
|
265 |
+
# thread.start()
|
266 |
+
|
267 |
+
# for new_audio in streamer:
|
268 |
+
# print(f"Sample of length: {round(new_audio.shape[0] / sampling_rate, 2)} seconds")
|
269 |
+
# yield sampling_rate, new_audio
|
270 |
+
|
271 |
+
@spaces.GPU
|
272 |
+
def generate_jenny(text, description, play_steps_in_s=2.0):
|
273 |
+
# Initialize variables
|
274 |
+
play_steps = int(frame_rate * play_steps_in_s)
|
275 |
+
chunk_size = 10 # Process 10 words at a time
|
276 |
+
|
277 |
+
# Tokenize the full text and description
|
278 |
+
inputs = description_tokenizer(description, return_tensors="pt").to(device)
|
279 |
+
|
280 |
+
# Split text into chunks of approximately 10 words
|
281 |
+
words = text.split()
|
282 |
+
chunks = [' '.join(words[i:i + chunk_size]) for i in range(0, len(words), chunk_size)]
|
283 |
+
|
284 |
+
all_audio = []
|
285 |
+
|
286 |
+
# Process each chunk
|
287 |
+
for chunk in chunks:
|
288 |
+
# Tokenize the chunk
|
289 |
+
prompt = tokenizer(chunk, return_tensors="pt").to(device)
|
290 |
+
|
291 |
+
# Generate audio for the chunk
|
292 |
+
generation = jenny_model.generate(
|
293 |
+
input_ids=inputs.input_ids,
|
294 |
+
attention_mask=inputs.attention_mask,
|
295 |
+
prompt_input_ids=prompt.input_ids,
|
296 |
+
prompt_attention_mask=prompt.attention_mask,
|
297 |
+
do_sample=True,
|
298 |
+
# temperature=1.0,
|
299 |
+
# min_new_tokens=10,
|
300 |
+
return_dict_in_generate=True
|
301 |
+
)
|
302 |
+
|
303 |
+
# Extract audio from generation
|
304 |
+
if hasattr(generation, 'sequences') and hasattr(generation, 'audios_length'):
|
305 |
+
audio = generation.sequences[0, :generation.audios_length[0]]
|
306 |
+
audio_np = audio.to(torch.float32).cpu().numpy().squeeze()
|
307 |
+
if len(audio_np.shape) > 1:
|
308 |
+
audio_np = audio_np.flatten()
|
309 |
+
all_audio.append(audio_np)
|
310 |
+
|
311 |
+
# Combine all audio chunks
|
312 |
+
combined_audio = np.concatenate(all_audio)
|
313 |
+
|
314 |
+
# Convert to expected format and yield
|
315 |
+
print(f"Sample of length: {round(combined_audio.shape[0] / sampling_rate, 2)} seconds")
|
316 |
+
yield numpy_to_mp3(combined_audio, sampling_rate=sampling_rate)
|
317 |
+
|
318 |
+
|
319 |
+
css = """
|
320 |
+
#share-btn-container {
|
321 |
+
display: flex;
|
322 |
+
padding-left: 0.5rem !important;
|
323 |
+
padding-right: 0.5rem !important;
|
324 |
+
background-color: #000000;
|
325 |
+
justify-content: center;
|
326 |
+
align-items: center;
|
327 |
+
border-radius: 9999px !important;
|
328 |
+
width: 13rem;
|
329 |
+
margin-top: 10px;
|
330 |
+
margin-left: auto;
|
331 |
+
flex: unset !important;
|
332 |
+
}
|
333 |
+
#share-btn {
|
334 |
+
all: initial;
|
335 |
+
color: #ffffff;
|
336 |
+
font-weight: 600;
|
337 |
+
cursor: pointer;
|
338 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
339 |
+
margin-left: 0.5rem !important;
|
340 |
+
padding-top: 0.25rem !important;
|
341 |
+
padding-bottom: 0.25rem !important;
|
342 |
+
right:0;
|
343 |
+
}
|
344 |
+
#share-btn * {
|
345 |
+
all: unset !important;
|
346 |
+
}
|
347 |
+
#share-btn-container div:nth-child(-n+2){
|
348 |
+
width: auto !important;
|
349 |
+
min-height: 0px !important;
|
350 |
+
}
|
351 |
+
#share-btn-container .wrap {
|
352 |
+
display: none !important;
|
353 |
+
}
|
354 |
+
"""
|
355 |
+
with gr.Blocks(css=css) as block:
|
356 |
+
gr.HTML(
|
357 |
+
"""
|
358 |
+
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
359 |
+
<div
|
360 |
+
style="
|
361 |
+
display: inline-flex; align-items: center; gap: 0.8rem; font-size: 1.75rem;
|
362 |
+
"
|
363 |
+
>
|
364 |
+
<h1 style="font-weight: 900; margin-bottom: 7px; line-height: normal;">
|
365 |
+
Parler-TTS 🗣️
|
366 |
+
</h1>
|
367 |
+
</div>
|
368 |
+
</div>
|
369 |
+
"""
|
370 |
+
)
|
371 |
+
gr.HTML(
|
372 |
+
f"""
|
373 |
+
<p><a href="https://github.com/huggingface/IndicParlerTTS">IndicParlerTTS</a> is a training and inference library for high-quality text-to-speech (TTS) models. This demonstration highlights the flexibility of the IndicParlerTTS model, which generates natural, expressive speech for over 22 Indian languages, using a simple text prompt to control features like speaker style, tone, pitch, pace, and more.</p>
|
374 |
+
|
375 |
+
<p>Tips for effective usage:
|
376 |
+
<ul>
|
377 |
+
<li>Use detailed captions to describe the speaker and desired characteristics (e.g., "Aditi speaks in a slightly expressive tone, with clear audio quality and a moderate pace.").</li>
|
378 |
+
<li>For best results, reference specific named speakers provided in the model card on the <a href="https://huggingface.co/IndicParlerTTS">model page</a>.</li>
|
379 |
+
<li>Include terms like <b>"very clear audio"</b> or <b>"slightly noisy audio"</b> to control the audio quality and background ambiance.</li>
|
380 |
+
<li>Punctuation can be used to shape prosody (e.g., commas add pauses for natural phrasing).</li>
|
381 |
+
<li>If unsure about what caption to use, you can start with: <b>"The speaker speaks naturally. The recording is very high quality with no background noise."</b></li>
|
382 |
+
</ul>
|
383 |
+
</p>
|
384 |
+
"""
|
385 |
+
)
|
386 |
+
|
387 |
+
with gr.Tab("Finetuned"):
|
388 |
+
with gr.Row():
|
389 |
+
with gr.Column():
|
390 |
+
input_text = gr.Textbox(label="Input Text", lines=2, value=jenny_examples[0][0], elem_id="input_text")
|
391 |
+
description = gr.Textbox(label="Description", lines=2, value=jenny_examples[0][1], elem_id="input_description")
|
392 |
+
play_seconds = gr.Slider(3.0, 7.0, value=jenny_examples[0][2], step=2, label="Streaming interval in seconds", info="Lower = shorter chunks, lower latency, more codec steps")
|
393 |
+
run_button = gr.Button("Generate Audio", variant="primary")
|
394 |
+
with gr.Column():
|
395 |
+
audio_out = gr.Audio(label="Parler-TTS generation", format="mp3", elem_id="audio_out", streaming=True, autoplay=True)
|
396 |
+
|
397 |
+
inputs = [input_text, description, play_seconds]
|
398 |
+
outputs = [audio_out]
|
399 |
+
gr.Examples(examples=jenny_examples, fn=generate_jenny, inputs=inputs, outputs=outputs, cache_examples=False)
|
400 |
+
run_button.click(fn=generate_jenny, inputs=inputs, outputs=outputs, queue=True)
|
401 |
+
|
402 |
+
with gr.Tab("Pretrained"):
|
403 |
+
with gr.Row():
|
404 |
+
with gr.Column():
|
405 |
+
input_text = gr.Textbox(label="Input Text", lines=2, value=default_text, elem_id="input_text")
|
406 |
+
description = gr.Textbox(label="Description", lines=2, value="", elem_id="input_description")
|
407 |
+
play_seconds = gr.Slider(3.0, 7.0, value=3.0, step=2, label="Streaming interval in seconds", info="Lower = shorter chunks, lower latency, more codec steps")
|
408 |
+
run_button = gr.Button("Generate Audio", variant="primary")
|
409 |
+
with gr.Column():
|
410 |
+
audio_out = gr.Audio(label="Parler-TTS generation", format="mp3", elem_id="audio_out", streaming=True, autoplay=True)
|
411 |
+
|
412 |
+
inputs = [input_text, description, play_seconds]
|
413 |
+
outputs = [audio_out]
|
414 |
+
gr.Examples(examples=examples, fn=generate_base, inputs=inputs, outputs=outputs, cache_examples=False)
|
415 |
+
run_button.click(fn=generate_base, inputs=inputs, outputs=outputs, queue=True)
|
416 |
+
|
417 |
+
|
418 |
+
gr.HTML(
|
419 |
+
"""
|
420 |
+
If you'd like to learn more about how the model was trained or explore fine-tuning it yourself, visit the <a href="https://github.com/huggingface/parler-tts">Parler-TTS</a> repository on GitHub. The Parler-TTS codebase and associated checkpoints are licensed under the <a href="https://github.com/huggingface/parler-tts/blob/main/LICENSE">Apache 2.0 license</a>.</p>
|
421 |
+
"""
|
422 |
+
)
|
423 |
+
|
424 |
+
block.queue()
|
425 |
+
block.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
git+https://github.com/huggingface/parler-tts.git
|
2 |
+
accelerate
|