Offex commited on
Commit
ef89a6f
·
verified ·
1 Parent(s): c34d857

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +136 -18
index.html CHANGED
@@ -1,19 +1,137 @@
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>11Labs Safe TTS Tool</title>
7
+ <style>
8
+ body { font-family: Arial, sans-serif; max-width: 600px; margin: 40px auto; padding: 20px; background-color: #f4f4f9; }
9
+ .container { background: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
10
+ h2 { text-align: center; color: #333; }
11
+ label { font-weight: bold; display: block; margin-top: 10px; }
12
+ input, textarea, select { width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; }
13
+ button { width: 100%; background-color: #28a745; color: white; padding: 12px; border: none; border-radius: 5px; margin-top: 15px; cursor: pointer; font-size: 16px; font-weight: bold; transition: 0.3s; }
14
+ button:disabled { background-color: #6c757d; cursor: not-allowed; }
15
+ button:hover:not(:disabled) { background-color: #218838; }
16
+
17
+ #audioContainer { margin-top: 20px; text-align: center; display: none; padding: 15px; background: #e9ecef; border-radius: 8px; }
18
+
19
+ /* Status Box Styling */
20
+ .status-box { text-align: center; margin-top: 15px; padding: 10px; border-radius: 5px; font-weight: bold; display: none; transition: 0.3s; }
21
+ .status-loading { background-color: #fff3cd; color: #856404; display: block; }
22
+ .status-success { background-color: #d4edda; color: #155724; display: block; }
23
+ .status-error { background-color: #f8d7da; color: #721c24; display: block; }
24
+ </style>
25
+ </head>
26
+ <body>
27
+
28
+ <div class="container">
29
+ <h2>11Labs Safe TTS (No IP Block)</h2>
30
+
31
+ <label for="apiKey">ElevenLabs API Key:</label>
32
+ <input type="password" id="apiKey" placeholder="Apni API key yahan daalein..." required>
33
+
34
+ <label for="voiceId">Voice ID:</label>
35
+ <input type="text" id="voiceId" value="EXAVITQu4vr4xnSDxMaL" placeholder="Voice ID (e.g., Bella)">
36
+
37
+ <label for="modelSelect">Select Model:</label>
38
+ <select id="modelSelect">
39
+ <option value="eleven_multilingual_v2">Multilingual v2 (Best for most)</option>
40
+ <option value="eleven_multilingual_v1">Multilingual v1</option>
41
+ <option value="eleven_monolingual_v1">Monolingual v1 (English only)</option>
42
+ </select>
43
+
44
+ <label for="text">Text to Speech:</label>
45
+ <textarea id="text" rows="5" placeholder="Jo bulwana hai yahan type karein..." required></textarea>
46
+
47
+ <button onclick="generateAudio()" id="generateBtn">Generate Audio</button>
48
+
49
+ <div id="statusBox" class="status-box"></div>
50
+
51
+ <div id="audioContainer">
52
+ <audio id="audioPlayer" controls style="width: 100%;"></audio>
53
+ <br><br>
54
+ <a id="downloadLink" download="generated_audio.mp3" style="text-decoration: none; background: #007bff; color: white; padding: 10px 20px; border-radius: 5px; display: inline-block;">Download MP3</a>
55
+ </div>
56
+ </div>
57
+
58
+ <script>
59
+ async function generateAudio() {
60
+ const apiKey = document.getElementById('apiKey').value.trim();
61
+ const voiceId = document.getElementById('voiceId').value.trim();
62
+ const modelId = document.getElementById('modelSelect').value;
63
+ const text = document.getElementById('text').value.trim();
64
+
65
+ const statusBox = document.getElementById('statusBox');
66
+ const audioContainer = document.getElementById('audioContainer');
67
+ const audioPlayer = document.getElementById('audioPlayer');
68
+ const downloadLink = document.getElementById('downloadLink');
69
+ const generateBtn = document.getElementById('generateBtn');
70
+
71
+ // Validation
72
+ if (!apiKey || !text || !voiceId) {
73
+ showStatus('Bhai, pehle API Key, Voice ID aur Text dalo!', 'error');
74
+ return;
75
+ }
76
+
77
+ // Reset UI for new request
78
+ audioContainer.style.display = "none";
79
+ showStatus('Audio generate ho raha hai, thoda wait karo... ⏳', 'loading');
80
+ generateBtn.disabled = true;
81
+ generateBtn.innerText = "Processing...";
82
+
83
+ try {
84
+ const response = await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`, {
85
+ method: 'POST',
86
+ headers: {
87
+ 'Accept': 'audio/mpeg',
88
+ 'xi-api-key': apiKey,
89
+ 'Content-Type': 'application/json'
90
+ },
91
+ body: JSON.stringify({
92
+ text: text,
93
+ model_id: modelId,
94
+ voice_settings: {
95
+ stability: 0.5,
96
+ similarity_boost: 0.5
97
+ }
98
+ })
99
+ });
100
+
101
+ if (!response.ok) {
102
+ const errData = await response.json();
103
+ throw new Error(errData.detail.message || "API request fail ho gayi!");
104
+ }
105
+
106
+ const blob = await response.blob();
107
+ const audioUrl = URL.createObjectURL(blob);
108
+
109
+ // Set audio URL to player and download link
110
+ audioPlayer.src = audioUrl;
111
+ downloadLink.href = audioUrl;
112
+ audioContainer.style.display = "block";
113
+
114
+ showStatus('Audio Ready! Ab play karo ya download karo 🎉', 'success');
115
+
116
+ } catch (error) {
117
+ showStatus('Error: ' + error.message, 'error');
118
+ } finally {
119
+ generateBtn.disabled = false;
120
+ generateBtn.innerText = "Generate Audio";
121
+ }
122
+ }
123
+
124
+ // Status dikhane ka function
125
+ function showStatus(message, type) {
126
+ const statusBox = document.getElementById('statusBox');
127
+ statusBox.innerText = message;
128
+ statusBox.className = 'status-box'; // Purani classes hatane ke liye
129
+
130
+ if(type === 'loading') statusBox.classList.add('status-loading');
131
+ if(type === 'success') statusBox.classList.add('status-success');
132
+ if(type === 'error') statusBox.classList.add('status-error');
133
+ }
134
+ </script>
135
+
136
+ </body>
137
  </html>