Last active
January 19, 2021 03:55
-
-
Save MatthewCallis/e02befb6ec83a7df8adfecdb00588c24 to your computer and use it in GitHub Desktop.
Check for broken *.WAV Files
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
// 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