Exception occurred when decoding incoming audio data
Created by: maxymoo22
Summary
An exception occurs when DSharpPlus runs my VoiceReceived
event handler. The error is along the lines of:
The given keys cannot be found in the dictionary at DSharpPlus.VoiceNext.VoiceNextConnection.ProcessVoicePacket(Byte[] data)
Details
I'm using the latest nightly build of DSharpPlus
Console output:
[2019-11-30 11:31:37 +13:00] [VNext RX] [Error] Exception occured when decoding incoming audio data
System.Collections.Generic.KeyNotFoundException: The given key '1' was not present in the dictionary.
at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNotFoundException(Object key)
at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
at DSharpPlus.VoiceNext.VoiceNextConnection.ProcessPacket(ReadOnlySpan`1 data, Memory`1& opus, Memory`1& pcm, IList`1 pcmPackets, AudioSender& voiceSender, AudioFormat& outputFormat)
at DSharpPlus.VoiceNext.VoiceNextConnection.ProcessVoicePacket(Byte[] data)
Event fired.
[2019-11-30 11:31:37 +13:00] [DSharpPlus] [Error] An System.AggregateException occurred in VNEXT_VOICE_RECEIVED.
System.AggregateException: Exceptions occured within one or more event handlers. Check InnerExceptions for details. (The given key '402299820825509899' was not present in the dictionary.)
---> System.Collections.Generic.KeyNotFoundException: The given key '402299820825509899' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at maxymooapp_DSharp.Program.HandleVoiceData(VoiceReceiveEventArgs voiceData) in C:\Users\Max\Documents\stuff of max\node.js stuff\maxymooapp-DSharp\Program.cs:line 232
at DSharpPlus.AsyncEvent`1.InvokeAsync(T e)
--- End of inner exception stack trace ---
The code I am using for the event handler:
static async Task HandleVoiceData(DSharpPlus.VoiceNext.EventArgs.VoiceReceiveEventArgs voiceData)
{
if (voiceData.User.IsBot) return;
Console.WriteLine("Event fired.");
var stereoBufferArray = voiceData.PcmData.ToArray();
foreach(byte b in stereoBufferArray)
{
bufs.Add(b);
}
}
Where bufs is a: List<byte>
There is no other code in the event handler so far as I cannot get this part to work.
Notes
Every once in a while, no exception will be thrown. This usually happens when I don't have var stereoBufferArray = voiceData.PcmData.ToArray();
or the foreach
loop in the code.
Also, in the second part of the error it cant find the key 402299820825509899
in a dictionary. I then realized that 402299820825509899
is my discord user id`