private async Task Say(IAudioClient connection, string sound, SocketVoiceChannel channel) { try { await connection.SetSpeakingAsync(true); // send a speaking indicator var psi = new ProcessStartInfo { FileName = "ffmpeg", Arguments = $@"-re -i ""audio/{sound}.wav"" -ac 2 -f s16le -ar 48000 pipe:1", RedirectStandardOutput = true, UseShellExecute = false }; var ffmpeg = Process.Start(psi); var output = ffmpeg.StandardOutput.BaseStream; Tuple <IAudioClient, Process> t = new Tuple <IAudioClient, Process>(connection, ffmpeg); _connections[channel.Guild.Id] = t; var discord = connection.CreatePCMStream(AudioApplication.Voice); await output.CopyToAsync(discord); await discord.FlushAsync(); Tuple <IAudioClient, Process> te = new Tuple <IAudioClient, Process>(connection, null); _connections[channel.Guild.Id] = te; await connection.SetSpeakingAsync(false); // we're not speaking anymore } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine($"- {ex.StackTrace}"); } }
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 UpdateSends(System.Threading.CancellationToken newListener) { foreach (var kvpSpeaker in ConnectedChannels) { IAudioClient speaker = kvpSpeaker.Value; await speaker.SetSpeakingAsync(true); AudioOutStream speak = speaker.CreateDirectOpusStream(); Console.WriteLine("Speaker"); foreach (var kvpListener in ConnectedChannels.Where(c => !speaker.Equals(c))) { Console.WriteLine("Listener"); IAudioClient listener = kvpListener.Value; await kvpListener.Value.CreateOpusStream().CopyToAsync(speaker.CreateOpusStream()); var users = (await(listener as IVoiceChannel).GetUsersAsync().FlattenAsync()).Where(u => !u.IsBot); foreach (var user in users) { await ListenUserAsync(user).CopyToAsync(speak); } } await speak.WriteAsync(new byte[3840], newListener); await speaker.SetSpeakingAsync(false); } }
internal static async Task Start(IAudioClient Client) { Cancel = new CancellationTokenSource(); while (!Cancel.IsCancellationRequested) { Duration = default(TimeSpan); Time = default(TimeSpan); TicksRemaining = long.MaxValue; try { await Queue.Next(Cancel.Token); if (SS == 0) { Formatting.Update($"Now playing {Queue.Playing.Title}"); Bot.Client.SetGameAsync(Queue.Playing.Title); } Skip = new CancellationTokenSource(); await Client.SetSpeakingAsync(true); using (var Out = Client.CreateDirectPCMStream(AudioApplication.Music, 128 * 1024, Filter.Packets)) await StreamAsync(Out); Queue.ResetPlaying(); } catch (Exception Ex) { Logger.Log(Ex); } } }
private async Task SendAudioAsync(IAudioClient client, string path) { await client.SetSpeakingAsync(true); // Create FFmpeg using the previous example using var ffmpeg = CreateStream(path); await using var audio = ffmpeg.StandardOutput.BaseStream; await using var discord = client.CreatePCMStream(AudioApplication.Mixed); try { await audio.CopyToAsync(discord); } finally { await discord.FlushAsync(); await client.SetSpeakingAsync(false); } }
public async Task SendAsync(IAudioClient client, string path) { LogMessage msg = new LogMessage(LogSeverity.Verbose, "AudioServ", "Sending Audio File " + path + " For " + client.ToString()); await client.SetSpeakingAsync(true); using var ffmpeg = CreateStream(path); using var output = ffmpeg.StandardOutput.BaseStream; using var discord = client.CreatePCMStream(AudioApplication.Mixed, 48000, 500); try { await output.CopyToAsync(discord); } finally { await discord.FlushAsync(); await output.DisposeAsync(); output.Close(); await client.SetSpeakingAsync(false); } }