geethareddy commited on
Commit
4e70d0d
·
verified ·
1 Parent(s): 69067ae

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +55 -0
templates/index.html ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>AI Dining Assistant</title>
7
+ <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
8
+ </head>
9
+ <body>
10
+ <h1>🍽️ AI Dining Assistant</h1>
11
+ <img src="{{ url_for('static', filename='mic.png') }}" id="mic-button" onclick="recordAudio()" alt="Mic Button">
12
+ <p id="status">Press the mic button to start...</p>
13
+ <audio id="audio-player" controls></audio>
14
+ <h3>Your Response:</h3>
15
+ <p id="transcription"></p>
16
+
17
+ <script>
18
+ async function playWelcomeAudio() {
19
+ let response = await fetch("/get_prompt");
20
+ let data = await response.json();
21
+ document.getElementById("audio-player").src = data.audio_url;
22
+ document.getElementById("audio-player").play();
23
+ }
24
+
25
+ async function recordAudio() {
26
+ let stream = await navigator.mediaDevices.getUserMedia({ audio: true });
27
+ let mediaRecorder = new MediaRecorder(stream);
28
+ let audioChunks = [];
29
+
30
+ mediaRecorder.ondataavailable = event => {
31
+ audioChunks.push(event.data);
32
+ };
33
+
34
+ mediaRecorder.onstop = async () => {
35
+ let audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
36
+ let formData = new FormData();
37
+ formData.append("audio", audioBlob, "input.wav");
38
+
39
+ let response = await fetch("/process_audio", {
40
+ method: "POST",
41
+ body: formData
42
+ });
43
+
44
+ let result = await response.json();
45
+ document.getElementById("transcription").innerText = result.text || result.error;
46
+ };
47
+
48
+ mediaRecorder.start();
49
+ setTimeout(() => mediaRecorder.stop(), 4000);
50
+ }
51
+
52
+ window.onload = playWelcomeAudio;
53
+ </script>
54
+ </body>
55
+ </html>