File size: 5,920 Bytes
d87d634
3329aef
d87d634
 
 
3329aef
d87d634
 
 
 
 
 
45da436
 
d87d634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec72951
d87d634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3329aef
 
d87d634
 
ec72951
d87d634
 
 
 
 
 
3329aef
d87d634
 
 
 
 
 
 
3329aef
d87d634
 
 
 
 
 
 
 
 
 
 
 
 
 
3329aef
 
d87d634
 
ec72951
d87d634
 
 
ec72951
d87d634
 
 
 
 
 
 
 
 
 
 
 
3329aef
d87d634
 
 
 
 
 
 
 
 
 
 
3329aef
d87d634
 
 
 
 
 
 
 
 
 
 
 
 
3329aef
d87d634
605ecc0
d87d634
 
 
605ecc0
d87d634
c611280
a936375
d87d634
 
a936375
d87d634
 
 
a936375
 
d87d634
 
 
 
605ecc0
d87d634
605ecc0
 
d87d634
 
 
 
58240b7
d87d634
605ecc0
 
 
 
 
d87d634
 
 
 
605ecc0
d87d634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
605ecc0
d87d634
 
 
 
 
605ecc0
d87d634
 
 
 
 
 
 
 
 
605ecc0
d87d634
 
 
 
 
 
 
 
605ecc0
d87d634
 
605ecc0
d87d634
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text To Speech</title>
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700&display=swap" rel="stylesheet">
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    font-family: 'Tajawal', sans-serif;
    background: linear-gradient(135deg, #000000 0%, #0d0a2e 50%, #1a0a3e 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }

  .container {
    background: #1a1a2e;
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 700px;
    border: 1px solid #2a2a4a;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  }

  h1 {
    color: #7c6bff;
    font-size: 28px;
    margin-bottom: 8px;
    text-align: center;
  }

  .subtitle {
    color: #888;
    text-align: center;
    margin-bottom: 30px;
    font-size: 14px;
  }

  textarea {
    width: 100%;
    height: 180px;
    background: #0f0f1a;
    border: 1px solid #2a2a4a;
    border-radius: 12px;
    padding: 16px;
    color: #fff;
    font-family: 'Tajawal', sans-serif;
    font-size: 15px;
    resize: vertical;
    outline: none;
    transition: border-color 0.3s;
    direction: ltr;
    text-align: left;
  }

  textarea:focus { border-color: #7c6bff; }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    margin: 20px 0;
    direction: ltr;
  }

  .control-group label {
    display: block;
    color: #888;
    font-size: 13px;
    margin-bottom: 8px;
    text-align: left;
  }

  select {
    width: 100%;
    background: #0f0f1a;
    border: 1px solid #2a2a4a;
    border-radius: 10px;
    padding: 10px 14px;
    color: #fff;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.3s;
    direction: ltr;
    text-align: left;
  }

  select:focus { border-color: #7c6bff; }

  button {
    width: 100%;
    background: linear-gradient(135deg, #7c6bff, #5b4de8);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 16px;
    font-family: 'Tajawal', sans-serif;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 10px;
  }

  button:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(74,158,255,0.4); }
  button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

  .status {
    text-align: center;
    margin-top: 16px;
    padding: 12px;
    border-radius: 10px;
    font-size: 14px;
    display: none;
  }

  .status.loading { background: #1e1e3a; color: #4a9eff; display: block; }
  .status.success { background: #0d2a1a; color: #4caf50; display: block; }
  .status.error { background: #2a0d0d; color: #f44336; display: block; }

  audio {
    width: 100%;
    margin-top: 16px;
    display: none;
    border-radius: 10px;
  }
</style>
</head>
<body>
<div class="container">
  <h1>Text To Speech</h1>

  <textarea id="text" placeholder="Enter the text"></textarea>

  <div class="controls">
    <div class="control-group">
      <label>Language</label>
      <select id="language">
        <option value="ar">Arabic</option>
        <option value="en" selected>English (US)</option>
        <option value="en-gb">English (UK)</option>
        <option value="fr">Français</option>
        <option value="de">German</option>
        <option value="es">Español</option>
        <option value="it">Italiano</option>
        <option value="tr">Türkçe</option>
        <option value="ru">Russian</option>
        <option value="hi">India</option>
      </select>
    </div>

    <div class="control-group">
      <label>Gender</label>
      <select id="gender">
        <option value="female">Female</option>
        <option value="male">Male</option>
      </select>
    </div>

    <div class="control-group">
      <label>Speed</label>
      <select id="rate">
        <option value="-50%">Very slow</option>
        <option value="-25%">Slow</option>
        <option value="+0%" selected>Normal</option>
        <option value="+25%">Fast</option>
        <option value="+50%">Very fast</option>
      </select>
    </div>
  </div>

  <button id="btn" onclick="generateSpeech()">Sound generation</button>

  <div class="status" id="status"></div>
  <audio id="audio" controls></audio>
</div>

<script>
async function generateSpeech() {
  const text = document.getElementById('text').value.trim();
  const language = document.getElementById('language').value;
  const gender = document.getElementById('gender').value;
  const rate = document.getElementById('rate').value;
  const btn = document.getElementById('btn');
  const status = document.getElementById('status');
  const audio = document.getElementById('audio');

  if (!text) {
    status.className = 'status error';
    status.textContent = 'Please enter text';
    return;
  }

  btn.disabled = true;
  status.className = 'status loading';
  status.textContent = 'Sound is being generated...';
  audio.style.display = 'none';

  try {
    const response = await fetch('https://tts-api-edge-tts.hf.space/tts', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ text, language, gender, rate })
    });

    if (!response.ok) throw new Error('Failed to generate sound');

    const blob = await response.blob();
    const url = URL.createObjectURL(blob);
    audio.src = url;
    audio.style.display = 'block';
    audio.play();

    status.className = 'status success';
    status.textContent = 'Sound was successfully generated!';
  } catch (err) {
    status.className = 'status error';
    status.textContent = 'An error occurred: ' + err.message;
  } finally {
    btn.disabled = false;
  }
}
</script>
</body>
</html>