简体   繁体   English

有没有办法从SoundJS中的声音中获取原始数据以读取自定义标头?

[英]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? 我正在使用CreateJS的SoundJS,我想知道,是否还能获得音频播放的原始(十六进制)数据? 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. 我试过在_playbackResource查找,但是什么也没有。

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. 我假设您的意思是您要加载原始的AudioBuffer

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 ). 在SoundJS 1.0中没有官方的方法可以做到这一点(我们将在2.0中进行更多介绍,您可以在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. 此外,SoundJS存储的加载项中还包含更多信息,包括原始数组缓冲区。

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: 您监听“ fileload”事件,可以直接从该事件获取src:

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: 或者从play()调用获取src:

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

I hope that helps! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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