Discord.Net
Discord.Net copied to clipboard
AudioOutStream Sends For A While, Then Errors Out
Hi,
I appear to be having some issues with sending audio properly. The audio will send perfectly fine for about 20-30 seconds, then throw errors.
Here's a snippet of my code:
internal static Task SendAsync(IAudioClient client, string path)
{
Task musicPlayingTask = Task.Run(() => {
using Process ffmpeg = AudioToDiscordFormat(path);
using Stream output = ffmpeg.StandardOutput.BaseStream;
using AudioOutStream outStream = client.CreatePCMStream(AudioApplication.Mixed);
try
{
client.SetSpeakingAsync(true);
int bufferSize = 1024;
byte[] audioDataBuffer = new byte[bufferSize];
while (!SkipCurrent)
{
int dataReadSize = output.Read(audioDataBuffer, 0, bufferSize);
if (dataReadSize < 1 && IsLooping)
SendAsync(client, path).Wait();
if (dataReadSize < 1)
break;
outStream.Write(audioDataBuffer, 0, dataReadSize);
while (IsPaused)
Task.Delay(100);
}
SkipCurrent = false;
client.SetSpeakingAsync(false);
}
catch (Exception e)
{
MasterLog.DebugWriteException(e, "Failure in sending audio stream");
}
});
musicPlayingTask.ConfigureAwait(false);
return musicPlayingTask;
}
Here's the offending error:
[2020-05-04 06:10:09.964] [DBG]: Disconnecting
[2020-05-04 06:10:10.090] [DBG]:
[2020-05-04 06:10:10.090] [DBG]: Disconnecting
[2020-05-04 06:10:10.091] [DBG]: Failure in sending audio stream
[2020-05-04 06:10:10.091] [DBG]: System.OperationCanceledException, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e:
[2020-05-04 06:10:10.091] [DBG]: Help link:
[2020-05-04 06:10:10.092] [DBG]: Error code: -2146233029
[2020-05-04 06:10:10.092] [DBG]: Message: The operation was canceled.
[2020-05-04 06:10:10.093] [DBG]: Source: System.Private.CoreLib
[2020-05-04 06:10:10.142] [DBG]: Stack trace:
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Threading.SemaphoreSlim.WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Discord.Audio.Streams.BufferedWriteStream.WriteAsync(Byte[] data, Int32 offset, Int32 count, CancellationToken cancelToken)
at Discord.Audio.Streams.OpusEncodeStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancelToken)
at Discord.Audio.AudioStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at TBot.Audio.BotAudio.<>c__DisplayClass9_0.<SendAsync>b__0() in D:\Repos\TBot\TBot\Audio\BotAudio.cs:line 88
I notice that it seems that I disconnected. Not sure if the audio stream should automatically pause and then resume or not. I don't believe that this is a function of my network connection, as in the past 3 hours of debugging it always happens at the exact same place in the song I'm testing with.
Any ideas? Thanks in advance!
Pretty sure this might be the same as my issue #1674 although for me it happens randomly with hours in between :/
@TBye101 are you still having issues with this?