Created
June 13, 2024 20:48
-
-
Save emilianobilli/76cd78abcdc1b2c64bee241f758ff2f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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