Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save emilianobilli/76cd78abcdc1b2c64bee241f758ff2f1 to your computer and use it in GitHub Desktop.
Save emilianobilli/76cd78abcdc1b2c64bee241f758ff2f1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Detect WAV Bit Depth</title>
</head>
<body>
<input type="file" id="fileInput" accept=".wav">
<p id="result"></p>
<script>
document.getElementById('fileInput').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const buffer = e.target.result;
const view = new DataView(buffer);
// WAV file header is 44 bytes long
const bitsPerSample = view.getUint16(34, true);
document.getElementById('result').textContent = `Bit Depth: ${bitsPerSample} bits`;
};
reader.onerror = function() {
console.error("Failed to read file");
};
reader.readAsArrayBuffer(file);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment