如何从音频网址中绘制分析器?
我从API服务器获取音频网址(http://api.server.com/uploads/files/ecae64b511b1266fa3930731ec379d2dcdcc7546.wav
)。我想在画布上绘制这个声音,跟随函数在blob对象上工作(从suer录制),但它不适用于url:
$window.AudioContext = $window.AudioContext || $window.webkitAudioContext;
vm.audioContext = new AudioContext();
function gotStream(stream) {
vm.inputPoint = vm.audioContext.createGain();
vm.realAudioInput = vm.audioContext.createMediaStreamSource(stream);
vm.audioInput = vm.realAudioInput;
vm.audioInput.connect(vm.inputPoint);
// audioInput = convertToMono( input );
vm.analyserNode = vm.audioContext.createAnalyser();
vm.analyserNode.fftSize = 2048;
vm.inputPoint.connect(vm.analyserNode);
vm.audioRecorder = new Recorder(vm.inputPoint);
var zeroGain = vm.audioContext.createGain();
zeroGain.gain.value = 0.0;
vm.inputPoint.connect(zeroGain);
zeroGain.connect(vm.audioContext.destination);
updateAnalysers();
}
答案 0 :(得分:0)
如果文件来自与代码不同的来源,这可能是一个CORS问题。如果你不解决这个问题,MediaStreamSource可能只会输出零。