https://github.com/reececomo/assetpack-plugin-audiosprite
🗜️ Powerful audiosprite compression for sound assets
https://github.com/reececomo/assetpack-plugin-audiosprite
Last synced: 5 months ago
JSON representation
🗜️ Powerful audiosprite compression for sound assets
- Host: GitHub
- URL: https://github.com/reececomo/assetpack-plugin-audiosprite
- Owner: reececomo
- Created: 2024-06-19T05:23:31.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-19T07:07:13.000Z (about 2 years ago)
- Last Synced: 2025-10-04T10:52:56.844Z (9 months ago)
- Language: JavaScript
- Homepage: https://npmjs.com/assetpack-plugin-audiosprite
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🙉 assetpack-plugin-audiosprite [](https://www.npmjs.com/package/assetpack-plugin-audiosprite)
[AssetPack](https://github.com/pixijs/assetpack) plugin for generating audio sprites using [audiosprite](https://github.com/tonistiigi/audiosprite).
### Installation
```
npm install assetpack-plugin-audiosprite --save-dev
```
> [!IMPORTANT]
> Requires `ffmpeg` to be installed in PATH
> [!NOTE]
> Using a fork of `audiosprite`? Just switch to the `v0.8.0+custom-audiosprite` branch:
>
> ```js
> "devDependencies": {
> "assetpack-plugin-audiosprite": "reececomo/assetpack-plugin-audiosprite#v0.8.0+custom-audiosprite",
> "audiosprite": "",
> // ...
> },
> ```
## Basic usage
Use the `{audiosprite}` tag (or set your own) to combine a directory of audio files into a single audiosprite.
```js
// .assetpack.js
const { audiosprite } = require('assetpack-plugin-audiosprite');
module.exports = {
entry: './raw-assets/',
output: './assets/',
plugins: {
audiosprite: audiosprite(),
},
};
```
### Options
```js
audiosprite({
// use a custom tag (default: 'audiosprite')
tags: { audiosprite: 'sfx' },
// whether assets are nested in their namespace "abc/abc.json" (default: true)
nested: false,
// limit which sound files should be imported
imports: ['aac', 'ac3', 'aiff', 'caf', 'flac', 'mp3',
'mp4', 'm4a', 'ogg', 'opus', 'wav', 'webm'],
// modify emitted JSON data
outputJson: {
path: undefined,
extension: '.json',
minify: true,
transform: (jsonData, jsonPath, resourcePaths) => jsonData,
},
// any option that can be passed to Audiosprite can be passed here.
audiosprite: {
export: 'ogg,mp3',
bitrate: 64,
samplerate: 32_000,
channels: 1,
// ...
}
})
```
## Example - [PixiJS SoundSprite](https://pixijs.io/sound/docs/SoundSprite.html)
Given these files:
```
assets/
sound_effects{audiosprite}/
cry.wav
laugh.mp3
sneeze.ogg
```
You can import packed assets like so:
```ts
import { Assets } from 'pixi.js';
// load assets
const myJson = await Assets.load('assets/sound_effects.json');
const mySound = await Assets.load('assets/sound_effects.{ogg,m4a,mp3,ac3}');
mySound.addSprites(myJson.spritemap);
// play sounds
mySound.play('cry');
```
> [!IMPORTANT]
> Combine with the `sound` utility from `@pixi/sound` for features like independent volume control.
```ts
import { sound } from '@pixi/sound';
// or use @pixi/sound 'sound' for features like independent volume control
sound.add('sound_effects', mySound);
sound.play('sound_effects', {
sprite: 'cry',
volume: 0.5,
});
```