anshharora commited on
Commit
1449696
·
verified ·
1 Parent(s): a9577f3

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +7 -4
static/script.js CHANGED
@@ -128,7 +128,7 @@ class ChatBot {
128
 
129
  async sendAudioToServer(audioBlob) {
130
  const formData = new FormData();
131
- formData.append('audio', audioBlob, 'recording.webm'); // Specify filename with extension
132
 
133
  try {
134
  const response = await fetch('/api/voice', {
@@ -136,9 +136,12 @@ class ChatBot {
136
  body: formData
137
  });
138
 
139
- if (!response.ok) throw new Error('Failed to send audio');
140
-
141
  const data = await response.json();
 
 
 
 
 
142
  if (data.text) {
143
  document.getElementById('messageInput').value = data.text;
144
  }
@@ -150,7 +153,7 @@ class ChatBot {
150
  }
151
  } catch (error) {
152
  console.error('Error sending audio:', error);
153
- this.addMessage('Sorry, there was an error processing your voice input.', 'bot');
154
  }
155
  }
156
 
 
128
 
129
  async sendAudioToServer(audioBlob) {
130
  const formData = new FormData();
131
+ formData.append('audio', audioBlob, 'recording.webm');
132
 
133
  try {
134
  const response = await fetch('/api/voice', {
 
136
  body: formData
137
  });
138
 
 
 
139
  const data = await response.json();
140
+
141
+ if (!response.ok) {
142
+ throw new Error(data.error || 'Failed to process audio');
143
+ }
144
+
145
  if (data.text) {
146
  document.getElementById('messageInput').value = data.text;
147
  }
 
153
  }
154
  } catch (error) {
155
  console.error('Error sending audio:', error);
156
+ this.addMessage(`Error: ${error.message}`, 'bot');
157
  }
158
  }
159