What I am trying to is, build a bot that wil play an wav file (that I pull from somewhere else) inside a discord channel. I thought let's use a library called NAudio which has a nuget packages that includes everything inside.
But I cannot get it to work. (for mp3 it works perfectly)
I made a sample on this Github page
So I read that I need to go to a PCM Stream to convert it to a valid format for discord. But for some reason it doesn't play... (Also it doesn't give any error to go from). But when I use NAudio to play the PCM Stream it just works.
private async Task SpeakAsync(IAudioClient client)
{
try
{
using (var reader = new WaveFileReader("Audio/Test123.wav"))
{
var naudio = WaveFormatConversionStream.CreatePcmStream(reader);
//using (var waveOut = new WaveOutEvent())
//{
// waveOut.Init(naudio);
// Log.Logger.Debug("Playing sounds...");
// waveOut.Play();
// while (waveOut.PlaybackState == PlaybackState.Playing)
// {
// Thread.Sleep(1000);
// }
//}
var dstream = client.CreatePCMStream(AudioApplication.Music);
await naudio.CopyToAsync(dstream);
dstream.Flush();
client.StopAsync().Wait();
}
}
catch (Exception e)
{
Log.Logger.Error(e, "Error while sending to discord");
}
}