kshvchvr commited on
Commit
0a34cf8
·
1 Parent(s): d8cfcc3

Add Indic TTS frontend

Browse files
Files changed (2) hide show
  1. README.md +11 -6
  2. index.html +236 -18
README.md CHANGED
@@ -1,10 +1,15 @@
1
  ---
2
- title: Indic Tts
3
- emoji: 😻
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: static
7
- pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
  ---
2
+ title: Indic TTS Swadesh
3
+ emoji: 🇮🇳
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: static
7
+ pinned: true
8
+ license: apache-2.0
9
  ---
10
 
11
+ # Indic TTS Swadesh
12
+
13
+ Free Indian Language Text-to-Speech — 21 languages, native speakers.
14
+
15
+ Powered by [AI4Bharat Indic Parler-TTS](https://huggingface.co/spaces/ai4bharat/indic-parler-tts).
index.html CHANGED
@@ -1,19 +1,237 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Indic TTS — Swadesh</title>
7
+ <style>
8
+ * { margin: 0; padding: 0; box-sizing: border-box; }
9
+ body {
10
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
11
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
12
+ min-height: 100vh;
13
+ display: flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ padding: 20px;
17
+ }
18
+ .container {
19
+ background: white;
20
+ border-radius: 16px;
21
+ padding: 32px;
22
+ max-width: 600px;
23
+ width: 100%;
24
+ box-shadow: 0 20px 60px rgba(0,0,0,0.3);
25
+ }
26
+ h1 {
27
+ text-align: center;
28
+ margin-bottom: 8px;
29
+ color: #333;
30
+ font-size: 1.6em;
31
+ }
32
+ .subtitle {
33
+ text-align: center;
34
+ color: #888;
35
+ margin-bottom: 24px;
36
+ font-size: 0.9em;
37
+ }
38
+ label {
39
+ display: block;
40
+ margin-bottom: 6px;
41
+ font-weight: 600;
42
+ color: #555;
43
+ font-size: 0.9em;
44
+ }
45
+ textarea {
46
+ width: 100%;
47
+ padding: 12px;
48
+ border: 2px solid #e0e0e0;
49
+ border-radius: 8px;
50
+ font-size: 16px;
51
+ resize: vertical;
52
+ min-height: 100px;
53
+ font-family: inherit;
54
+ transition: border-color 0.2s;
55
+ }
56
+ textarea:focus { outline: none; border-color: #667eea; }
57
+ select {
58
+ width: 100%;
59
+ padding: 12px;
60
+ border: 2px solid #e0e0e0;
61
+ border-radius: 8px;
62
+ font-size: 16px;
63
+ background: white;
64
+ cursor: pointer;
65
+ margin-bottom: 20px;
66
+ }
67
+ select:focus { outline: none; border-color: #667eea; }
68
+ .btn {
69
+ width: 100%;
70
+ padding: 14px;
71
+ background: linear-gradient(135deg, #667eea, #764ba2);
72
+ color: white;
73
+ border: none;
74
+ border-radius: 8px;
75
+ font-size: 16px;
76
+ font-weight: 600;
77
+ cursor: pointer;
78
+ transition: opacity 0.2s;
79
+ }
80
+ .btn:hover { opacity: 0.9; }
81
+ .btn:disabled { opacity: 0.5; cursor: not-allowed; }
82
+ .status {
83
+ margin-top: 16px;
84
+ padding: 12px;
85
+ border-radius: 8px;
86
+ text-align: center;
87
+ font-size: 0.9em;
88
+ display: none;
89
+ }
90
+ .status.loading { display: block; background: #fff3cd; color: #856404; }
91
+ .status.error { display: block; background: #f8d7da; color: #721c24; }
92
+ .status.success { display: block; background: #d4edda; color: #155724; }
93
+ audio {
94
+ width: 100%;
95
+ margin-top: 16px;
96
+ display: none;
97
+ }
98
+ .footer {
99
+ text-align: center;
100
+ margin-top: 20px;
101
+ color: #aaa;
102
+ font-size: 0.8em;
103
+ }
104
+ </style>
105
+ </head>
106
+ <body>
107
+ <div class="container">
108
+ <h1>Indic TTS — Swadesh</h1>
109
+ <p class="subtitle">21 Indian Languages — AI4Bharat Model</p>
110
+
111
+ <label for="text">Text</label>
112
+ <textarea id="text" placeholder="Type text here... / yahan text likhein..."></textarea>
113
+
114
+ <label for="lang">Language</label>
115
+ <select id="lang">
116
+ <option value="hi">Hindi</option>
117
+ <option value="bn">Bengali</option>
118
+ <option value="ta">Tamil</option>
119
+ <option value="te">Telugu</option>
120
+ <option value="mr">Marathi</option>
121
+ <option value="kn">Kannada</option>
122
+ <option value="ml">Malayalam</option>
123
+ <option value="gu">Gujarati</option>
124
+ <option value="or">Odia</option>
125
+ <option value="ur">Urdu</option>
126
+ <option value="en">English</option>
127
+ <option value="as">Assamese</option>
128
+ <option value="ne">Nepali</option>
129
+ <option value="sa">Sanskrit</option>
130
+ <option value="mai">Maithili</option>
131
+ <option value="brx">Bodo</option>
132
+ <option value="doi">Dogri</option>
133
+ <option value="kok">Konkani</option>
134
+ <option value="mni">Manipuri</option>
135
+ <option value="sat">Santali</option>
136
+ <option value="sd">Sindhi</option>
137
+ </select>
138
+
139
+ <button class="btn" id="btn" onclick="generate()">Generate Speech</button>
140
+
141
+ <div class="status" id="status"></div>
142
+ <audio id="audio" controls></audio>
143
+
144
+ <p class="footer">Powered by <a href="https://huggingface.co/spaces/ai4bharat/indic-parler-tts" target="_blank">AI4Bharat Indic Parler-TTS</a></p>
145
+ </div>
146
+
147
+ <script type="module">
148
+ import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";
149
+
150
+ const LANG_NAMES = {
151
+ as:"Assamese", bn:"Bengali", brx:"Bodo", doi:"Dogri",
152
+ en:"English", gu:"Gujarati", hi:"Hindi", kn:"Kannada",
153
+ kok:"Konkani", mai:"Maithili", ml:"Malayalam", mni:"Manipuri",
154
+ mr:"Marathi", ne:"Nepali", or:"Odia", sa:"Sanskrit",
155
+ sat:"Santali", sd:"Sindhi", ta:"Tamil", te:"Telugu", ur:"Urdu"
156
+ };
157
+ const SPEAKER_NAMES = {
158
+ as:"Sita", bn:"Aditi", brx:"Maya", doi:"Karan",
159
+ en:"Mary", gu:"Neha", hi:"Divya", kn:"Anu",
160
+ kok:"Sita", mai:"Sita", ml:"Anjali", mni:"Laishram",
161
+ mr:"Sunita", ne:"Amrita", or:"Debjani", sa:"Aryan",
162
+ sat:"Sita", sd:"Sita", ta:"Jaya", te:"Lalitha", ur:"Sita"
163
+ };
164
+
165
+ let client = null;
166
+
167
+ async function getClient() {
168
+ if (!client) {
169
+ const status = document.getElementById("status");
170
+ status.className = "status loading";
171
+ status.textContent = "Connecting to AI4Bharat server...";
172
+ status.style.display = "block";
173
+ client = await Client.connect("ai4bharat/indic-parler-tts");
174
+ status.style.display = "none";
175
+ }
176
+ return client;
177
+ }
178
+
179
+ window.generate = async function() {
180
+ const text = document.getElementById("text").value.trim();
181
+ const lang = document.getElementById("lang").value;
182
+ const btn = document.getElementById("btn");
183
+ const status = document.getElementById("status");
184
+ const audio = document.getElementById("audio");
185
+
186
+ if (!text) {
187
+ status.className = "status error";
188
+ status.textContent = "Please enter some text.";
189
+ status.style.display = "block";
190
+ return;
191
+ }
192
+
193
+ btn.disabled = true;
194
+ btn.textContent = "Generating...";
195
+ audio.style.display = "none";
196
+ status.className = "status loading";
197
+ status.textContent = "Loading model & generating speech... This may take 30-60 seconds on first use.";
198
+ status.style.display = "block";
199
+
200
+ try {
201
+ const c = await getClient();
202
+ const speaker = SPEAKER_NAMES[lang] || "Divya";
203
+ const langName = LANG_NAMES[lang] || "Hindi";
204
+ const description = speaker + " speaks " + langName + " fluently with a native accent. Her voice is clear, warm, and expressive, with a moderate pace and pitch, using a friendly storytelling tone suited for children. The recording is of very high quality, with the speaker's voice sounding close up and easy to understand, in a quiet room with no background noise.";
205
+
206
+ const result = await c.predict("/generate_tts", [text, description]);
207
+
208
+ if (result.data && result.data[0]) {
209
+ const audioData = result.data[0];
210
+ let audioUrl;
211
+ if (typeof audioData === "object" && audioData.url) {
212
+ audioUrl = audioData.url;
213
+ } else if (typeof audioData === "string") {
214
+ audioUrl = audioData;
215
+ } else {
216
+ audioUrl = URL.createObjectURL(new Blob([new Uint8Array(audioData)], { type: "audio/wav" }));
217
+ }
218
+ audio.src = audioUrl;
219
+ audio.style.display = "block";
220
+ audio.play();
221
+ status.className = "status success";
222
+ status.textContent = "Audio generated successfully!";
223
+ } else {
224
+ throw new Error("No audio data received");
225
+ }
226
+ } catch (err) {
227
+ status.className = "status error";
228
+ status.textContent = "Error: " + err.message + ". The AI4Bharat server may be temporarily down. Try again later.";
229
+ console.error(err);
230
+ } finally {
231
+ btn.disabled = false;
232
+ btn.textContent = "Generate Speech";
233
+ }
234
+ };
235
+ </script>
236
+ </body>
237
  </html>