Audio 如何在AS3中将声音对象提取到单字节数组

Audio 如何在AS3中将声音对象提取到单字节数组,audio,actionscript,bytearray,microphone,Audio,Actionscript,Bytearray,Microphone,我正在尝试将声音对象的字节数组前置到捕获的麦克风声音字节数组 它可以工作,但提取的声音对象会被拍摄下来,长度会增加一倍。我猜这是因为声音对象的字节数组是立体声的,而麦克风字节数组是单声道的 我有这个: sound.extract(myByteArray, extract); myByteArray现在包含立体声数据。我怎样才能把它转换成mono(我是ByteArray的新手) 更新: 这里有一个可行的解决方案: existingByte.position = 0; var mono : Byt

我正在尝试将声音对象的字节数组前置到捕获的麦克风声音字节数组

它可以工作,但提取的声音对象会被拍摄下来,长度会增加一倍。我猜这是因为声音对象的字节数组是立体声的,而麦克风字节数组是单声道的

我有这个:

sound.extract(myByteArray, extract);
myByteArray现在包含立体声数据。我怎样才能把它转换成mono(我是ByteArray的新手)

更新:

这里有一个可行的解决方案:

existingByte.position = 0;
var mono : ByteArray = new ByteArray();
while(existingByte.bytesAvailable) {
    var left : Number = existingByte.readFloat();
    mono.writeFloat(left);
    existingByte.position +=4;
}

只需选择一个频道进行提取。我认为ByteArray是交错的,所以如果你选择所有奇数字节,它是左通道,如果你选择所有偶数字节,它是右通道

var mono : ByteArray = new ByteArray();
for( var i : int = 0; i < raw.length; i+=2 ) {
    var left : int = raw[i];
    var right : int = raw[i+1];

    var mixed : int = left * 0.5 + right * 0.5;
    if( pickLeft ) {
      mono.writeByte( left );
    } else if( pickRight ) {
      mono.writeByte( right );
    } else {
      mono.writeByte( mixed );
    }
}
var mono:ByteArray=newbytearray();
对于(变量i:int=0;i
谢谢。不幸的是,如果我使用您的代码,我正在使用的wave writer类(由Adobe提供)会引发以下错误:错误:音频样本在类中不是浮点格式::WAVWriter/processSamples()是,我的“代码”不正确。读取字节意味着一切都是8bit。浮点是16位的,因此您需要读取交替浮点(如果流是16位,则不是字节),但选择左通道、右通道或混合它们的想法仍然有效。