{"id":17087844,"url":"https://github.com/geraintluff/ndarray-wav","last_synced_at":"2025-10-18T20:24:56.432Z","repository":{"id":16371160,"uuid":"19121474","full_name":"geraintluff/ndarray-wav","owner":"geraintluff","description":"Read WAV files into ndarray","archived":false,"fork":false,"pushed_at":"2015-11-23T13:07:42.000Z","size":10,"stargazers_count":11,"open_issues_count":1,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-03T11:39:04.242Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geraintluff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-24T19:37:03.000Z","updated_at":"2022-09-23T09:09:32.000Z","dependencies_parsed_at":"2022-09-13T11:01:42.262Z","dependency_job_id":null,"html_url":"https://github.com/geraintluff/ndarray-wav","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/geraintluff/ndarray-wav","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geraintluff%2Fndarray-wav","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geraintluff%2Fndarray-wav/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geraintluff%2Fndarray-wav/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geraintluff%2Fndarray-wav/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geraintluff","download_url":"https://codeload.github.com/geraintluff/ndarray-wav/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geraintluff%2Fndarray-wav/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259731036,"owners_count":22902958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T13:35:07.252Z","updated_at":"2025-10-18T20:24:56.340Z","avatar_url":"https://github.com/geraintluff.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ndarray-wav\n\nRead/write RIFF WAVE files as ndarrays.\n\n## Supported formats\n\nCurrently supported formats (for read and write) are:\n* 16-bit linear (CD standard)\n* 24-bit linear (CD standard)\n* 32-bit IEEE floating-point\n\nAdding new (uncompressed) sample formats is relatively easy, though, so if you need one just raise an issue on GitHub and I'll put in.\n\n## API\n\n### Reading\n\n```javascript\nvar ndarrayWav = require('ndarray-wav');\n\nndarrayWav.open('input.wav', function (err, chunkMap, chunkArr) {\n    var format = chunks.fmt;\n    var ndSamples = chunks.data; // the wave data as an ndarray\n    assert(format.channels == ndSamples.shape[0]);\n    var numSamples = arr.shape[1];\n});\n```\n\nRegardless of the sample format of the WAV file itself, the data is always returned as floating-point.\n\n### Writing\n\n```javascript\nndarrayWav.write('output.wav', ndSamples, format, function (error) {...});\n```\n\nIn the `write()` method, `format` is optional.  If omitted, it defaults to 44100Hz. 16-bit audio.\n\nThe structure of `format` is the same as `chunkMap.fmt` when you read:\n\n```javascript\nvar format = {\n\tsampleRate: 44100,\n\tformat: 1, // 1 is the default \"linear\" format (two's complement integer), 3 is floating-point.\n\tbitsPerSample: 16, //\n\textraChunks: {...}\n};\n```\n\nAll properties are optional.\n\n## What's all this about \"chunks\"?\n\nWAV files are organised into chunks.  Each is labelled with a four-character ID - the main ones are `\"fmt \"` and `\"data\"`.\n\nWhen reading, this ID is stripped of whitespace and placed in `chunkMap` (second argument in callback).  Additionally, `chunkArr` is an array that holds the same chunks in the order they appeared in the file (where each entry has two keys `\"id\"` and `\"data\"`).\n\nThere are built-in parsers for `fmt` and `data` chunks.  This means that the format will always be available (parsed) as `chunkMap.fmt`, and the wave data is in `chunkMap.data`.\n\nWhen writing `extraChunks` can contain additional chunks to write (e.g. `bext`).  It can be an object (like `chunkMap`) that maps IDs to Buffers, or if order is important it can be an array (like `chunkArr`).\n\n### Chunk parsers\n\nYou can add parsers for particular types of chunk (e.g. `bext` for the broadcast-extension chunk).  It works like this:\n\n```javascript\nndarrayWav.addChunkParser('bext', function (buffer) {\n    return buffer.toString('ascii');\n});\n```\n\nYou can register more than one parser for a particular type of chunk.  If you return something true-ish, then it stops, otherwise it continues.  Parsers are tried in reverse order (most recently-registered first).\n\nThis is actually the mechanism that is used to parse the format and wave data (`fmt` and `data`).\n\n## Thanks\n\nThanks to Chinmay Pendharkar [(notthetup)](https://github.com/notthetup) for 24-bit write support plus some other details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeraintluff%2Fndarray-wav","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeraintluff%2Fndarray-wav","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeraintluff%2Fndarray-wav/lists"}