我正在使用Javascript中的AMR编解码器,我似乎无法获得解码器模块可识别的文件引用。以下是我的代码示例:
reader.onload = (function (file) {
return function (e) {
var extension = file.name.split(".")[1];
if (extension === "amr") {
console.log("in try");
var stuff = e.target.result;
console.log(stuff.length);
var jigg = new AMR();
jigg.benchmark == 'true';
console.log(jigg); //jigg is defined, it's an instance of amr
// let's call some amr functions...
var dcoded = jigg.decode(stuff);
AMR.util.play(dcoded); //this throws an 'undefined' error, indicating that 'dcoded' is undefined.
} else if (extension == "wav") {
var data = e.target.result;
encodeWAV(data);
} else if (extension == "pcm" && isTypedArray) {
encodeRawPCM(new Int16Array(e.target.result));
}
};
})(f);
if ( !! isTypedArray) {
reader.readAsArraybuffer(f);
return;
}
// Read the file as a Binary String
reader.readAsBinaryString(f);
}
我已经评论了发生故障的地方。
AMR.util.play(dcoded);