usmanyousaf's picture
Update templates/index.html
7918102 verified
raw
history blame
6.96 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Audio Transcription with Grammar and Vocabulary Check</title>
<style>
body {
background-color: black;
font-family: 'Arial', sans-serif;
color: white;
padding: 20px;
}
h1, h2, h3 {
color: white;
margin-bottom: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
}
.form-label, #recording-status {
color: white;
}
select, button, input[type="text"] {
background-color: black;
color: white;
border: 1px solid lightgray;
padding: 10px;
border-radius: 4px;
transition: all 0.3s ease;
}
select:hover, button:hover, input[type="text"]:hover {
border-color: white;
}
.btn {
color: white;
background-color: green;
border: 1px solid lightgray;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
.btn:hover {
background-color: #0f9d58;
}
.feedback-section {
margin-top: 30px;
border: 1px solid lightgray;
padding: 15px;
border-radius: 8px;
}
#transcription-result, #grammar-feedback, #vocabulary-feedback {
background-color: black;
border: 1px solid lightgray;
padding: 10px;
border-radius: 4px;
min-height: 50px;
color: white;
}
.recording-bar {
width: 0;
height: 5px;
background-color: green;
margin-top: 10px;
border-radius: 2px;
transition: width 0.5s;
}
#recording-status {
margin-top: 10px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1 style="text-align: center;">Audio Transcription with Grammar and Vocabulary Check</h1>
<!-- Language Selection -->
<div>
<label for="language-select" class="form-label">Select Language:</label>
<select id="language-select" class="form-select">
<option value="en">English</option>
<option value="es">Spanish</option>
<option value="fr">French</option>
<option value="de">German</option>
<option value="zh">Chinese</option>
<option value="ja">Japanese</option>
<option value="ko">Korean</option>
<option value="ar">Arabic</option>
</select>
</div>
<!-- Recording Controls -->
<h2>Record Audio</h2>
<button id="start-recording" class="btn">Start Recording</button>
<button id="stop-recording" class="btn" disabled>Stop Recording</button>
<div id="recording-status"></div>
<div id="recording-bar" class="recording-bar"></div>
<!-- Feedback Sections -->
<div class="feedback-section">
<h3>Transcription Result:</h3>
<div id="transcription-result"></div>
</div>
<div class="feedback-section">
<h3>Grammar Feedback:</h3>
<div id="grammar-feedback"></div>
<p><strong>Grammar Score:</strong> <span id="grammar-score"></span>/10</p>
<h3>Vocabulary Feedback:</h3>
<div id="vocabulary-feedback"></div>
<p><strong>Vocabulary Score:</strong> <span id="vocabulary-score"></span>/10</p>
<button id="check-grammar" class="btn" disabled>Check Grammar and Vocabulary</button>
</div>
</div>
<script>
// JavaScript logic as provided by the user
let mediaRecorder;
let audioChunks = [];
document.getElementById("start-recording").onclick = async () => {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.start();
document.getElementById("recording-status").textContent = "Recording...";
document.getElementById("start-recording").disabled = true;
document.getElementById("stop-recording").disabled = false;
let recordingInterval = setInterval(() => {
const currentWidth = parseFloat(document.getElementById("recording-bar").style.width) || 0;
document.getElementById("recording-bar").style.width = Math.min(currentWidth + 5, 100) + '%';
}, 1000);
mediaRecorder.ondataavailable = (event) => audioChunks.push(event.data);
mediaRecorder.onstop = async () => {
clearInterval(recordingInterval);
document.getElementById("recording-bar").style.width = '0%';
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
const formData = new FormData();
formData.append('audio_data', audioBlob, 'audio.wav');
const response = await fetch('/transcribe', {
method: 'POST',
body: formData
});
const result = await response.json();
document.getElementById("transcription-result").textContent = result.transcription;
document.getElementById("check-grammar").disabled = false;
audioChunks = [];
document.getElementById("recording-status").textContent = "Recording stopped.";
document.getElementById("start-recording").disabled = false;
document.getElementById("stop-recording").disabled = true;
};
};
document.getElementById("stop-recording").onclick = () => mediaRecorder.stop();
document.getElementById("check-grammar").onclick = async () => {
const transcription = document.getElementById("transcription-result").textContent;
const formData = new FormData();
formData.append('transcription', transcription);
const response = await fetch('/check_grammar', {
method: 'POST',
body: formData
});
const result = await response.json();
document.getElementById("grammar-feedback").textContent = result.grammar_feedback;
document.getElementById("vocabulary-feedback").textContent = result.vocabulary_feedback;
document.getElementById("grammar-score").textContent = result.grammar_score;
document.getElementById("vocabulary-score").textContent = result.vocabulary_score;
};
</script>
</body>
</html>