Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +67 -56
templates/index.html
CHANGED
@@ -3,84 +3,95 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Biryani Hub</title>
|
7 |
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
8 |
</head>
|
9 |
<body>
|
10 |
<div class="container">
|
11 |
<h1>Biryani Hub</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
audioPlayer.play();
|
52 |
-
}
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
};
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
formData.append("audio", audioBlob, "input.wav");
|
68 |
-
|
69 |
-
let response = await fetch("/process_audio", {
|
70 |
-
method: "POST",
|
71 |
-
body: formData
|
72 |
-
});
|
73 |
-
|
74 |
-
let result = await response.json();
|
75 |
-
resolve(result.text || "Error capturing speech");
|
76 |
-
};
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
81 |
}
|
82 |
|
83 |
-
window.onload =
|
84 |
</script>
|
85 |
</body>
|
86 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Biryani Hub Registration</title>
|
7 |
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
8 |
</head>
|
9 |
<body>
|
10 |
<div class="container">
|
11 |
<h1>Biryani Hub</h1>
|
12 |
+
<label for="name">Name:</label>
|
13 |
+
<input type="text" id="name" readonly>
|
14 |
+
<label for="email">Email:</label>
|
15 |
+
<input type="text" id="email" readonly>
|
16 |
+
<p id="status">Initializing...</p>
|
17 |
+
<audio id="audio-player" autoplay></audio>
|
18 |
+
</div>
|
19 |
+
<script>
|
20 |
+
async function playAudio(src) {
|
21 |
+
const audioPlayer = document.getElementById('audio-player');
|
22 |
+
audioPlayer.src = src;
|
23 |
+
await audioPlayer.play();
|
24 |
+
return new Promise(resolve => {
|
25 |
+
audioPlayer.onended = resolve;
|
26 |
+
});
|
27 |
+
}
|
28 |
|
29 |
+
async function recordAudio() {
|
30 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
31 |
+
const mediaRecorder = new MediaRecorder(stream);
|
32 |
+
const audioChunks = [];
|
33 |
|
34 |
+
mediaRecorder.ondataavailable = event => {
|
35 |
+
audioChunks.push(event.data);
|
36 |
+
};
|
37 |
|
38 |
+
mediaRecorder.start();
|
39 |
|
40 |
+
await new Promise(resolve => setTimeout(resolve, 4000)); // Record for 4 seconds
|
41 |
+
mediaRecorder.stop();
|
42 |
|
43 |
+
return new Promise(resolve => {
|
44 |
+
mediaRecorder.onstop = () => {
|
45 |
+
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
46 |
+
resolve(audioBlob);
|
47 |
+
};
|
48 |
+
});
|
49 |
+
}
|
50 |
|
51 |
+
async function transcribeAudio(audioBlob) {
|
52 |
+
const formData = new FormData();
|
53 |
+
formData.append('audio', audioBlob, 'input.wav');
|
|
|
54 |
|
55 |
+
const response = await fetch('/transcribe', {
|
56 |
+
method: 'POST',
|
57 |
+
body: formData
|
58 |
+
});
|
59 |
|
60 |
+
const result = await response.json();
|
61 |
+
return result.text || 'Unable to transcribe audio.';
|
62 |
+
}
|
63 |
|
64 |
+
async function startInteraction() {
|
65 |
+
const status = document.getElementById('status');
|
66 |
+
const nameInput = document.getElementById('name');
|
67 |
+
const emailInput = document.getElementById('email');
|
68 |
|
69 |
+
status.textContent = 'Playing welcome message...';
|
70 |
+
await playAudio('{{ url_for("static", filename="welcome.mp3") }}');
|
71 |
|
72 |
+
status.textContent = 'Asking for your name...';
|
73 |
+
await playAudio('{{ url_for("static", filename="ask_name.mp3") }}');
|
|
|
|
|
74 |
|
75 |
+
status.textContent = 'Recording your name...';
|
76 |
+
const nameAudio = await recordAudio();
|
77 |
+
const nameText = await transcribeAudio(nameAudio);
|
78 |
+
nameInput.value = nameText;
|
79 |
|
80 |
+
status.textContent = 'Asking for your email...';
|
81 |
+
await playAudio('{{ url_for("static", filename="ask_email.mp3") }}');
|
|
|
82 |
|
83 |
+
status.textContent = 'Recording your email...';
|
84 |
+
const emailAudio = await recordAudio();
|
85 |
+
const emailText = await transcribeAudio(emailAudio);
|
86 |
+
emailInput.value = emailText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
+
status.textContent = 'Playing thank you message...';
|
89 |
+
await playAudio('{{ url_for("static", filename="thank_you.mp3") }}');
|
90 |
+
|
91 |
+
status.textContent = 'Registration complete.';
|
92 |
}
|
93 |
|
94 |
+
window.onload = startInteraction;
|
95 |
</script>
|
96 |
</body>
|
97 |
</html>
|