我在浏览器上播放PCM Audio时遇到了一些问题.PCM音频来自具有udp协议的Android设备,并以*.raw保存在服务器上
我在webaudioapi的帮助下试图播放这个保存的文件失败了.使用以下代码,播放一些带有白噪声的令人毛骨悚然的声音:
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
audioCtx.sampleRate = 16000;
// Stereo
var channels = 1;
// Create an empty two second stereo buffer at the
// sample rate of the AudioContext
var frameCount = audioCtx.sampleRate * 10.0;
var myAudioBuffer = audioCtx.createBuffer(channels, frameCount, audioCtx.sampleRate);
var req = new XMLHttpRequest();
req.open('GET', "example.raw", false);
req.overrideMimeType('text\/plain; charset=x-user-defined');
req.send(null);
function play(){
for (var channel = 0; channel < channels; channel++) {
var nowBuffering = myAudioBuffer.getChannelData(channel,16,16000);
for (var i = 0; i …Run Code Online (Sandbox Code Playgroud)