Skip to content

Instantly share code, notes, and snippets.

@MatthewCallis
Last active January 19, 2021 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthewCallis/e02befb6ec83a7df8adfecdb00588c24 to your computer and use it in GitHub Desktop.
Save MatthewCallis/e02befb6ec83a7df8adfecdb00588c24 to your computer and use it in GitHub Desktop.
Check for broken *.WAV Files
// npm install @uttori/audio-wave
// UTTORI_AUDIOWAV_DEBUG=1 DEBUG=AudioWAV node wav-checker.js
const path = require('path');
const { readdir, readFile } = require('fs').promises;
const { AudioWAV } = require('@uttori/audio-wave');
async function* getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
for (const dirent of dirents) {
const res = path.resolve(dir, dirent.name);
if (dirent.isDirectory()) {
yield* getFiles(res);
} else {
yield res;
}
}
}
;(async () => {
for await (const file of getFiles('.')) {
if (file[0] !== '.' && path.extname(file).toLowerCase() === '.wav') {
try {
console.log(file);
const data = await readFile(file);
const { chunks } = AudioWAV.fromFile(data);
} catch (error) {
console.error(file, error);
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment