/// <summary> /// Adds to queue new audio data /// </summary> /// <param name="newVoice">Audio to be played</param> public void AddToQueue(byte[] newVoice) { currentBPSCount += newVoice.Length; VoiceQueue.Enqueue(newVoice); if (!PlayingVoice) { Task.Run(() => PlayVoiceAsync()); } }
private async void PlayVoiceAsync() { PlayingVoice = true; while (VoiceQueue.Count > 0) { await Task.Run(() => { AudioUtils.PlaySound(VoiceQueue.Dequeue()); if (VoiceQueue.Count > 1) { VoiceQueue.Clear(); } }); } PlayingVoice = false; }