我想到了。
我做的第一件事是将示例 javascript 放入一个对象中。这是我正在使用的记录功能:
record: function() {
this.data = [];
this.poll = '';
Recorder.record({
start: function () {
alert("recording starts now. press stop when youre done. and then play or upload if you want.");
},
progress: function (milliseconds) {
document.getElementById("time").innerHTML = Voiceover.timecode(milliseconds);
}
});
this.waveform = new Waveform({
container: document.getElementById("voiceover_waveform"),
interpolate: false
});
var ctx = this.waveform.context;
var gradient = ctx.createLinearGradient(0, 0, 0, this.waveform.height);
gradient.addColorStop(0.0, "#f60");
gradient.addColorStop(1.0, "#ff1b00");
this.waveform.innerColor = gradient;
var i=0;
this.poll = setInterval(function() {
Voiceover.data.push(Recorder.PollAudioBuffer());
Voiceover.waveform.update({
data: Voiceover.data
});
}, 70);
},
这会初始化波形并设置 70ms 的间隔来轮询记录器以获取新数据点并将其绘制在波形上。
在recorder.js
中,我添加了以下功能:
PollAudioBuffer: function() {
try {
var poll = this.flashInterface().pollAudioBuffer();
console.log(poll);
if(poll < 0.15) {
// Messing around with the math a bit to improve the effect.
// The final result just has to be between 0 and 1.
poll = Math.floor((Math.random()*1.5)+1)/10;
}
return poll;
}
catch(error) {
console.log(error);
}
},
现在到动作脚本。在Recorder.as
中,我添加了我的pollAudioBuffer()
函数,现在实际上有点名不副实。
protected function pollAudioBuffer():Number
{
return (microphone.activityLevel*2)/100;
}
要使函数正常工作,您需要在addExternalInterfaceCallbacks()
in 中添加回调引用Recorder.as
:
ExternalInterface.addCallback("pollAudioBuffer",this.pollAudioBuffer);
这些更改使我能够即时创建波形。希望这对其他人有帮助。