Spaces:
Runtime error
Runtime error
Update script.js
Browse files
script.js
CHANGED
|
@@ -12,7 +12,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 12 |
audioPlayer.style.display = 'none';
|
| 13 |
|
| 14 |
try {
|
| 15 |
-
const response = await fetch('http://localhost:
|
| 16 |
method: 'POST',
|
| 17 |
headers: {
|
| 18 |
'Content-Type': 'application/json',
|
|
@@ -20,17 +20,21 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 20 |
body: JSON.stringify({ text: text }),
|
| 21 |
});
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
downloadLink.href = 'http://localhost:5000' + data.url;
|
| 28 |
-
downloadLink.style.display = 'block';
|
| 29 |
-
audioPlayer.src = 'http://localhost:5000' + data.url;
|
| 30 |
-
audioPlayer.style.display = 'block';
|
| 31 |
-
} else {
|
| 32 |
-
statusDiv.textContent = `Error: ${data.message}`;
|
| 33 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
} catch (error) {
|
| 35 |
statusDiv.textContent = `Network error: ${error}`;
|
| 36 |
}
|
|
|
|
| 12 |
audioPlayer.style.display = 'none';
|
| 13 |
|
| 14 |
try {
|
| 15 |
+
const response = await fetch('http://localhost:80/text-to-speech/', { // Updated port to 80
|
| 16 |
method: 'POST',
|
| 17 |
headers: {
|
| 18 |
'Content-Type': 'application/json',
|
|
|
|
| 20 |
body: JSON.stringify({ text: text }),
|
| 21 |
});
|
| 22 |
|
| 23 |
+
if (!response.ok) {
|
| 24 |
+
const errorData = await response.json();
|
| 25 |
+
statusDiv.textContent = `Error: ${errorData.detail || response.statusText}`;
|
| 26 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
+
|
| 29 |
+
const blob = await response.blob();
|
| 30 |
+
const audioUrl = URL.createObjectURL(blob);
|
| 31 |
+
|
| 32 |
+
statusDiv.textContent = 'Speech generated successfully!';
|
| 33 |
+
downloadLink.href = audioUrl;
|
| 34 |
+
downloadLink.style.display = 'block';
|
| 35 |
+
audioPlayer.src = audioUrl;
|
| 36 |
+
audioPlayer.style.display = 'block';
|
| 37 |
+
|
| 38 |
} catch (error) {
|
| 39 |
statusDiv.textContent = `Network error: ${error}`;
|
| 40 |
}
|