显然,Safari的分析器节点没有getFloatTimeDomainData方法Here you can see the error。我正在寻找一个类似的功能,该功能可以将当前波形或时域数据复制到Float32Array中,并且可以在safari的浏览器中使用。
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var buflen = 1024;
var buf = new Float32Array( buflen );
audioContext = new AudioContext();
MAX_SIZE = Math.max(4,Math.floor(audioContext.sampleRate/5000));
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
navigator.mediaDevices.getUserMedia({audio: true})
.then(function(stream) {
gotStreamPre(stream);
});
function gotStreamPre(stream) {
// Create an AudioNode from the stream.
mediaStreamSource = audioContext.createMediaStreamSource(stream);
// Connect it to the destination.
analyser = audioContext.createAnalyser();
analyser.fftSize = 2048;
mediaStreamSource.connect( analyser );
updatePitchPre();
}
function updatePitchPre( time ) {
if(analyser!=null){
var cycles = new Array;
analyser.getFloatTimeDomainData( buf );//not working on Safari
var ac = autoCorrelatePre( buf , audioContext.sampleRate );
if (ac > -1) {
}
if (!window.requestAnimationFrame)
window.requestAnimationFrame = window.webkitRequestAnimationFrame;
rafID = window.requestAnimationFrame( updatePitchPre );
}
}
答案 0 :(得分:0)
我有同样的问题,你可以添加这个:
if (analyser && !analyser.getFloatTimeDomainData) {
var r = new Uint8Array(2048);
analyser.getFloatTimeDomainData = function(e) {
analyser.getByteTimeDomainData(r);
for (var t = 0, o = e.length; o > t; t++) e[t] = .0078125 * (r[t] - 128)
}
}