geethareddy commited on
Commit
ff7b68c
·
verified ·
1 Parent(s): 7467739

Update templates/index.html

Browse files
Files changed (1) hide show
  1. 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
- <label for="name">Name</label>
14
- <input type="text" id="name" placeholder="Your name will appear here..." readonly>
 
 
15
 
16
- <label for="email">Email</label>
17
- <input type="text" id="email" placeholder="Your email will appear here..." readonly>
 
18
 
19
- <p class="instructions">Voice interaction in progress...</p>
20
 
21
- <audio id="audio-player" autoplay></audio>
22
- </div>
23
 
24
- <script>
25
- async function startVoiceInteraction() {
26
- let audioPlayer = document.getElementById("audio-player");
 
 
 
 
27
 
28
- // Step 1: Welcome Message
29
- audioPlayer.src = "/static/welcome.mp3";
30
- audioPlayer.play();
31
- await new Promise(resolve => setTimeout(resolve, 2000));
32
 
33
- // Step 2: Ask for Name
34
- audioPlayer.src = "/static/ask_name.mp3";
35
- audioPlayer.play();
36
- await new Promise(resolve => setTimeout(resolve, 3000));
37
 
38
- let name = await recordAndProcessAudio();
39
- document.getElementById("name").value = name;
 
40
 
41
- // Step 3: Ask for Email
42
- audioPlayer.src = "/static/ask_email.mp3";
43
- audioPlayer.play();
44
- await new Promise(resolve => setTimeout(resolve, 3000));
45
 
46
- let email = await recordAndProcessAudio();
47
- document.getElementById("email").value = email;
48
 
49
- // Step 4: Thank You Message
50
- audioPlayer.src = "/static/thank_you.mp3";
51
- audioPlayer.play();
52
- }
53
 
54
- async function recordAndProcessAudio() {
55
- let stream = await navigator.mediaDevices.getUserMedia({ audio: true });
56
- let mediaRecorder = new MediaRecorder(stream);
57
- let audioChunks = [];
58
 
59
- mediaRecorder.ondataavailable = event => {
60
- audioChunks.push(event.data);
61
- };
62
 
63
- return new Promise(resolve => {
64
- mediaRecorder.onstop = async () => {
65
- let audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
66
- let formData = new FormData();
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
- mediaRecorder.start();
79
- setTimeout(() => mediaRecorder.stop(), 4000);
80
- });
 
81
  }
82
 
83
- window.onload = startVoiceInteraction;
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>