{"id":15093485,"url":"https://github.com/wpdas/wave-header","last_synced_at":"2025-04-19T18:20:55.515Z","repository":{"id":77498475,"uuid":"224347750","full_name":"wpdas/wave-header","owner":"wpdas","description":"Generates, Reads and Rewrites a WAVE-file header.","archived":false,"fork":false,"pushed_at":"2020-05-11T19:34:48.000Z","size":13,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-17T20:16:06.168Z","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/wpdas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-27T04:57:55.000Z","updated_at":"2024-10-10T03:37:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"2331629e-788b-468b-93b8-ee8c2bfec63e","html_url":"https://github.com/wpdas/wave-header","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.25,"last_synced_commit":"070a5a742a41acdc7484c93186252f0822faa204"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpdas%2Fwave-header","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpdas%2Fwave-header/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpdas%2Fwave-header/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wpdas%2Fwave-header/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wpdas","download_url":"https://codeload.github.com/wpdas/wave-header/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227001705,"owners_count":17715621,"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-09-25T11:23:36.117Z","updated_at":"2024-11-28T22:42:12.033Z","avatar_url":"https://github.com/wpdas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wave-header\n\nUsing this module you can generate, read and rewrite a WAVE-file header. It's very useful for fix wav file headers as well.\n\nI developed this module with a purpose to fix wav files generated by FFmpeg using stream. It's well-known that every wav files that was generated by FFmpeg in a stream has an issue with its header information, and the final file presents issue with the total time (00:00). This module will definitely fix this issue.\n\nYou can use this module for many others purposes, of course.\n\n## Examples\n\nGenerating a WAVE-file header buffer:\n\n```js\nconst fs = require('fs');\nconst waveHeader = require('wave-header');\n\nconst fileSize = 141971546;\n\n// Options: (length, {channels: 1, sampleRate: 44100, bitDepth: 16})\nconst fileHeaderBuffer = waveHeader.generateHeader(fileSize, { bitDepth: 16 });\n```\n\nReading a WAVE-file header from buffer chunk:\n\n```js\nconst { promises } = require('fs');\nconst waveHeader = require('wave-header');\n\nconst HEADER_OFFSET = 44;\n\npromises\n  // Read only the head chunk from the audio file (better performance and reliability)\n  .readFile('my-wav-file.wav', { start: 0, end: HEADER_OFFSET })\n  .then(bufferChunk =\u003e {\n    const header = waveHeader.readHeader(bufferChunk);\n    console.log(header);\n    /**\n     { \n        riffHead: 'RIFF',\n        fileSize: 4294967295,\n        waveHead: 'WAVE',\n        fmtHead: 'fmt ',\n        formatLength: 16,\n        audioFormat: 1,\n        channels: 1,\n        sampleRate: 44100,\n        byteRate: 88200,\n        blockAlign: 2,\n        bitDepth: 16,\n        data: 'LIST',\n        dataLength: 130\n    }\n    */\n  });\n```\n\nRewriting the header of an issued audio file in real time using stream process. You can use this example when you're using FFmpeg to get wav streamed file and fix the header:\n\n```js\nconst { promises, createReadStream, createWriteStream } = require('fs');\nconst waveHeader = require('wave-header');\n\nconst audioFileWithHeaderIssueDir = 'my-wav-file-with-header-issue.wav';\nlet firstChunkRead = false;\n\nfunction fixAudioHeader(fileSize) {\n  const newHeaderBuffer = waveHeader.generateHeader(fileSize, {\n    bitDepth: 16\n  });\n\n  // Final file with header fixed\n  const writeStream = createWriteStream('my-wav-file-with-fixed-header.wav');\n\n  createReadStream(audioFileWithHeaderIssueDir).on('data', buffer =\u003e {\n    // WARNING: Rewrites the header information in a chunk of buffer. Must be used the first chunk of buffer from a .wav file.\n    if (!firstChunkRead) {\n      writeStream.write(\n        waveHeader.rewriteHeaderInBufferChunk(newHeaderBuffer, buffer)\n      );\n      firstChunkRead = true;\n    } else {\n      writeStream.write(buffer);\n    }\n  });\n}\n\npromises.stat(audioFileWithHeaderIssueDir).then(stats =\u003e {\n  fixAudioHeader(stats.size);\n});\n```\n\n## Well to know\n\nIf you want to use similar process above with AWS.S3, you may want to use `stream.PassThrough` to write the fixed buffer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwpdas%2Fwave-header","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwpdas%2Fwave-header","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwpdas%2Fwave-header/lists"}