{"id":16132699,"url":"https://github.com/sbrl/soundbox","last_synced_at":"2025-03-16T09:32:52.832Z","repository":{"id":27433629,"uuid":"30911540","full_name":"sbrl/soundbox","owner":"sbrl","description":":speaker: :notes: A super simple JS library for playing sound effects :headphones: :musical_keyboard:","archived":false,"fork":false,"pushed_at":"2023-12-05T22:25:50.000Z","size":431,"stargazers_count":39,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T13:18:32.951Z","etag":null,"topics":["html","javascript","js-library","sound","web-audio-library"],"latest_commit_sha":null,"homepage":"https://sbrl.github.io/soundbox/example.html","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/sbrl.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":"2015-02-17T10:03:09.000Z","updated_at":"2024-03-20T11:13:29.000Z","dependencies_parsed_at":"2024-10-09T22:33:10.209Z","dependency_job_id":"dc852880-6a8d-4e28-9147-1f41a99aa4e1","html_url":"https://github.com/sbrl/soundbox","commit_stats":{"total_commits":95,"total_committers":8,"mean_commits":11.875,"dds":"0.19999999999999996","last_synced_commit":"8cdf5ffeb71d99ad56944b977906d03f8b4420d6"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsoundbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsoundbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsoundbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbrl%2Fsoundbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbrl","download_url":"https://codeload.github.com/sbrl/soundbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221661653,"owners_count":16859563,"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":["html","javascript","js-library","sound","web-audio-library"],"created_at":"2024-10-09T22:32:59.357Z","updated_at":"2024-10-27T10:18:48.920Z","avatar_url":"https://github.com/sbrl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# soundbox\nA super simple JS library for playing sound effects and other audio.\n\n![npm package size](https://img.shields.io/bundlephobia/min/sound-box.svg) | ![minified + gzipped size](https://badgen.net/bundlephobia/minzip/sound-box)\n\n## Demo\nCheck it out in action with the [Online Demo](https://sbrl.github.io/soundbox/example) (see also the [Real-World Usage](#real-world-usage) section :D)!\n\n### Running Demo Locally\nThe demo can also be run locally. Clone this repository, and then run the following from the root of this repo:\n\n```\nnpm install\nnpm run demo\n```\n\n## Quick example:\n\n```javascript\nvar soundbox = new SoundBox();\nsoundbox.load(\"beep-a\", \"beep-a.wav\")\n    .then(\n        () =\u003e console.log(\"Loaded beep a!\"),\n        () =\u003e console.error(\"Failed to load keep a :-(\")\n    );\nsoundbox.load(\"beep-b\", \"beep-b.wav\");\nsoundbox.load(\"beep-c\", \"beep-c.wav\");\nsoundbox.load(\"victory\", \"victory.mp3\");\n\nsoundbox.play(\"beep-a\")\n    .then(() =\u003e soundbox.play(\"beep-b\"))\n    .then(() =\u003e soundbox.play(\"beep-c\"))\n    .then(() =\u003e soundbox.play(\"victory\"));\n    \n// The 3rd parameter is the volume: The callback can be omitted to enable promise mode\nsoundbox.play(\"beep\", null, 0.8)\n    .then(() =\u003e soundbox.play(\"victory\"))\n```\n\n_(Full documentation below)_\n\n\n## Download\nThe recommended way to obtain soundbox is via [npm](https://npmjs.org/) here: [sound-box](https://www.npmjs.com/package/sound-box) - To install it simply type `npm install sound-box`. Then you can include any of the 4 files described below from the `./node_modules/sound-box/` directory.\n\nIf npm isn't for you, then the latest master should be perfectly stable. If you want something that you know will work, try the latest [release](https://github.com/sbrl/soundbox/releases).\n\nThe following files are available via all release methods:\n * [soundbox.js](https://raw.githubusercontent.com/sbrl/soundbox/master/soundbox.js) - The main development version.\n * [soundbox.min.js](https://raw.githubusercontent.com/sbrl/soundbox/master/soundbox.min.js) - A minified version of the above.\n * [soundbox.jsm](https://raw.githubusercontent.com/sbrl/soundbox/master/soundbox.jsm) - An ES6 module-compatible version that's autogenerated. If you possibly can, I'd advise learning about about them. [This is a useful resource](https://jakearchibald.com/2017/es-modules-in-browsers/).\n * [soundbox.jsm](https://raw.githubusercontent.com/sbrl/soundbox/master/soundbox.min.jsm) - A minified version of the above.\n\n\n## Usage\n\n### Create a new instance:\n\n```javascript\nvar soundbox = new SoundBox();\n```\n\n### Load a sound\nSound loading is done as follows. If a callback is not specified, promise mode is activated.\n\n```javascript\n// Promise mode\nsoundbox.load(\"alias\", \"path/to/filename\").then(\n    () =\u003e console.log(\"Loaded beep!\"),\n    () =\u003e console.error(\"Failed to load beep :-(\")\n);\nsoundbox.load(\"victory\", \"./sounds/yay.wav\").then( /* .... */);\n```\n\n```javascript\n// Callback mode\nsoundbox.load(\"alias\", \"path/to/filename\", function() {\n    console.log(\"Loaded beep!\");\n});\n```\n\n### Play a sound\nSimilarly, playing a sound takes 2 forms: callback and promise.\n\n```javascript\n// Promise mode\nsoundbox.play(\"beep-a\")\n    .then(() =\u003e soundbox.play(\"beep-b\")) /* The .then() is optional of course */\n    .then(() =\u003e soundbox.play(\"beep-c\"))\n    .then(() =\u003e soundbox.play(\"victory\"));\n```\n\n```javascript\n// Callback mode\nsoundbox.play(\"beep\", function() {\n\t// Do stuff\n});\n```\n\n#### Specify the volume\nThe volume can be specified when playing a sound, too. The volume should be a floating-point number between 0 (silent) and 1 (full volume, default).\n\nHere's how:\n\n```javascript\n// Promise mode\nsoundbox.play(\"beep-a\", null, 0.8)\n    .then(() =\u003e /* .... */);\n```\n\n```javascript\n// Callback mode\nsoundbox.play(\"beep\", function() {\n\t// Do stuff\n}, 0.5);\n```\n\n### Specify the default volume\nIf you'd like to change the default volume that sounds are played at, do this:\n\n```javascript\nsoundbox.default_volume = 0.45; // Sets the default volume to 45%\n```\n\n#### Looping again and again\nAs of v0.3.7, looping support has been added. Use it like this:\n\n```javascript\n// Promise mode\nsoundbox.play(\"rocket\", null, 0.8, true)\n    .then(() =\u003e /* .... */);\n```\n\n```javascript\n// Callback mode\nsoundbox.play(\"rocket\", function() {\n\t// Do stuff\n}, null, true); // A null volume = use the default volume. Supported in both modes of operation\n```\n\n### Stop all sounds\nYou can stop all currently playing sounds like this:\n\n```javascript\nsoundbox.stop_all();\n```\n\n### Unload a sound\nIf you want to, you can unload a sound:\n\n```javascript\nsoundbox.remove(\"sound_alias\");\nsoundbox.remove(\"oops\");\n```\n\n### Get the current version\nGet the current version of SoundBox:\n\n```javascript\nconsole.log(`Soundbox is at ${SoundBox.version}`);\n```\n\n\n## Changelog\n - **v1.0.0:** This has to be stable by now! Also switch to `alive-server` in dev dependencies to fix security issues - long live forks!\n - **v0.3.10:** Bugfix: Don't skip playback if the volume is set to 0 ([#10](https://github.com/sbrl/soundbox/pull/10), thanks @matthewoates!) - **v0.3.9:** Documentation release. Use badges to show size.\n - **v0.3.8:** Add optional `loop` parameter to `.play()`\n - **v0.3.7:** Update changelog in README\n - **v0.3.6:** Fix `main` definition in `package.json`\n - **v0.3.5:** Update from `.jsm` to `.mjs` for file extension\n - **v0.3.4:** Fix another bug in `.stop_all()`\n - **v0.3.3:** Fix a bug in `.stop_all()`\n - **v0.3.2:** Added `.stop_all()` and `default_volume`\n - **v0.3.1:** Added non-es6 version and build system to automate minification.\n - **v0.3:** Added volume support! Converted for use as an ES6 module. If this doesn't suit you, then just remove the `import` and `export` statements to make it the way it was before.\n - **v0.2:** Now with button mashing support!\n\n\n\n## Real-World Usage\n - @MyTheValentinus has [created a mobile web app for playing sound-effects and other sounds](https://github.com/MyTheValentinus/soundbox)\n - @kdallas has used it as part of a [100 movies list](https://www.weblabsperth.com.au/100-movies/)\n - ...? _(Are you using soundbox? Let me know by opening an issue or contacting me and I'll add your project here!)_\n\n\n## Contributing\nContributions are welcome! Please mention that you release your contribution under the MIT license (see below) in your PR message.\n\nEdits should be made to `soundbox.js` - the other 3 are automatically generated by the bash-based build script `build`, which is located in the root of this repository.\n\n\n## License\nSoundBox.js is licensed under MIT:\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2015 Starbeamrainbowlabs\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbrl%2Fsoundbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbrl%2Fsoundbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbrl%2Fsoundbox/lists"}