Spaces:
Running
Running
Upload 5 files
Browse files- README.md +11 -7
- app.py +396 -0
- gitattributes +35 -0
- gitignore +0 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
---
|
2 |
-
title: TTS
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
-
pinned:
|
|
|
|
|
|
|
|
|
10 |
---
|
11 |
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Indic Parler-TTS
|
3 |
+
emoji: 👀
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: pink
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.7.1
|
8 |
app_file: app.py
|
9 |
+
pinned: true
|
10 |
+
license: apache-2.0
|
11 |
+
short_description: A demo of Indic Parler-TTS
|
12 |
+
thumbnail: >-
|
13 |
+
https://cdn-uploads.huggingface.co/production/uploads/62611fcabbcbd1c34f1615f6/7v2cvg8cPKrWU0DahrbU_.png
|
14 |
---
|
15 |
|
16 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
import nltk
|
13 |
+
|
14 |
+
|
15 |
+
from parler_tts import ParlerTTSForConditionalGeneration
|
16 |
+
from pydub import AudioSegment
|
17 |
+
from transformers import AutoTokenizer, AutoFeatureExtractor, set_seed
|
18 |
+
|
19 |
+
nltk.download('punkt_tab')
|
20 |
+
|
21 |
+
device = "cuda:0" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
22 |
+
torch_dtype = torch.bfloat16 if device != "cpu" else torch.float32
|
23 |
+
|
24 |
+
repo_id = "ai4bharat/indic-parler-tts-pretrained"
|
25 |
+
finetuned_repo_id = "ai4bharat/indic-parler-tts"
|
26 |
+
|
27 |
+
model = ParlerTTSForConditionalGeneration.from_pretrained(
|
28 |
+
repo_id, attn_implementation="eager", torch_dtype=torch_dtype,
|
29 |
+
).to(device)
|
30 |
+
finetuned_model = ParlerTTSForConditionalGeneration.from_pretrained(
|
31 |
+
finetuned_repo_id, attn_implementation="eager", torch_dtype=torch_dtype,
|
32 |
+
).to(device)
|
33 |
+
|
34 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id)
|
35 |
+
description_tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
|
36 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(repo_id)
|
37 |
+
|
38 |
+
SAMPLE_RATE = feature_extractor.sampling_rate
|
39 |
+
SEED = 42
|
40 |
+
|
41 |
+
default_text = "Please surprise me and speak in whatever voice you enjoy."
|
42 |
+
examples = [
|
43 |
+
[
|
44 |
+
"मुले बागेत खेळत आहेत आणि पक्षी किलबिलाट करत आहेत.",
|
45 |
+
"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.",
|
46 |
+
3.0
|
47 |
+
],
|
48 |
+
[
|
49 |
+
"ಉದ್ಯಾನದಲ್ಲಿ ಮಕ್ಕಳ ಆಟವಾಡುತ್ತಿದ್ದಾರೆ ಮತ್ತು ಪಕ್ಷಿಗಳು ಚಿಲಿಪಿಲಿ ಮಾಡುತ್ತಿವೆ.",
|
50 |
+
"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.",
|
51 |
+
3.0
|
52 |
+
],
|
53 |
+
[
|
54 |
+
"বাচ্চারা বাগানে খেলছে আর পাখি কিচিরমিচির করছে।",
|
55 |
+
"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.",
|
56 |
+
3.0
|
57 |
+
],
|
58 |
+
[
|
59 |
+
"పిల్లలు తోటలో ఆడుకుంటున్నారు, పక్షుల కిలకిలరావాలు.",
|
60 |
+
"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.",
|
61 |
+
3.0
|
62 |
+
],
|
63 |
+
[
|
64 |
+
"పిల్లలు తోటలో ఆడుకుంటున్నారు, పక్షుల కిలకిలరావాలు.",
|
65 |
+
"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.",
|
66 |
+
3.0
|
67 |
+
],
|
68 |
+
[
|
69 |
+
"This is the best time of my life, Bartley,' she said happily",
|
70 |
+
"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.",
|
71 |
+
3.0
|
72 |
+
],
|
73 |
+
[
|
74 |
+
"Montrose also, after having experienced still more variety of good and bad fortune, threw down his arms, and retired out of the kingdom.",
|
75 |
+
"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.",
|
76 |
+
3.0
|
77 |
+
],
|
78 |
+
[
|
79 |
+
"बगीचे में बच्चे खेल रहे हैं और पक्षी चहचहा रहे हैं।",
|
80 |
+
"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.",
|
81 |
+
3.0
|
82 |
+
],
|
83 |
+
[
|
84 |
+
"കുട്ടികൾ പൂന്തോട്ടത്തിൽ കളിക്കുന്നു, പക്ഷികൾ ചിലയ്ക്കുന്നു.",
|
85 |
+
"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.",
|
86 |
+
3.0
|
87 |
+
],
|
88 |
+
[
|
89 |
+
"குழந்தைகள் தோட்டத்தில் விளையாடுகிறார்கள், பறவைகள் கிண்டல் செய்கின்றன.",
|
90 |
+
"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.",
|
91 |
+
3.0
|
92 |
+
]
|
93 |
+
]
|
94 |
+
|
95 |
+
|
96 |
+
finetuned_examples = [
|
97 |
+
[
|
98 |
+
"मुले बागेत खेळत आहेत आणि पक्षी किलबिलाट करत आहेत.",
|
99 |
+
"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.",
|
100 |
+
3.0
|
101 |
+
],
|
102 |
+
[
|
103 |
+
"ಉದ್ಯಾನದಲ್ಲಿ ಮಕ್ಕಳ ಆಟವಾಡುತ್ತಿದ್ದಾರೆ ಮತ್ತು ಪಕ್ಷಿಗಳು ಚಿಲಿಪಿಲಿ ಮಾಡುತ್ತಿವೆ.",
|
104 |
+
"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.",
|
105 |
+
3.0
|
106 |
+
],
|
107 |
+
[
|
108 |
+
"বাচ্চারা বাগানে খেলছে আর পাখি কিচিরমিচির করছে।",
|
109 |
+
"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.",
|
110 |
+
3.0
|
111 |
+
],
|
112 |
+
[
|
113 |
+
"పిల్లలు తోటలో ఆడుకుంటున్నారు, పక్షుల కిలకిలరావాలు.",
|
114 |
+
"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.",
|
115 |
+
3.0
|
116 |
+
],
|
117 |
+
[
|
118 |
+
"పిల్లలు తోటలో ఆడుకుంటున్నారు, పక్షుల కిలకిలరావాలు.",
|
119 |
+
"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.",
|
120 |
+
3.0
|
121 |
+
],
|
122 |
+
[
|
123 |
+
"This is the best time of my life, Bartley,' she said happily",
|
124 |
+
"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.",
|
125 |
+
3.0
|
126 |
+
],
|
127 |
+
[
|
128 |
+
"Montrose also, after having experienced still more variety of good and bad fortune, threw down his arms, and retired out of the kingdom.",
|
129 |
+
"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.",
|
130 |
+
3.0
|
131 |
+
],
|
132 |
+
[
|
133 |
+
"बगीचे में बच्चे खेल रहे हैं और पक्षी चहचहा रहे हैं।",
|
134 |
+
"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.",
|
135 |
+
3.0
|
136 |
+
],
|
137 |
+
[
|
138 |
+
"കുട്ടികൾ പൂന്തോട്ടത്തിൽ കളിക്കുന്നു, പക്ഷികൾ ചിലയ്ക്കുന്നു.",
|
139 |
+
"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.",
|
140 |
+
3.0
|
141 |
+
],
|
142 |
+
[
|
143 |
+
"குழந்தைகள் தோட்டத்தில் விளையாடுகிறார்கள், பறவைகள் கிண்டல் செய்கின்றன.",
|
144 |
+
"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.",
|
145 |
+
3.0
|
146 |
+
]
|
147 |
+
]
|
148 |
+
|
149 |
+
|
150 |
+
def numpy_to_mp3(audio_array, sampling_rate):
|
151 |
+
# Normalize audio_array if it's floating-point
|
152 |
+
if np.issubdtype(audio_array.dtype, np.floating):
|
153 |
+
max_val = np.max(np.abs(audio_array))
|
154 |
+
audio_array = (audio_array / max_val) * 32767 # Normalize to 16-bit range
|
155 |
+
audio_array = audio_array.astype(np.int16)
|
156 |
+
|
157 |
+
# Create an audio segment from the numpy array
|
158 |
+
audio_segment = AudioSegment(
|
159 |
+
audio_array.tobytes(),
|
160 |
+
frame_rate=sampling_rate,
|
161 |
+
sample_width=audio_array.dtype.itemsize,
|
162 |
+
channels=1
|
163 |
+
)
|
164 |
+
|
165 |
+
# Export the audio segment to MP3 bytes - use a high bitrate to maximise quality
|
166 |
+
mp3_io = io.BytesIO()
|
167 |
+
audio_segment.export(mp3_io, format="mp3", bitrate="320k")
|
168 |
+
|
169 |
+
# Get the MP3 bytes
|
170 |
+
mp3_bytes = mp3_io.getvalue()
|
171 |
+
mp3_io.close()
|
172 |
+
|
173 |
+
return mp3_bytes
|
174 |
+
|
175 |
+
sampling_rate = model.audio_encoder.config.sampling_rate
|
176 |
+
frame_rate = model.audio_encoder.config.frame_rate
|
177 |
+
|
178 |
+
@spaces.GPU
|
179 |
+
def generate_base(text, description,):
|
180 |
+
# Initialize variables
|
181 |
+
chunk_size = 25 # Process max 25 words or a sentence at a time
|
182 |
+
|
183 |
+
# Tokenize the full text and description
|
184 |
+
inputs = description_tokenizer(description, return_tensors="pt").to(device)
|
185 |
+
|
186 |
+
sentences_text = nltk.sent_tokenize(text) # this gives us a list of sentences
|
187 |
+
curr_sentence = ""
|
188 |
+
chunks = []
|
189 |
+
for sentence in sentences_text:
|
190 |
+
candidate = " ".join([curr_sentence, sentence])
|
191 |
+
if len(candidate.split()) >= chunk_size:
|
192 |
+
chunks.append(curr_sentence)
|
193 |
+
curr_sentence = sentence
|
194 |
+
else:
|
195 |
+
curr_sentence = candidate
|
196 |
+
|
197 |
+
if curr_sentence != "":
|
198 |
+
chunks.append(curr_sentence)
|
199 |
+
|
200 |
+
print(chunks)
|
201 |
+
|
202 |
+
all_audio = []
|
203 |
+
|
204 |
+
# Process each chunk
|
205 |
+
for chunk in chunks:
|
206 |
+
# Tokenize the chunk
|
207 |
+
prompt = tokenizer(chunk, return_tensors="pt").to(device)
|
208 |
+
|
209 |
+
# Generate audio for the chunk
|
210 |
+
generation = model.generate(
|
211 |
+
input_ids=inputs.input_ids,
|
212 |
+
attention_mask=inputs.attention_mask,
|
213 |
+
prompt_input_ids=prompt.input_ids,
|
214 |
+
prompt_attention_mask=prompt.attention_mask,
|
215 |
+
do_sample=True,
|
216 |
+
return_dict_in_generate=True
|
217 |
+
)
|
218 |
+
|
219 |
+
# Extract audio from generation
|
220 |
+
if hasattr(generation, 'sequences') and hasattr(generation, 'audios_length'):
|
221 |
+
audio = generation.sequences[0, :generation.audios_length[0]]
|
222 |
+
audio_np = audio.to(torch.float32).cpu().numpy().squeeze()
|
223 |
+
if len(audio_np.shape) > 1:
|
224 |
+
audio_np = audio_np.flatten()
|
225 |
+
all_audio.append(audio_np)
|
226 |
+
|
227 |
+
# Combine all audio chunks
|
228 |
+
combined_audio = np.concatenate(all_audio)
|
229 |
+
|
230 |
+
# Convert to expected format and yield
|
231 |
+
print(f"Sample of length: {round(combined_audio.shape[0] / sampling_rate, 2)} seconds")
|
232 |
+
yield numpy_to_mp3(combined_audio, sampling_rate=sampling_rate)
|
233 |
+
|
234 |
+
|
235 |
+
@spaces.GPU
|
236 |
+
def generate_finetuned(text, description):
|
237 |
+
# Initialize variables
|
238 |
+
chunk_size = 25 # Process max 25 words or a sentence at a time
|
239 |
+
|
240 |
+
# Tokenize the full text and description
|
241 |
+
inputs = description_tokenizer(description, return_tensors="pt").to(device)
|
242 |
+
|
243 |
+
sentences_text = nltk.sent_tokenize(text) # this gives us a list of sentences
|
244 |
+
curr_sentence = ""
|
245 |
+
chunks = []
|
246 |
+
for sentence in sentences_text:
|
247 |
+
candidate = " ".join([curr_sentence, sentence])
|
248 |
+
if len(candidate.split()) >= chunk_size:
|
249 |
+
chunks.append(curr_sentence)
|
250 |
+
curr_sentence = sentence
|
251 |
+
else:
|
252 |
+
curr_sentence = candidate
|
253 |
+
|
254 |
+
if curr_sentence != "":
|
255 |
+
chunks.append(curr_sentence)
|
256 |
+
|
257 |
+
print(chunks)
|
258 |
+
|
259 |
+
all_audio = []
|
260 |
+
|
261 |
+
# Process each chunk
|
262 |
+
for chunk in chunks:
|
263 |
+
# Tokenize the chunk
|
264 |
+
prompt = tokenizer(chunk, return_tensors="pt").to(device)
|
265 |
+
|
266 |
+
# Generate audio for the chunk
|
267 |
+
generation = finetuned_model.generate(
|
268 |
+
input_ids=inputs.input_ids,
|
269 |
+
attention_mask=inputs.attention_mask,
|
270 |
+
prompt_input_ids=prompt.input_ids,
|
271 |
+
prompt_attention_mask=prompt.attention_mask,
|
272 |
+
do_sample=True,
|
273 |
+
return_dict_in_generate=True
|
274 |
+
)
|
275 |
+
|
276 |
+
# Extract audio from generation
|
277 |
+
if hasattr(generation, 'sequences') and hasattr(generation, 'audios_length'):
|
278 |
+
audio = generation.sequences[0, :generation.audios_length[0]]
|
279 |
+
audio_np = audio.to(torch.float32).cpu().numpy().squeeze()
|
280 |
+
if len(audio_np.shape) > 1:
|
281 |
+
audio_np = audio_np.flatten()
|
282 |
+
all_audio.append(audio_np)
|
283 |
+
|
284 |
+
# Combine all audio chunks
|
285 |
+
combined_audio = np.concatenate(all_audio)
|
286 |
+
|
287 |
+
# Convert to expected format and yield
|
288 |
+
print(f"Sample of length: {round(combined_audio.shape[0] / sampling_rate, 2)} seconds")
|
289 |
+
yield numpy_to_mp3(combined_audio, sampling_rate=sampling_rate)
|
290 |
+
|
291 |
+
|
292 |
+
css = """
|
293 |
+
#share-btn-container {
|
294 |
+
display: flex;
|
295 |
+
padding-left: 0.5rem !important;
|
296 |
+
padding-right: 0.5rem !important;
|
297 |
+
background-color: #000000;
|
298 |
+
justify-content: center;
|
299 |
+
align-items: center;
|
300 |
+
border-radius: 9999px !important;
|
301 |
+
width: 13rem;
|
302 |
+
margin-top: 10px;
|
303 |
+
margin-left: auto;
|
304 |
+
flex: unset !important;
|
305 |
+
}
|
306 |
+
#share-btn {
|
307 |
+
all: initial;
|
308 |
+
color: #ffffff;
|
309 |
+
font-weight: 600;
|
310 |
+
cursor: pointer;
|
311 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
312 |
+
margin-left: 0.5rem !important;
|
313 |
+
padding-top: 0.25rem !important;
|
314 |
+
padding-bottom: 0.25rem !important;
|
315 |
+
right:0;
|
316 |
+
}
|
317 |
+
#share-btn * {
|
318 |
+
all: unset !important;
|
319 |
+
}
|
320 |
+
#share-btn-container div:nth-child(-n+2){
|
321 |
+
width: auto !important;
|
322 |
+
min-height: 0px !important;
|
323 |
+
}
|
324 |
+
#share-btn-container .wrap {
|
325 |
+
display: none !important;
|
326 |
+
}
|
327 |
+
"""
|
328 |
+
with gr.Blocks(css=css) as block:
|
329 |
+
gr.HTML(
|
330 |
+
"""
|
331 |
+
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
332 |
+
<div
|
333 |
+
style="
|
334 |
+
display: inline-flex; align-items: center; gap: 0.8rem; font-size: 1.75rem;
|
335 |
+
"
|
336 |
+
>
|
337 |
+
<h1 style="font-weight: 900; margin-bottom: 7px; line-height: normal;">
|
338 |
+
Parler-TTS 🗣️
|
339 |
+
</h1>
|
340 |
+
</div>
|
341 |
+
</div>
|
342 |
+
"""
|
343 |
+
)
|
344 |
+
gr.HTML(
|
345 |
+
f"""
|
346 |
+
<p><a href="https://github.com/huggingface/Parler-TTS">ParlerTTS</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>
|
347 |
+
|
348 |
+
<p>Tips for effective usage:
|
349 |
+
<ul>
|
350 |
+
<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>
|
351 |
+
<li>For best results, reference specific named speakers provided in the model card on the <a href="https://huggingface.co/ai4bharat/indic-parler-tts#%F0%9F%8E%AF-using-a-specific-speaker">model page</a>.</li>
|
352 |
+
<li>Include terms like <b>"very clear audio"</b> or <b>"slightly noisy audio"</b> to control the audio quality and background ambiance.</li>
|
353 |
+
<li>Punctuation can be used to shape prosody (e.g., commas add pauses for natural phrasing).</li>
|
354 |
+
<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>
|
355 |
+
</ul>
|
356 |
+
</p>
|
357 |
+
"""
|
358 |
+
)
|
359 |
+
|
360 |
+
with gr.Tab("Finetuned"):
|
361 |
+
with gr.Row():
|
362 |
+
with gr.Column():
|
363 |
+
input_text = gr.Textbox(label="Input Text", lines=2, value=finetuned_examples[0][0], elem_id="input_text")
|
364 |
+
description = gr.Textbox(label="Description", lines=2, value=finetuned_examples[0][1], elem_id="input_description")
|
365 |
+
run_button = gr.Button("Generate Audio", variant="primary")
|
366 |
+
with gr.Column():
|
367 |
+
audio_out = gr.Audio(label="Parler-TTS generation", format="mp3", elem_id="audio_out", autoplay=True)
|
368 |
+
|
369 |
+
inputs = [input_text, description]
|
370 |
+
outputs = [audio_out]
|
371 |
+
gr.Examples(examples=finetuned_examples, fn=generate_finetuned, inputs=inputs, outputs=outputs, cache_examples=False)
|
372 |
+
run_button.click(fn=generate_finetuned, inputs=inputs, outputs=outputs, queue=True)
|
373 |
+
|
374 |
+
with gr.Tab("Pretrained"):
|
375 |
+
with gr.Row():
|
376 |
+
with gr.Column():
|
377 |
+
input_text = gr.Textbox(label="Input Text", lines=2, value=default_text, elem_id="input_text")
|
378 |
+
description = gr.Textbox(label="Description", lines=2, value="", elem_id="input_description")
|
379 |
+
run_button = gr.Button("Generate Audio", variant="primary")
|
380 |
+
with gr.Column():
|
381 |
+
audio_out = gr.Audio(label="Parler-TTS generation", format="mp3", elem_id="audio_out", autoplay=True)
|
382 |
+
|
383 |
+
inputs = [input_text, description]
|
384 |
+
outputs = [audio_out]
|
385 |
+
gr.Examples(examples=examples, fn=generate_base, inputs=inputs, outputs=outputs, cache_examples=False)
|
386 |
+
run_button.click(fn=generate_base, inputs=inputs, outputs=outputs, queue=True)
|
387 |
+
|
388 |
+
|
389 |
+
gr.HTML(
|
390 |
+
"""
|
391 |
+
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>
|
392 |
+
"""
|
393 |
+
)
|
394 |
+
|
395 |
+
block.queue()
|
396 |
+
block.launch(share=True)
|
gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
gitignore
ADDED
File without changes
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
spaces
|
3 |
+
git+https://github.com/huggingface/parler-tts.git
|
4 |
+
nltk
|