private void TransmitBuffer(float[] sampleBuffer) { int length = 0; byte[] buffer = ViSpeexCompress.SpeexCompress(sampleBuffer, out length); ViChatPacket packet = new ViChatPacket(); byte[] availableSampleBuffer = new byte[length]; Buffer.BlockCopy(buffer, 0, availableSampleBuffer, 0, length); packet.Data = availableSampleBuffer; packet.Length = length; packet.DataLength = buffer.Length; if (OnReSampleCompleteCallback != null) { OnReSampleCompleteCallback(packet); } }
//每帧记录声音float[]转byte[] void TransmitBuffer(float[] sampleBuffer) { //压缩语音: //得到声音包长度 int length = 0; byte[] buffer = ViSpeexCompress.SpeexCompress(sampleBuffer, out length); //创建声音包 ViChatPacket packet = new ViChatPacket(); //拷贝压缩数据 byte[] availableSampleBuffer = new byte[length]; Buffer.BlockCopy(buffer, 0, availableSampleBuffer, 0, length); //赋值声音包 packet.Data = availableSampleBuffer; packet.Length = length; packet.DataLength = buffer.Length; //记录缓存 OnRecordSample(packet); }