{"id":19531493,"url":"https://github.com/alexanderwallin/super-tiny-wave-decoder","last_synced_at":"2025-04-26T13:31:52.747Z","repository":{"id":57374619,"uuid":"82921171","full_name":"alexanderwallin/super-tiny-wave-decoder","owner":"alexanderwallin","description":"📻  A super tiny WAVE parser and decoder, without any dependencies or unnecessary abstraction layers","archived":false,"fork":false,"pushed_at":"2018-08-21T09:28:05.000Z","size":12,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-07T10:42:49.003Z","etag":null,"topics":["audio","decoder","tiny","wave"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexanderwallin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-23T11:34:36.000Z","updated_at":"2023-11-27T01:03:11.000Z","dependencies_parsed_at":"2022-08-27T13:11:13.235Z","dependency_job_id":null,"html_url":"https://github.com/alexanderwallin/super-tiny-wave-decoder","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderwallin%2Fsuper-tiny-wave-decoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderwallin%2Fsuper-tiny-wave-decoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderwallin%2Fsuper-tiny-wave-decoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderwallin%2Fsuper-tiny-wave-decoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexanderwallin","download_url":"https://codeload.github.com/alexanderwallin/super-tiny-wave-decoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224036391,"owners_count":17245034,"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":["audio","decoder","tiny","wave"],"created_at":"2024-11-11T01:43:08.173Z","updated_at":"2024-11-11T01:43:09.629Z","avatar_url":"https://github.com/alexanderwallin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# super-tiny-wave-decoder\n\n[![npm version](https://badge.fury.io/js/super-tiny-wave-decoder.svg)](https://badge.fury.io/js/super-tiny-wave-decoder)\n\nA super tiny WAVE parser and decoder, without any dependencies or unnecessary abstraction layers.\n\nMost of the logic was directly ported from parts of [aurora.js](https://github.com/audiocogs/aurora.js), so lots of ❤️ from here to there!\n\n**Note:** This is terribly similar to [`wav-decoder`](https://github.com/mohayonao/wav-decoder), which I found after making this. There are some minor differences in the API, but if you're fine with the one in `wav-decoder`, you should probably use that one.\n\n\n## Why?\n\nSometimes I just want to decode WAVE audio. Sometimes I even just want to parse a WAVE header. All libraries I have found have either too much other stuff I don't need, too abstraced APIs (I don't need it to make the HTTP request for me) or is specifically targeted towards either Node or the web browser.\n\nThis library is just a utility that parses WAVE headers and decodes WAVE audio. Nothing more, nothing less.\n\n\n## Installation\n\n```sh\nnpm install --save super-tiny-wave-decoder\n```\n\n\n## Usage\n\n```js\nimport { getWaveHeader, decodeWaveData } from 'super-tiny-wave-decoder'\n\n// Read a wave file somehow\nconst waveContents = readAudioFileAsAnArrayBufferSomehow('sound.wav')\nconst waveData = new Uint8Array(waveContents)\n\n// Get WAVE header\nconst header = getWaveHeader(waveData)\n\n// Get a chunk of 4096 bytes starting after the header and\n// decode that chunk\nconst audioDataChunk = waveData.slice(44, 44 + 4096)\nconst decodedAudio = decodeWaveData(audioDataChunk, header)\n\n// decodedAudio is now a Float32Array ready to be used as an\n// audio buffer\n```\n\n\n## API\n\n### Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#getAsDataView\"\u003egetAsDataView(data)\u003c/a\u003e ⇒ \u003ccode\u003eDataView\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eWraps and returns a typed array or ArrayBuffer in a DataView\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#getString\"\u003egetString(data, offset, bytes, encoding)\u003c/a\u003e ⇒ \u003ccode\u003eString\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eReturns a string read from some data.\u003c/p\u003e\n\u003cp\u003eThis code is directly ported and rewritten from aurora.js\u0026#39;s stream.coffee.\nI have no idea how it works! Might use a library for this if it doesn\u0026#39;t\nwork properly.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#getWaveHeader\"\u003egetWaveHeader(data)\u003c/a\u003e ⇒ \u003ccode\u003eObject\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eParses a chunk of wave data and tries to extract all wave header\ninfo from it.\u003c/p\u003e\n\u003cp\u003eYou can see an overview of the WAVE header format here:\n\u003ca href=\"http://www.topherlee.com/software/pcm-tut-wavformat.html\"\u003ehttp://www.topherlee.com/software/pcm-tut-wavformat.html\u003c/a\u003e\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#getWaveDuration\"\u003egetWaveDuration(header)\u003c/a\u003e ⇒ \u003ccode\u003eNumber\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eReturns the duration of some wave audio given its header info\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#decodeWaveData\"\u003edecodeWaveData(header, data)\u003c/a\u003e ⇒ \u003ccode\u003eFloat32Array\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eDecodes a chunk of wave audio data\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"getAsDataView\"\u003e\u003c/a\u003e\n\n### getAsDataView(data) ⇒ \u003ccode\u003eDataView\u003c/code\u003e\nWraps and returns a typed array or ArrayBuffer in a DataView\n\n**Returns**: \u003ccode\u003eDataView\u003c/code\u003e - A DataView wrapping the passed data  \n**Throws**:\n\n- \u003ccode\u003eTypeError\u003c/code\u003e The passed data needs to be of a supported type\n\n**Params**\n\n- `data`: \u003ccode\u003eMixed\u003c/code\u003e - A DataView, ArrayBuffer, TypedArray or node Buffer\n\n\u003ca name=\"getString\"\u003e\u003c/a\u003e\n\n### getString(data, offset, bytes, encoding) ⇒ \u003ccode\u003eString\u003c/code\u003e\nReturns a string read from some data.\n\nThis code is directly ported and rewritten from aurora.js's stream.coffee.\nI have no idea how it works! Might use a library for this if it doesn't\nwork properly.\n\n**Returns**: \u003ccode\u003eString\u003c/code\u003e - A string  \n**Link**: https://github.com/audiocogs/aurora.js/blob/master/src/core/stream.coffee#L303  \n**Params**\n\n- `data`: \u003ccode\u003eMixed\u003c/code\u003e - A DataView, ArrayBuffer, TypedArray or node Buffer\n- `offset`: \u003ccode\u003eNumber\u003c/code\u003e - An offset in bytes to start read the string from\n- `bytes`: \u003ccode\u003eNumber\u003c/code\u003e - The number of bytes to read\n- `encoding`: \u003ccode\u003eString\u003c/code\u003e - The encoding to parse the text as\n\n\u003ca name=\"getWaveHeader\"\u003e\u003c/a\u003e\n\n### getWaveHeader(data) ⇒ \u003ccode\u003eObject\u003c/code\u003e\nParses a chunk of wave data and tries to extract all wave header\ninfo from it.\n\nYou can see an overview of the WAVE header format here:\nhttp://www.topherlee.com/software/pcm-tut-wavformat.html\n\n**Returns**: \u003ccode\u003eObject\u003c/code\u003e - An object containing the WAVE header info  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e The passed data needs to be at least 44 bytes long\n- \u003ccode\u003eError\u003c/code\u003e The passed data needs to match the WAVE header spec\n\n**Params**\n\n- `data`: \u003ccode\u003eMixed\u003c/code\u003e - A DataView, ArrayBuffer, TypedArray or node Buffer containing WAVE audio data, more specifically the beginning of a WAVE audio file\n\n\u003ca name=\"getWaveDuration\"\u003e\u003c/a\u003e\n\n### getWaveDuration(header) ⇒ \u003ccode\u003eNumber\u003c/code\u003e\nReturns the duration of some wave audio given its header info\n\n**Returns**: \u003ccode\u003eNumber\u003c/code\u003e - The duration of the WAVE audio in seconds  \n**Params**\n\n- `header`: \u003ccode\u003eObject\u003c/code\u003e - A WAVE header object\n\n\u003ca name=\"decodeWaveData\"\u003e\u003c/a\u003e\n\n### decodeWaveData(header, data) ⇒ \u003ccode\u003eFloat32Array\u003c/code\u003e\nDecodes a chunk of wave audio data\n\n**Returns**: \u003ccode\u003eFloat32Array\u003c/code\u003e - A Float32Array containing decoded audio  \n**Throws**:\n\n- \u003ccode\u003eError\u003c/code\u003e The bit depth passed in header must be 8, 16, 24, 32 or 64\n\n**Params**\n\n- `header`: \u003ccode\u003eObject\u003c/code\u003e - A WAVE header object\n- `data`: \u003ccode\u003eMixed\u003c/code\u003e - A DataView, ArrayBuffer, TypedArray or node Buffer containing WAVE audio data\n\n\n\n## Contributing\n\nDo `npm run` to see what's available, and don't be shy sending a pull request!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderwallin%2Fsuper-tiny-wave-decoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexanderwallin%2Fsuper-tiny-wave-decoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderwallin%2Fsuper-tiny-wave-decoder/lists"}