Пример #1
0
        private async static void PlaySoundWav(MessageEventArgs e)
        {
            if (e.Message.Text.Length > "-play ".Length && voiceclient != null)
            {
                string file = e.Message.Text.Substring("-play ".Length);
                Console.WriteLine("Trying to play: " + file);
                try {
                    var ws = new NAudio.Wave.WaveFileReader(file);
                    byte[] buf;
                    if (ws.WaveFormat.Channels > 1)
                    {
                        var tomono = new NAudio.Wave.StereoToMonoProvider16(ws);
                        tomono.RightVolume = 0.5f;
                        tomono.LeftVolume = 0.5f;
                        buf = new byte[ws.Length];
                        while (ws.HasData(ws.WaveFormat.AverageBytesPerSecond))
                        {
                            tomono.Read(buf, 0, ws.WaveFormat.AverageBytesPerSecond);
                            voiceclient.SendVoicePCM(buf, buf.Length);
                        }
                    }
                    else
                    {
                        buf = new byte[ws.Length];
                        ws.Read(buf, 0, buf.Length);
                        voiceclient.SendVoicePCM(buf, buf.Length);
                    }
                    ws.Close();
                }
                catch(Exception)
                {
                    Console.WriteLine("File not found or incompatible.");
                }

            }
        }