boltvoice / templates /index.html
geethareddy's picture
Update templates/index.html
cb0a021 verified
raw
history blame
2.43 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Biryani Hub</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
<div class="container">
<h1>Biryani Hub</h1>
<label for="name">Name</label>
<input type="text" id="name" placeholder="Your name will appear here..." readonly>
<label for="email">Email</label>
<input type="text" id="email" placeholder="Your email will appear here..." readonly>
<button id="mic-button" onclick="recordAudio()">
πŸŽ™οΈ Click to Speak
</button>
<p class="instructions">Please say your name when ready</p>
<audio id="audio-player" controls></audio>
</div>
<script>
async function playWelcomeAudio() {
let response = await fetch("/get_prompt");
let data = await response.json();
document.getElementById("audio-player").src = data.audio_url;
document.getElementById("audio-player").play();
}
async function recordAudio() {
let stream = await navigator.mediaDevices.getUserMedia({ audio: true });
let mediaRecorder = new MediaRecorder(stream);
let audioChunks = [];
mediaRecorder.ondataavailable = event => {
audioChunks.push(event.data);
};
mediaRecorder.onstop = async () => {
let audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
let formData = new FormData();
formData.append("audio", audioBlob, "input.wav");
let response = await fetch("/process_audio", {
method: "POST",
body: formData
});
let result = await response.json();
document.getElementById("name").value = result.text || result.error;
// Prompt for Email after Name
setTimeout(() => {
let emailPrompt = new Audio("/static/email_prompt.mp3");
emailPrompt.play();
}, 2000);
};
mediaRecorder.start();
setTimeout(() => mediaRecorder.stop(), 4000);
}
window.onload = playWelcomeAudio;
</script>
</body>
</html>