void FixedUpdate()
    {
        if (voiceClient == null)
        {
            return;
        }

        if (voiceClient.isOnline)
        {
            if (sending)
            {
                float[] sendbuffer = new float[960];
                sendClip.GetData(sendbuffer, sendinterval * 960);
                voiceClient.SendVoice(sendbuffer);
                sendinterval = sendinterval >= 49 ? 0 : sendinterval + 1;
            }

            if (buffer.Count > 0)
            {
                if (delayed > 9)
                {
                    if (buffer.Count > 9600)
                    {
                        delayed = 0;
                        float[] packet = buffer[9600];
                        if (source.isPlaying)
                        {
                            source.Stop();
                        }
                        receivedClip.SetData(packet, 0);
                        source.Play();
                    }

                    else
                    {
                        float[] packet = buffer[buffer.Count];
                        if (source.isPlaying)
                        {
                            source.Stop();
                        }
                        receivedClip.SetData(packet, 0);
                        source.Play();
                    }
                }

                else
                {
                    delayed++;
                }
            }

            else
            {
                delayed = 0;
            }
        }
    }
Esempio n. 2
0
        public void SendBytes(byte[] voiceBytes)
        {
            DiscordVoiceClient vc = client.GetVoiceClient();

            try
            {
                if (vc.Connected)
                {
                    vc.SendVoice(voiceBytes);
                }
            }
            catch (Exception ex) { client.GetTextClientLogger.Log(ex.Message, MessageLevel.Critical); }
        }
Esempio n. 3
0
        public static void TestRheaStream(DiscordMessageEventArgs e)
        {
            DiscordVoiceClient vc = client.GetVoiceClient();

            if (vc == null)
            {
                SendBotMessage("!@Not in a channel!", e.Channel);
            }
            try
            {
                int ms         = 20;//buffer
                int channels   = 1;
                int sampleRate = 48000;

                int    blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds
                byte[] buffer    = new byte[blockSize];
                var    outFormat = new WaveFormat(sampleRate, 16, channels);
                vc.SetSpeaking(true);
                using (var mp3Reader = new MediaFoundationReader("https://www.youtube.com/watch?v=2Vv-BfVoq4g"))
                {
                    using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat)
                    {
                        ResamplerQuality = 60
                    })
                    {
                        int byteCount;
                        while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                        {
                            if (vc.Connected)
                            {
                                vc.SendVoice(buffer);
                            }
                            else
                            {
                                break;
                            }
                        }
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("Voice finished enqueuing");
                        Console.ForegroundColor = ConsoleColor.White;
                        resampler.Dispose();
                        mp3Reader.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Log("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```", LogType.Console);
            }
            #endregion
        }
Esempio n. 4
0
        private void TestRheaStream()
        {
            DiscordVoiceClient vc = client.GetVoiceClient();

            try
            {
                int ms         = voiceMsBuffer;
                int channels   = 1;
                int sampleRate = 48000;

                int    blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds
                byte[] buffer    = new byte[blockSize];
                var    outFormat = new WaveFormat(sampleRate, 16, channels);
                vc.SetSpeaking(true);
                using (var mp3Reader = new MediaFoundationReader("http://radiosidewinder.out.airtime.pro:8000/radiosidewinder_a"))
                {
                    using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat)
                    {
                        ResamplerQuality = 60
                    })
                    {
                        int byteCount;
                        while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                        {
                            if (vc.Connected)
                            {
                                vc.SendVoice(buffer);
                            }
                            else
                            {
                                break;
                            }
                        }
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("Voice finished enqueuing");
                        Console.ForegroundColor = ConsoleColor.White;
                        resampler.Dispose();
                        mp3Reader.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                owner.SendMessage("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```");
            }
        }
Esempio n. 5
0
        static Task DoVoice(DiscordVoiceClient vc, string file)
        {
            return(Task.Run(() =>
            {
                try
                {
                    int ms = 20;
                    int channels = 2;
                    int sampleRate = 48000;

                    int blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds
                    byte[] buffer = new byte[blockSize];
                    var outFormat = new WaveFormat(sampleRate, 16, channels);

                    vc.SetSpeaking(true);
                    using (var mp3Reader = new Mp3FileReader(file))
                    {
                        using (var resampler = new WaveFormatConversionStream(outFormat, mp3Reader))
                        {
                            int byteCount;
                            while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                            {
                                if (vc.Connected)
                                {
                                    //sequence = await vc.SendSmallOpusAudioPacket(buffer, sampleRate, byteCount, sequence).ConfigureAwait(false);
                                    vc.SendVoice(buffer);
                                    //sequence = vc.SendSmallOpusAudioPacket(buffer, 48000, buffer.Length, sequence);
                                    //Task.Delay(19).Wait();
                                }
                                else
                                {
                                    break;
                                }
                            }
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("Voice finished enqueuing");
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }));
        }
Esempio n. 6
0
 public void SendVoice(AudioClip audioClip)
 {
     voiceClient.SendVoice(audioClip);
 }
Esempio n. 7
0
        private void SendVoice(string file, DiscordClient client, YouTubeVideo video)
        {
            DiscordVoiceClient vc = client.GetVoiceClient();

            try
            {
                int ms         = vc.VoiceConfig.FrameLengthMs;
                int channels   = vc.VoiceConfig.Channels;
                int sampleRate = 48000;

                int    blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds
                byte[] buffer    = new byte[blockSize];
                var    outFormat = new WaveFormat(sampleRate, 16, channels);

                vc.SetSpeaking(true);

                if (video.AudioFormat == AudioFormat.Mp3)
                {
                    using (var mp3Reader = new Mp3FileReader(video.Stream()))
                    {
                        using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat)
                        {
                            ResamplerQuality = 60
                        })
                        {
                            //resampler.ResamplerQuality = 60;
                            int byteCount;
                            while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                            {
                                if (vc.Connected)
                                {
                                    vc.SendVoice(buffer);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("Voice finished enqueuing");
                            Console.ForegroundColor = ConsoleColor.White;
                            resampler.Dispose();
                            mp3Reader.Close();
                        }
                    }
                }
                else if (video.AudioFormat == AudioFormat.Vorbis)
                {
                    using (var vorbis = new NAudio.Vorbis.VorbisWaveReader(video.Stream()))
                    {
                        using (var resampler = new MediaFoundationResampler(vorbis, outFormat)
                        {
                            ResamplerQuality = 60
                        })
                        {
                            int byteCount;
                            while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                            {
                                if (vc.Connected)
                                {
                                    vc.SendVoice(buffer);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("Voice finished enqueuing");
                            Console.ForegroundColor = ConsoleColor.White;
                            resampler.Dispose();
                            vorbis.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    MainEntry.owner.SendMessage("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```");
                }
                catch { }
            }
        }
Esempio n. 8
0
        public void SendVoice(string file)
        {
            DiscordVoiceClient vc = Concordia.voice;

            try
            {
                int ms         = 60;
                int channels   = 1;
                int sampleRate = 48000;

                int    blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds
                byte[] buffer    = new byte[blockSize];
                var    outFormat = new WaveFormat(sampleRate, 16, channels);

                vc.SetSpeaking(true);
                if (file.EndsWith(".wav"))
                {
                    using (var waveReader = new WaveFileReader(file))
                    {
                        int byteCount;
                        while ((byteCount = waveReader.Read(buffer, 0, blockSize)) > 0)
                        {
                            if (vc.Connected)
                            {
                                vc.SendVoice(buffer);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else if (file.EndsWith(".mp3"))
                {
                    using (var mp3Reader = new MediaFoundationReader(file))
                    {
                        using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat)
                        {
                            ResamplerQuality = 60
                        })
                        {
                            //resampler.ResamplerQuality = 60;
                            int byteCount;
                            while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0)
                            {
                                if (vc.Connected)
                                {
                                    vc.SendVoice(buffer);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("Voice finished enqueuing");
                            Console.ForegroundColor = ConsoleColor.White;
                            resampler.Dispose();
                            mp3Reader.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```");
            }
        }