Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VoiceNext adds noise #1500

Open
9903286 opened this issue Mar 16, 2023 · 1 comment
Open

VoiceNext adds noise #1500

9903286 opened this issue Mar 16, 2023 · 1 comment

Comments

@9903286
Copy link

9903286 commented Mar 16, 2023

Summary

A lot of audio passed through DSharpPlus with VoiceNext has noise in it.
Provided problem.mp4 (recorded from soundcard out) for example, test.mp4 (cut down version because of copyright) is the input

Details

Tried running on both Windows 10 and Ubuntu 20.04 with discord clients tried on both Windows 10 and Android. Any combination has the same issue.

Tried both .NET 6.0 and .NET 7.0

Packages tried with both NuGet and cloning release/4.3
DSharpPlus v4.3.0
DSharpPlus.CommandsNext v4.3.0
DSharpPlus.Interactivity v4.3.0
DSharpPlus.Rest v4.3.0
DSharpPlus.SlashCommands v4.3.0
DSharpPlus.VoiceNext v4.3.0
DSharpPlus.VoiceNext.Natives v1.0.0

FFMPEG: Tried both pre-compiled and self-compiled
Pre-compiled version: ffmpeg version 2022-12-08-git-9ca139b2aa-essentials_build
Self-compiled version: ffmpeg version N-110021-g85b185b504-ffmpeg-windows-build-helpers

Reproduce

Created new project in Visual Studio 2022
Used NuGet to install DSharpPlus v4.3.0 / Natives 1.0.0
Added test.mp4, ffmpeg.exe and a TOKEN.txt to the output bin folder
Added provided code to Program.cs
Run program, join discord channel and do '/join' followed by '/play path: test.mp4'
Listen to noisy audio

Program.cs

using System.Diagnostics;

using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using DSharpPlus.VoiceNext;

using Microsoft.Extensions.Logging;

internal class Program {
	public DiscordClient _client;
	public SlashCommandsExtension _slashCommands;

	public static void Main(string[] args) {
		Program program = new();
		program.RunAsync().Wait();
	}
	
	public Program() {
		string discordToken = File.ReadAllText("TOKEN.txt");
		_client = new DiscordClient(new DiscordConfiguration {
			Token = discordToken,
			TokenType = TokenType.Bot,
			Intents = DiscordIntents.All,
			MinimumLogLevel = LogLevel.Warning
		});
		
		_client.UseVoiceNext();
		_slashCommands = _client.UseSlashCommands();
		_slashCommands.RegisterCommands<MediaCommands>();
	}

	public async Task RunAsync() {
		await _client.ConnectAsync(new("nothing", ActivityType.Playing), UserStatus.Online);
		await Task.Delay(-1);
	}

	internal class MediaCommands : ApplicationCommandModule {
		public static Stream? ConvertAudioToPcm(string filePath) {
			Process? ffmpeg = Process.Start(new ProcessStartInfo {
				FileName = "ffmpeg",
				Arguments = $@"-i ""{filePath}"" -ac 2 -f s16le -ar 48000 pipe:1",
				RedirectStandardOutput = true,
				UseShellExecute = false
			});

			return ffmpeg?.StandardOutput.BaseStream;
		}

		[SlashCommand("join", "joins")]
		public async Task JoinCommand(InteractionContext ctx) {
			DiscordChannel channel = ctx.Member.VoiceState?.Channel;
			await channel.ConnectAsync();
		}

		[SlashCommand("play", "plays")]
		public async Task PlayCommand(InteractionContext ctx, [Option("path", "path")] string path) {
			VoiceNextExtension vnext = ctx.Client.GetVoiceNext();
			VoiceNextConnection connection = vnext.GetConnection(ctx.Guild);

			VoiceTransmitSink transmit = connection.GetTransmitSink();

			Stream? pcm = ConvertAudioToPcm(path);
			await pcm.CopyToAsync(transmit);
			await pcm.DisposeAsync();
		}

		[SlashCommand("leave", "leaves")]
		public async Task LeaveCommand(InteractionContext ctx) {
			VoiceNextExtension vnext = ctx.Client.GetVoiceNext();
			VoiceNextConnection connection = vnext.GetConnection(ctx.Guild);

			connection.Disconnect();
		}
	}
}

Extra

Did not have this problem with Anarchy, but decided to try and switch to DSharpPlus since it seems more actively maintained and has better documentation. Used the same ffmpeg.exe and libs for that.

I've also tried a bunch of different settings with ffmpeg on the test.mp4 file but could not replicate the result without DSharpPlus and since it doesn't happen in Anarchy i'm assuming there's something wrong with DSharpPlus's VoiceNext module?

@OoLunar
Copy link
Member

OoLunar commented Mar 16, 2023

VNext in general isn't actively maintained and unfortunately all the active maintainers (myself included) struggles to understand the VNext codebase. We've wanted to rewrite it for awhile now, however nobody has been able to follow through with it.

Unfortunately I cannot provide any solutions, nor am I aware of any alternatives that's compatible with DSharpPlus.

If any progress is made on VNext, I'll be sure to update this issue. Apologies for the inconvenience.

@akiraveliara akiraveliara removed the v4.x label Oct 5, 2023
@akiraveliara akiraveliara added this to the Backlog milestone Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants