public void SendFirstAudioPart() { var headerBytes = CreateAudioHeaders(); var headerHead = CreateAudioHeaderHead(headerBytes); using (RiffChunker riff = new RiffChunker(audioFile)) { var riffHeaderBytes = riff.RiffHeader.Bytes; var arr = headerHead.Concat(headerBytes).Concat(riffHeaderBytes).ToArray(); socketManager.SendBinary(arr); } }
public void SendAllAudio() { using (RiffChunker riff = new RiffChunker(audioFile)) { var currentChunk = riff.Next(); while (currentChunk != null) { var cursor = 0; while (cursor < currentChunk.SubChunkDataBytes.Length) { var headerBytes = CreateAudioHeaders(); var headerHead = CreateAudioHeaderHead(headerBytes); var length = Math.Min(4096 * 2 - headerBytes.Length - 8, currentChunk.AllBytes.Length - cursor); //8bytes for the chunk header var chunkHeader = Encoding.ASCII.GetBytes("data").Concat(BitConverter.GetBytes((UInt32)length)).ToArray(); byte[] dataArray = new byte[length]; Array.Copy(currentChunk.AllBytes, cursor, dataArray, 0, length); cursor += length; var arr = headerHead.Concat(headerBytes).Concat(chunkHeader).Concat(dataArray).ToArray(); var arrSeg = new ArraySegment <byte>(arr, 0, arr.Length); socketManager.SendBinary(arr); } //Move to the next RIFF chunk if there is one. currentChunk = riff.Next(); } //Send Audio End { var headerBytes = CreateAudioHeaders(); var headerHead = CreateAudioHeaderHead(headerBytes); var arr = headerHead.Concat(headerBytes).ToArray(); socketManager.SendBinary(arr); } } }