Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +9 -16
index.html
CHANGED
|
@@ -116,6 +116,7 @@
|
|
| 116 |
const languageSelect = document.getElementById("languageSelect");
|
| 117 |
const playButton = document.getElementById("playButton");
|
| 118 |
const outputText = document.getElementById("outputText");
|
|
|
|
| 119 |
|
| 120 |
recordButton.addEventListener("click", function () {
|
| 121 |
if (!isRecording) {
|
|
@@ -139,6 +140,8 @@
|
|
| 139 |
});
|
| 140 |
} else {
|
| 141 |
mediaRecorder.stop();
|
|
|
|
|
|
|
| 142 |
isRecording = false;
|
| 143 |
recordButton.innerText = "Start Recording";
|
| 144 |
}
|
|
@@ -155,6 +158,7 @@
|
|
| 155 |
};
|
| 156 |
fileReader.readAsArrayBuffer(uploadedFile);
|
| 157 |
}
|
|
|
|
| 158 |
console.log('File uploaded')
|
| 159 |
});
|
| 160 |
|
|
@@ -163,9 +167,9 @@
|
|
| 163 |
if (recordedAudioBlob || uploadedFile) {
|
| 164 |
const formData = new FormData();
|
| 165 |
|
| 166 |
-
if (
|
| 167 |
formData.append("audio", recordedAudioBlob, "recorded_audio.wav");
|
| 168 |
-
} else if (uploadedFile) {
|
| 169 |
formData.append("audio", uploadedFile, uploadedFile.name);
|
| 170 |
}
|
| 171 |
|
|
@@ -189,17 +193,6 @@
|
|
| 189 |
console.error("Error communicating with the backend:", error);
|
| 190 |
outputText.value = "Backend communication failed.";
|
| 191 |
});
|
| 192 |
-
|
| 193 |
-
// if (recordedAudioBlob) {
|
| 194 |
-
// const downloadLink = document.createElement("a");
|
| 195 |
-
// downloadLink.href = URL.createObjectURL(recordedAudioBlob);
|
| 196 |
-
// downloadLink.download = "recorded_audio.wav";
|
| 197 |
-
// downloadLink.style.display = "none";
|
| 198 |
-
// document.body.appendChild(downloadLink);
|
| 199 |
-
// downloadLink.click();
|
| 200 |
-
// URL.revokeObjectURL(downloadLink.href);
|
| 201 |
-
// document.body.removeChild(downloadLink);
|
| 202 |
-
// }
|
| 203 |
} else {
|
| 204 |
outputText.value = "Please record audio or upload a file and select a language before submitting.";
|
| 205 |
}
|
|
@@ -208,9 +201,9 @@
|
|
| 208 |
playButton.addEventListener("click", function () {
|
| 209 |
let audioURL;
|
| 210 |
|
| 211 |
-
if (
|
| 212 |
audioURL = URL.createObjectURL(recordedAudioBlob);
|
| 213 |
-
} else if (uploadedFile) {
|
| 214 |
audioURL = URL.createObjectURL(uploadedFile);
|
| 215 |
}
|
| 216 |
|
|
@@ -220,7 +213,7 @@
|
|
| 220 |
} else {
|
| 221 |
outputText.value = "No audio available.";
|
| 222 |
}
|
| 223 |
-
|
| 224 |
|
| 225 |
</script>
|
| 226 |
</body>
|
|
|
|
| 116 |
const languageSelect = document.getElementById("languageSelect");
|
| 117 |
const playButton = document.getElementById("playButton");
|
| 118 |
const outputText = document.getElementById("outputText");
|
| 119 |
+
let lastModifiedType = null;
|
| 120 |
|
| 121 |
recordButton.addEventListener("click", function () {
|
| 122 |
if (!isRecording) {
|
|
|
|
| 140 |
});
|
| 141 |
} else {
|
| 142 |
mediaRecorder.stop();
|
| 143 |
+
console.log('Audio recorded')
|
| 144 |
+
lastModifiedType = "recorded";
|
| 145 |
isRecording = false;
|
| 146 |
recordButton.innerText = "Start Recording";
|
| 147 |
}
|
|
|
|
| 158 |
};
|
| 159 |
fileReader.readAsArrayBuffer(uploadedFile);
|
| 160 |
}
|
| 161 |
+
lastModifiedType = "uploaded";
|
| 162 |
console.log('File uploaded')
|
| 163 |
});
|
| 164 |
|
|
|
|
| 167 |
if (recordedAudioBlob || uploadedFile) {
|
| 168 |
const formData = new FormData();
|
| 169 |
|
| 170 |
+
if (lastModifiedType === "recorded" && recordedAudioBlob) {
|
| 171 |
formData.append("audio", recordedAudioBlob, "recorded_audio.wav");
|
| 172 |
+
} else if (lastModifiedType === "uploaded" && uploadedFile) {
|
| 173 |
formData.append("audio", uploadedFile, uploadedFile.name);
|
| 174 |
}
|
| 175 |
|
|
|
|
| 193 |
console.error("Error communicating with the backend:", error);
|
| 194 |
outputText.value = "Backend communication failed.";
|
| 195 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
} else {
|
| 197 |
outputText.value = "Please record audio or upload a file and select a language before submitting.";
|
| 198 |
}
|
|
|
|
| 201 |
playButton.addEventListener("click", function () {
|
| 202 |
let audioURL;
|
| 203 |
|
| 204 |
+
if (lastModifiedType === "recorded" && recordedAudioBlob) {
|
| 205 |
audioURL = URL.createObjectURL(recordedAudioBlob);
|
| 206 |
+
} else if (lastModifiedType === "uploaded" && uploadedFile) {
|
| 207 |
audioURL = URL.createObjectURL(uploadedFile);
|
| 208 |
}
|
| 209 |
|
|
|
|
| 213 |
} else {
|
| 214 |
outputText.value = "No audio available.";
|
| 215 |
}
|
| 216 |
+
});
|
| 217 |
|
| 218 |
</script>
|
| 219 |
</body>
|