0

I am using SoundJS from CreateJS and I was wondering, is there anyway I can get the raw (hex) data of an audio playing? I am adding a custom header into the audio file for lip syncing characters but I don't know how to get the audio's raw Hex Data.

I've tried looking in _playbackResource but nothing.

var instance = playSound(whichTalkie);
console.log(instance._playbackResource);

I need the raw audio data. How do I solve the problem?

WindowsTV
  • 1
  • 2

1 Answers1

0

I assume you mean that you want the raw AudioBuffer that is loaded.

There is no official way to do this in SoundJS 1.0 (we are exposing a lot more in 2.0, which you can see in the in-progress branch in Git).

However, you can access all the buffers that are loaded using:

var plugin = createjs.Sound.activePlugin; // The WebAudioPlugin
var buffer = plugin._audioSources[url];

Additionally, there is even more info, including the raw Array Buffer, buried in the load items that SoundJS stores.

var loader = plugin._loaders[url];
var buffer = loader.rawResult;

Unfortunately there is no clean way to get the buffer from a sound instance.

You listen to the "fileload" event, you can get the src directly from the event:

createjs.Sound.on("fileload", handleFileLoad);
  createjs.Sound.registerSound("https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/MK21.mp3", "music");
function handleFileLoad(event) {
    var src = event.src;
    // Use whatever approach to get the Array or Audio buffer
}

Or get the src from a play() call:

var inst = createjs.Sound.play("music");
var src = inst.src;

I hope that helps!

Lanny
  • 11,244
  • 1
  • 22
  • 30
  • The rawResult you've mentioned seemed like what I needed but everytime it would come up as undefined. I think the raw AudioBuffer is what I'm looking for. To try to clarify I want to be able to view the audio file's data as text(to where headers can be visible in the file like a WAV has the RIFF header). So that way when CreateJS/SoundJS loads in all ot the talking files I can get their data and find my custom headers that will store custom info. – WindowsTV Aug 09 '19 at 01:07