private async Task Say(IAudioClient connection, ZapSound sound) { try { await connection.SetSpeakingAsync(true); // send a speaking indicator var psi = new ProcessStartInfo { FileName = "ffmpeg", Arguments = $@"-i ""{sound.Filename}"" -ac 2 -f s16le -ar 48000 pipe:1", RedirectStandardOutput = true, UseShellExecute = false }; var ffmpeg = Process.Start(psi); var output = ffmpeg.StandardOutput.BaseStream; var discord = connection.CreatePCMStream(AudioApplication.Voice); await output.CopyToAsync(discord); await discord.FlushAsync(); await connection.SetSpeakingAsync(false); // we're not speaking anymore } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine($"- {ex.StackTrace}"); } }
private async Task RandomSound(IAudioClient connection) { await Say(connection, ZapSound.RandomSound()); }