usmanyousaf
commited on
Commit
•
e24409d
1
Parent(s):
30432c9
Upload index.html
Browse files- templates/index.html +171 -0
templates/index.html
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>Audio Transcription with Grammar and Vocabulary Check</title>
|
7 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
|
8 |
+
<style>
|
9 |
+
body {
|
10 |
+
padding: 20px;
|
11 |
+
background: linear-gradient(135deg, #6d7be5, #8699ee);
|
12 |
+
font-family: 'Arial', sans-serif;
|
13 |
+
color: #333;
|
14 |
+
}
|
15 |
+
h1, h2, h3 {
|
16 |
+
margin-bottom: 20px;
|
17 |
+
}
|
18 |
+
.recording-bar {
|
19 |
+
width: 0;
|
20 |
+
height: 5px;
|
21 |
+
background-color: #4caf50;
|
22 |
+
transition: width 0.5s;
|
23 |
+
}
|
24 |
+
#transcription-result, #grammar-feedback, #vocabulary-feedback {
|
25 |
+
padding: 10px;
|
26 |
+
background-color: rgba(255, 255, 255, 0.8);
|
27 |
+
border-radius: 4px;
|
28 |
+
margin-bottom: 20px;
|
29 |
+
min-height: 50px;
|
30 |
+
}
|
31 |
+
.feedback-section {
|
32 |
+
margin-top: 30px;
|
33 |
+
}
|
34 |
+
.btn {
|
35 |
+
margin-top: 10px;
|
36 |
+
transition: background-color 0.3s, transform 0.2s;
|
37 |
+
}
|
38 |
+
.btn:hover {
|
39 |
+
transform: scale(1.05);
|
40 |
+
}
|
41 |
+
.form-select, input[type="text"] {
|
42 |
+
padding: 10px;
|
43 |
+
transition: border-color 0.3s;
|
44 |
+
}
|
45 |
+
#recording-status {
|
46 |
+
margin-top: 10px;
|
47 |
+
font-weight: bold;
|
48 |
+
color: #4caf50;
|
49 |
+
}
|
50 |
+
</style>
|
51 |
+
</head>
|
52 |
+
<body>
|
53 |
+
<div class="container">
|
54 |
+
<h1 style="text-align: center; font-weight: bold; color: #000;">Grammar and Vocabulary Checker with Audio Transcription</h1>
|
55 |
+
<div class="mb-3">
|
56 |
+
<label for="language-select" class="form-label">Select Language:</label>
|
57 |
+
<select id="language-select" class="form-select">
|
58 |
+
<option value="en">English</option>
|
59 |
+
<option value="es">Spanish</option>
|
60 |
+
<option value="fr">French</option>
|
61 |
+
<option value="de">German</option>
|
62 |
+
<option value="zh">Chinese</option>
|
63 |
+
<option value="ja">Japanese</option>
|
64 |
+
<option value="ko">Korean</option>
|
65 |
+
<option value="ar">Arabic</option>
|
66 |
+
</select>
|
67 |
+
</div>
|
68 |
+
|
69 |
+
<h2>Record Audio</h2>
|
70 |
+
<button id="start-recording" class="btn btn-primary">Start Recording</button>
|
71 |
+
<button id="stop-recording" class="btn btn-danger" disabled>Stop Recording</button>
|
72 |
+
<div id="recording-status"></div>
|
73 |
+
|
74 |
+
<div class="recording-container">
|
75 |
+
<div id="recording-bar" class="recording-bar"></div>
|
76 |
+
</div>
|
77 |
+
|
78 |
+
<div class="feedback-section">
|
79 |
+
<h3>Transcription Result:</h3>
|
80 |
+
<div id="transcription-result"></div>
|
81 |
+
</div>
|
82 |
+
|
83 |
+
<div class="feedback-section">
|
84 |
+
<h3>Grammar Feedback:</h3>
|
85 |
+
<div id="grammar-feedback"></div>
|
86 |
+
<p><strong>Grammar Score:</strong> <span id="grammar-score"></span>/10</p>
|
87 |
+
|
88 |
+
<h3>Vocabulary Feedback:</h3>
|
89 |
+
<div id="vocabulary-feedback"></div>
|
90 |
+
<p><strong>Vocabulary Score:</strong> <span id="vocabulary-score"></span>/10</p>
|
91 |
+
|
92 |
+
<button id="check-grammar" class="btn btn-secondary" disabled>Check Grammar and Vocabulary</button>
|
93 |
+
</div>
|
94 |
+
</div>
|
95 |
+
|
96 |
+
<script>
|
97 |
+
let mediaRecorder;
|
98 |
+
let audioChunks = [];
|
99 |
+
|
100 |
+
document.getElementById("start-recording").onclick = async () => {
|
101 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
102 |
+
mediaRecorder = new MediaRecorder(stream);
|
103 |
+
mediaRecorder.start();
|
104 |
+
document.getElementById("recording-status").textContent = "Recording...";
|
105 |
+
document.getElementById("start-recording").disabled = true;
|
106 |
+
document.getElementById("stop-recording").disabled = false;
|
107 |
+
|
108 |
+
document.getElementById("recording-bar").style.width = '0%';
|
109 |
+
let recordingInterval = setInterval(() => {
|
110 |
+
const currentWidth = parseFloat(document.getElementById("recording-bar").style.width);
|
111 |
+
const newWidth = Math.min(currentWidth + 5, 100);
|
112 |
+
document.getElementById("recording-bar").style.width = newWidth + '%';
|
113 |
+
if (newWidth >= 100) {
|
114 |
+
clearInterval(recordingInterval);
|
115 |
+
}
|
116 |
+
}, 1000);
|
117 |
+
|
118 |
+
mediaRecorder.ondataavailable = (event) => {
|
119 |
+
audioChunks.push(event.data);
|
120 |
+
};
|
121 |
+
|
122 |
+
mediaRecorder.onstop = async () => {
|
123 |
+
clearInterval(recordingInterval);
|
124 |
+
document.getElementById("recording-bar").style.width = '0%';
|
125 |
+
|
126 |
+
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
127 |
+
const formData = new FormData();
|
128 |
+
formData.append('audio_data', audioBlob, 'audio.wav');
|
129 |
+
const selectedLanguage = document.getElementById("language-select").value;
|
130 |
+
formData.append('language', selectedLanguage);
|
131 |
+
|
132 |
+
const response = await fetch('/transcribe', {
|
133 |
+
method: 'POST',
|
134 |
+
body: formData
|
135 |
+
});
|
136 |
+
const result = await response.json();
|
137 |
+
document.getElementById("transcription-result").textContent = result.transcription;
|
138 |
+
document.getElementById("check-grammar").disabled = false;
|
139 |
+
|
140 |
+
audioChunks = [];
|
141 |
+
document.getElementById("recording-status").textContent = "Recording stopped.";
|
142 |
+
document.getElementById("start-recording").disabled = false;
|
143 |
+
document.getElementById("stop-recording").disabled = true;
|
144 |
+
};
|
145 |
+
};
|
146 |
+
|
147 |
+
document.getElementById("stop-recording").onclick = () => {
|
148 |
+
mediaRecorder.stop();
|
149 |
+
};
|
150 |
+
|
151 |
+
document.getElementById("check-grammar").onclick = async () => {
|
152 |
+
const transcription = document.getElementById("transcription-result").textContent;
|
153 |
+
const formData = new FormData();
|
154 |
+
formData.append('transcription', transcription);
|
155 |
+
const selectedLanguage = document.getElementById("language-select").value;
|
156 |
+
formData.append('language', selectedLanguage);
|
157 |
+
|
158 |
+
const response = await fetch('/check_grammar', {
|
159 |
+
method: 'POST',
|
160 |
+
body: formData
|
161 |
+
});
|
162 |
+
const result = await response.json();
|
163 |
+
|
164 |
+
document.getElementById("grammar-feedback").textContent = result.grammar_feedback;
|
165 |
+
document.getElementById("vocabulary-feedback").textContent = result.vocabulary_feedback;
|
166 |
+
document.getElementById("grammar-score").textContent = result.grammar_score;
|
167 |
+
document.getElementById("vocabulary-score").textContent = result.vocabulary_score;
|
168 |
+
};
|
169 |
+
</script>
|
170 |
+
</body>
|
171 |
+
</html>
|