简体   繁体   中英

Is there a way to get the raw data from a sound in SoundJS for reading custom headers?

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM