private async Task ConnectToVoice(SocketVoiceChannel voiceChannel, string sound, string id) { if (voiceChannel == null) { return; } try { Console.WriteLine($"Connecting to channel {voiceChannel.Id}"); var connection = await voiceChannel.ConnectAsync(); Console.WriteLine($"Connected to channel {voiceChannel.Id}"); Tuple <IAudioClient, Process> t = new Tuple <IAudioClient, Process>(connection, null); _connections[voiceChannel.Guild.Id] = t; await Task.Delay(3000); await Say(connection, sound, voiceChannel); await Task.Delay(1000); await voiceChannel.DisconnectAsync(); File.Delete($"prank/{id}.37"); } catch (Exception ex) { // Oh no, error Console.WriteLine(ex.Message); Console.WriteLine($"- {ex.StackTrace}"); } }
public static async void LeaveChannel() { voiceStream?.Close(); voiceStream = null; await audioClient.StopAsync(); await voiceChannel.DisconnectAsync(); }
private async void HandleTaskExecuted(ScheduledTask task) { System.Console.WriteLine(task.Id); var voiceChannels = client.GetGuild(guildId).VoiceChannels; //gets the channel with the highest user count SocketVoiceChannel voiceChannel = voiceChannels.OrderByDescending(x => x.Users.Count).First(); IAudioClient audioClient = await voiceChannel.ConnectAsync(); await PlayAudioClip(audioClient, GetRandomAudioClip()); await voiceChannel.DisconnectAsync(); }
public virtual Task DisconnectAsync() { return(_socketVoiceChannel.DisconnectAsync()); }
protected override async Task DoWorkAsync(CancellationToken cancellationToken) { try { Console.WriteLine("Voice Channel Worker Connecting"); var audioClient = await _voiceChannel.ConnectAsync(); using var audioOutStream = audioClient.CreatePCMStream(AudioApplication.Music); _ = Task.Run(() => _assistantManager(cancellationToken)); _mainTrack = new Track(); _mainTrack.OnClipCompleted += async(s, e) => { if (_mainTrack.Playlist.Count == 0) { _mainTrack.Enqueue(new FFmpegClip(await _getNextAsync())); } }; _mainTrack.Enqueue(new FFmpegClip(await _getNextAsync())); await _mainTrack.PrepareAsync(); _ttsTrack = new Track(); await _ttsTrack.PrepareAsync(); await using var mainTrack = _mainTrack.SetVolume(Program.SoundVolume / 100f); await mainTrack.PrepareAsync(); await using var ttsTrack = _ttsTrack.SetVolume(Program.VoiceAssistantVolume / 100f); await ttsTrack.PrepareAsync(); await using var mixTrack = new MixedTrack(mainTrack, ttsTrack); await mixTrack.PrepareAsync(); while (!cancellationToken.IsCancellationRequested) { var blockSize = 2880; var buffer = new byte[blockSize]; var byteCount = await mixTrack.ReadAsync(buffer, 0, blockSize, cancellationToken); if (byteCount == 0) { await Task.Delay(TimeSpan.FromMilliseconds(50)); continue; } cancellationToken.ThrowIfCancellationRequested(); await audioOutStream.WriteAsync(buffer, 0, byteCount, cancellationToken); } } catch (Exception e) { Console.WriteLine(e); } finally { Console.WriteLine("Voice Channel Worker Disconnecting"); await _voiceChannel.DisconnectAsync(); } }
private async Task DisconnectFromVoiceChannel(SocketVoiceChannel voiceChannel) { Console.WriteLine("Disconnecting from voice channel"); var connection = voiceChannel.DisconnectAsync(); }