Skip to content

Generating AudioSprites with Audacity

Matt Karl edited this page Apr 20, 2019 · 4 revisions

Here’s a brief tutorial for generating audio sprites from Audacity instead of manually creating the start and end times by hand.

Steps

  1. Download Audacity it’s free and open-source.

  2. Open your audio file in Audacity

  3. Select and highlight a region you want to make a sprite image

  4. Use key ctrl+B (Windows or Linux) command+B (macOS) to add label regions. Give it a name. image

  5. Repeat the process for other regions. You can also adjust the region with shift+click image

  6. Export labels by going to File > Export > Export Labels... image

  7. Convert the labels text file to valid JSON for pixi-sound using this NodeJS Script:

convert.js

const data = require('fs').readFileSync(process.argv[2], 'utf8');
const result = {};
data.split(/[\n\r]+/)
  .filter(line => !!line)
  .map(line => line.split('\t'))
  .forEach(([start, end, name]) => result[name] = { start, end });
console.log(JSON.stringify(result, null, '  '));
node convert.js labels-from-audacity.txt

Alternatively, you can use this one-liner.

node -e 'const o={};require("fs").readFileSync(process.argv[1],"utf8").split(/[\n\r]+/).filter(l=>!!l).map(l=>l.split("\t")).forEach(([l,r,t])=>o[t]={start:l,end:r}),console.log(JSON.stringify(o,null,"  "))' labels-from-audacity.txt

Should return an object like this:

{
  "boing_1": {
    "start": "0.225725",
    "end": "0.767466"
  },
  "boing_2": {
    "start": "2.257252",
    "end": "2.988601"
  },
  "boing_3": {
    "start": "4.577707",
    "end": "5.354201"
  },
  "boing_4": {
    "start": "6.871075",
    "end": "7.620482"
  },
  "boing_5": {
    "start": "11.322375",
    "end": "11.864116"
  }
}
  1. Enjoy Sprites with pixi-sound.
Clone this wiki locally