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