-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
324 lines (287 loc) · 11.6 KB
/
index.html
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Speech Translation</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #fceabb;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
h1 {
margin-bottom: 30px;
font-size: 54px; /* Increased font size */
color: #0056b3;
text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
animation: shrink 1s ease forwards;
}
@keyframes shrink {
0% {
transform: scale(1.2); /* Initial larger size */
}
100% {
transform: scale(0.9);
}
}
.button-container {
display: none;
justify-content: center;
align-items: center;
gap: 20px;
opacity: 0;
animation: fadeIn 1s ease forwards;
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.button-container.show {
display: flex;
}
.button-container button {
margin: 10px;
padding: 12px 24px;
font-size: 24px;
cursor: pointer;
border: none;
border-radius: 30px;
background-color: #ff6f61;
color: #fff;
transition: all 0.5s ease; /* Increased transition duration */
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
position: relative;
overflow: hidden;
}
.button-container button:hover {
background-color: #ff3d00;
transform: translateY(-2px);
}
.button-container button::before {
content: '';
position: absolute;
left: 20px;
top: 50%;
transform: translateY(-50%);
font-size: 28px;
color: #fff;
opacity: 0.7;
}
.button-container button#recordBtn::before {
content: '\f130'; /* Microphone icon */
font-family: 'Font Awesome 5 Free';
}
.button-container button#translateBtn::before {
content: '\f4ad'; /* Language icon */
font-family: 'Font Awesome 5 Free';
}
.button-container button#playBtn::before {
content: '\f04b'; /* Play icon */
font-family: 'Font Awesome 5 Free';
}
#status {
margin-top: 40px; /* Increased margin to avoid overlap */
margin-bottom: 20px; /* Added margin for better spacing */
font-size: 24px;
color: #0056b3;
text-align: center;
animation: statusFade 1s ease infinite alternate;
}
@keyframes statusFade {
0% {
opacity: 0.7;
}
100% {
opacity: 1;
}
}
/* Styling for audio player */
.audio-player {
display: none;
margin-top: 20px;
width: 300px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.audio-player audio {
width: 100%;
outline: none;
}
.audio-player button {
width: 50%;
padding: 10px;
font-size: 18px;
border: none;
background-color: #ff6f61;
color: #fff;
cursor: pointer;
transition: background-color 0.5s ease; /* Increased transition duration */
}
.audio-player button:hover {
background-color: #ff3d00;
}
/* Dropdown button */
.dropdown {
position: relative;
display: inline-block;
margin-bottom: 20px; /* Added margin for better spacing */
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content select {
display: block;
width: 100%;
padding: 10px;
font-size: 18px;
border: none;
background-color: #f9f9f9;
cursor: pointer;
transition: background-color 0.5s ease; /* Increased transition duration */
}
/* Change color of dropdown links on hover */
.dropdown-content select:hover {
background-color: #ddd;
}
/* Show the dropdown content when hovering over the dropdown button */
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>
<h1>Speech Translation</h1>
<div class="button-container" id="buttonContainer">
<button id="recordBtn"><i class="fas fa-microphone"></i> Record</button>
<!-- Inside the <div class="button-container" id="buttonContainer"> -->
<div class="dropdown">
<button class="dropbtn" id="translateBtn"><i class="fas fa-language"></i> Translate</button>
<div class="dropdown-content">
<select id="targetLanguage">
<option value="Spanish">Spanish</option>
<option value="French">French</option>
<option value="German">German</option>
<option value="Hindi">Hindi</option>
<!-- Add more options for other languages as needed -->
</select>
</div>
</div>
<button id="playBtn"><i class="fas fa-play"></i> Play</button>
</div>
<div id="status">Status Message</div>
<div class="audio-player" id="audioPlayer">
<audio controls id="audioControl">
Your browser does not support the audio element.
</audio>
<button id="closePlayer">Close Player</button>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
// Animation for header and buttons
setTimeout(function() {
document.querySelector('h1').classList.add('shrink');
document.getElementById('buttonContainer').classList.add('show');
}, 500);
document.getElementById('recordBtn').addEventListener('click', function() {
// Set status to 'Recording...'
document.getElementById('status').innerText = 'Recording...';
// Send POST request to '/record_audio'
fetch('/record_audio', { method: 'POST' })
.then(response => response.json())
.then(data => {
// Set status to response message
})
.catch(error => {
// Log error to console
console.error('Error:', error);
});
var startTime = Date.now(); // Get the start time
// Update status every second until recording completes
var timerId = setInterval(function() {
var elapsedTime = Math.floor((Date.now() - startTime) / 1000); // Calculate elapsed time in seconds
// Set status to 'Recording... (elapsedTime seconds)'
document.getElementById('status').innerText = 'Recording... (' + elapsedTime + ' seconds)';
}, 1000); // Update every 1 second (1000 milliseconds)
// Simulate recording for 5 seconds
setTimeout(function() {
clearInterval(timerId); // Stop updating the status
var elapsedTime = Math.floor((Date.now() - startTime) / 1000); // Calculate total elapsed time in seconds
// Set status to 'Recording completed. Duration: elapsedTime seconds'
document.getElementById('status').innerText = 'Recording completed. Duration: ' + elapsedTime + ' seconds';
}, 5000); // 5000 milliseconds = 5 seconds
});
document.getElementById('translateBtn').addEventListener('click', function() {
// Set status to 'Translating...'
document.getElementById('status').innerText = 'Translating...';
// Get the selected target language from the dropdown
var selectedLanguage = document.getElementById('targetLanguage').value;
// Send POST request to '/translate_text' with selected target language
fetch('/translate_text', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ target_language: selectedLanguage }) // Send selected target language in the request body
})
.then(response => response.json())
.then(data => {
// Set status to 'Translating to [destination_language]'
document.getElementById('status').innerText = 'Translating to ' + data.target_language;
// Display translated text after a short delay (for better user experience)
setTimeout(function() {
document.getElementById('status').innerText = data.translated_text;
}, 2000); // 1000 milliseconds = 1 second (adjust as needed)
})
.catch(error => console.error('Error:', error));
});
document.getElementById('playBtn').addEventListener('click', function() {
// Set status to 'Creating file...'
document.getElementById('status').innerText = 'Creating file...';
fetch('/play_translation', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // Set the content type to JSON
}
})
.then(response => response.json())
.then(data => {
console.log(data); // Check the response data in the console
if (data.message) {
// Set status to 'Playing...'
document.getElementById('status').innerText = 'Playing...';
// Update the status after a short delay to simulate the duration of the audio playback
setTimeout(function() {
document.getElementById('status').innerText = data.message;
}, 3000); // Simulating playback duration (adjust as needed)
} else if (data.error) {
// Set status to the error message
document.getElementById('status').innerText = data.error;
}
})
.catch(error => console.error('Error:', error));
});
});
</script>
</body>
</html>