我有某些TCP
包含音频数据的数据包。
我是 Js 和 html5 的新手。
我写过这样的东西,它会发出嗡嗡声。TCP
我想知道音频样本在数据包中的样子。
我使用wire-shark捕获了TCP
数据包,数据段显示了一些字符及其ASCII值。
我相信这些字符是音频数据。假设是这样,我怎样才能将这些传递给myArrayBuffer
下面的喜欢?
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var source = audioCtx.createBufferSource();
function Set1()
{
try {
// Create an empty three-second stereo buffer at the sample rate of the AudioContext
var myArrayBuffer = audioCtx.createBuffer(2, audioCtx.sampleRate * 30, audioCtx.sampleRate);
// Fill the buffer with white noise;
// just random values between -1.0 and 1.0
for (var channel = 0; channel < myArrayBuffer.numberOfChannels; channel++) {
// This gives us the actual array that contains the data
var nowBuffering = myArrayBuffer.getChannelData(channel);
for (var i = 0; i < myArrayBuffer.length; i++) {
// Math.random() is in [0; 1.0]
// audio needs to be in [-1.0; 1.0]
nowBuffering[i] = Math.random() * 2 - 1;
}
}
// set the buffer in the AudioBufferSourceNode
source.buffer = myArrayBuffer;
// connect the AudioBufferSourceNode to the
// destination so we can hear the sound
source.connect(audioCtx.destination);
// start the source playing
source.start();
}
catch(e) {
alert('Web Audio API is not supported in this browser');
}
}
function stop()
{
try {
source.stop();
}
catch(e) {
alert('Unable to stop file');
}
}