{"id":26607325,"url":"https://github.com/clumsycomputer/clumsy-wav","last_synced_at":"2025-04-09T21:05:46.664Z","repository":{"id":61608031,"uuid":"553107485","full_name":"clumsycomputer/clumsy-wav","owner":"clumsycomputer","description":"functions for generating .wav file data 🔉","archived":false,"fork":false,"pushed_at":"2022-11-19T01:50:19.000Z","size":10,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"stable","last_synced_at":"2025-04-09T21:05:41.772Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clumsycomputer.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}},"created_at":"2022-10-17T18:18:12.000Z","updated_at":"2023-04-13T09:54:33.000Z","dependencies_parsed_at":"2023-01-22T22:15:35.729Z","dependency_job_id":null,"html_url":"https://github.com/clumsycomputer/clumsy-wav","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clumsycomputer%2Fclumsy-wav","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clumsycomputer%2Fclumsy-wav/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clumsycomputer%2Fclumsy-wav/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clumsycomputer%2Fclumsy-wav/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clumsycomputer","download_url":"https://codeload.github.com/clumsycomputer/clumsy-wav/tar.gz/refs/heads/stable","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111982,"owners_count":21049578,"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":"2025-03-23T22:50:39.166Z","updated_at":"2025-04-09T21:05:46.632Z","avatar_url":"https://github.com/clumsycomputer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clumsy-wav\n\nfunctions for generating .wav file data 🔉\n\n## tl;dr\n\ngenerate a three-second wav file of a 440hz sine wave at 48000 samples per second\n\n```typescript\nimport { getWavBuffer } from \"clumsy-wav\";\n\nconst lengthOfAudioInSeconds = 3;\nconst sampleRate: SampleRate = 48000;\nconst sampleCount = lengthOfAudioInSeconds * sampleRate;\nconst channelsData: MonoChannelsData = [\n  new Array(sampleCount).fill(undefined).map((_, sampleIndex) =\u003e {\n    const waveFrequency = 440;\n    const frequencySampleRateScalar = sampleCount / sampleRate;\n    const angleStep = (2 * Math.PI) / sampleRate;\n    const sampleAngle = sampleIndex * angleStep;\n    return Math.sin(waveFrequency * frequencySampleRateScalar * sampleAngle);\n  }),\n];\nconst wavBuffer = getWavBuffer(sampleRate, channelsData);\n```\n\n### play wav file\n\n```typescript\n// within some async onClick handler\nconst audioContext = new AudioContext({\n  sampleRate,\n});\nconst audioSourceNode = new AudioBufferSourceNode(currentAudioContext);\naudioSourceNode.buffer = await audioContext.decodeAudioData(wavBuffer.slice(0));\naudioSourceNode.connect(audioContext.destination);\naudioSourceNode.start();\n```\n\n### download wav file\n\n```typescript\n// within some onClick handler\nconst wavFile = new Blob([wavBuffer], {\n  type: \"audio/wav\",\n});\nconst wavUrl = URL.createObjectURL(wavFile);\nconst tempAnchor = document.createElement(\"a\");\ntempAnchor.href = wavUrl;\ntempAnchor.download = \"sine440.wav\";\ntempAnchor.click();\nURL.revokeObjectURL(wavUrl);\n```\n\n## installation\n\n```bash\nyarn add clumsy-wav\n```\n\n## resources\n\n- [Wav File Spec](http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html)\n\n- [Wav Notes](https://gist.github.com/endolith/e8597a58bcd11a6462f33fa8eb75c43d)\n\n- [Wav Reference Implementation](https://github.com/Jam3/audiobuffer-to-wav/blob/2272eb09bd46a05e50a6d684d908aa6f13c58f63/index.js#L18)\n\n- [PCM and Wav Relation](https://stackoverflow.com/a/21159699)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclumsycomputer%2Fclumsy-wav","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclumsycomputer%2Fclumsy-wav","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclumsycomputer%2Fclumsy-wav/lists"}