Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +22 -19
static/script.js
CHANGED
@@ -1,21 +1,24 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
const
|
4 |
-
|
5 |
-
const inferJson = await inferResponse.json();
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
});
|
|
|
1 |
+
document.getElementById('submit-audio').addEventListener('click', async () => {
|
2 |
+
const audioInput = document.getElementById('audio-input');
|
3 |
+
if (audioInput.files.length === 0) {
|
4 |
+
alert('Please select an audio file.');
|
5 |
+
return;
|
6 |
+
}
|
7 |
|
8 |
+
const formData = new FormData();
|
9 |
+
formData.append('audio', audioInput.files[0]);
|
|
|
10 |
|
11 |
+
try {
|
12 |
+
const response = await fetch('/process_audio', {
|
13 |
+
method: 'POST',
|
14 |
+
body: formData
|
15 |
+
});
|
16 |
+
const data = await response.json();
|
17 |
+
document.querySelector('.response-text').textContent = data.response_text;
|
18 |
+
const audioElement = document.querySelector('.response-audio');
|
19 |
+
audioElement.src = data.response_audio_url;
|
20 |
+
audioElement.style.display = 'block';
|
21 |
+
} catch (error) {
|
22 |
+
console.error('Error:', error);
|
23 |
+
}
|
24 |
+
});
|
|