Beispiel #1
0
    static void speak(string msg)
    {
        using (var tts = new FonixTalkEngine())
        {
            System.Collections.Specialized.NameValueCollection list = HttpUtility.ParseQueryString(msg);

            string message = list["msg"];
            string ckey    = list["ckey"];
            ckey    = ckey.Replace(System.Environment.NewLine, string.Empty);
            ckey    = ckey.Replace("\r", string.Empty);
            message = HttpUtility.HtmlDecode(message);
            Console.WriteLine($"{message} {ckey} length:{ckey.Length}");
            foreach (char c in ckey)
            {
                Console.WriteLine(System.Convert.ToInt32(c));
            }
            try
            {
                tts.SpeakToWavFile($"sound\\playervoices\\{ckey}.wav", message);
            }
            catch {
                Console.WriteLine("Failed");
            }


            Process          process   = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.FileName    = "OggEnc.exe";
            startInfo.Arguments   = $"sound\\playervoices\\{ckey}.wav";
            process.StartInfo     = startInfo;
            process.Start();
        }
    }
        public static void PLEASE_TalkToWav(string fileName, string text)
        {
            using (var tts = new FonixTalkEngine())
            {
                // tts.Voice = (TtsVoice)Enum.Parse(typeof(TtsVoice), VoiceSelector.Text);


                tts.SpeakToWavFile(fileName, text);
            }
        }
Beispiel #3
0
        static void generateTTS(TtsVoice?voice, string text, string file)
        {
            if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(file) || voice == null || fte == null)
            {
                return;
            }

            if (File.Exists(file + ".tmp"))
            {
                File.Delete(file + ".tmp");
            }

            /*
             * To make sure we don't prematurely send a sound file
             * ALl files start off as .tmp and are renamed when it's finished
             * Process:
             *   1. Create .wav file
             *   2. Convert to .ogg file
             *   3. Find length of .wav file
             *   4. Delete .wav file
             *   5. Write .meta file
             */

            /* .wav file */
            fte.Voice = (TtsVoice)voice;
            fte.SpeakToWavFile(file + ".tmp", text);
            File.Move(file + ".tmp", file + ".wav");

            /* Convert to .ogg */
            Process converter = new Process();

            converter.StartInfo.FileName         = ConverterProgram;
            converter.StartInfo.WorkingDirectory = program_folder;
            converter.StartInfo.Arguments       += " -o \"" + file + ".tmp\" ";
            converter.StartInfo.Arguments       += "\"" + file + ".wav\"";
            converter.StartInfo.WindowStyle      = ProcessWindowStyle.Hidden;
            converter.Start();
            converter.WaitForExit();
            File.Move(file + ".tmp", file + ".ogg");

            /* Meta file */
            int length = SoundInfo.GetSoundLength(file + ".wav");

            File.Delete(file + ".wav");
            File.WriteAllText(file + ".tmp", length.ToString());
            File.Move(file + ".tmp", file + ".meta");

            /* Reset engine to default rate */
            fte.Rate = 200;
        }
Beispiel #4
0
    static void speak(string msg)
    {
        using (var tts = new FonixTalkEngine())
        {
            System.Collections.Specialized.NameValueCollection list = HttpUtility.ParseQueryString(msg);

            string message = list["msg"];
            string ckey    = list["ckey"];
            ckey    = ckey.Replace(System.Environment.NewLine, string.Empty);
            ckey    = ckey.Replace("\r", string.Empty);
            message = HttpUtility.HtmlDecode(message);
            try
            {
                tts.SpeakToWavFile(string.Format("sound\\playervoices\\{0}.wav", ckey), message);
            }
            catch {
                Console.WriteLine("Failed");
            }
        }
    }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                System.Windows.Controls.Button button = (System.Windows.Controls.Button)sender;

                switch (button.Name)
                {
                case "Ab0rt":

                    break;

                case "IsraelNuke":

                    var text = Richy.Text;
                    if (MoonbaseCheckbox.IsChecked == true)
                    {
                        text = memetext(text);
                    }
                    //save as a sound file
                    const string abusedFile = "abusedFile.wav";
                    using (var tts = new FonixTalkEngine())
                    {
                        tts.Voice = (TtsVoice)Enum.Parse(typeof(TtsVoice), VoiceSelector.Text);


                        tts.SpeakToWavFile(abusedFile, text);
                    }

                    if (LucciHear.IsChecked == true)
                    {
                        Console.WriteLine("how the f**k ise this happen?");
                        //System.IO.File.Copy(abusedFile, "copyboy", true);
                        //playback on speaker
                        string SelectedName = abusedFile;
                        Thread thread       = new Thread(new ParameterizedThreadStart((__SelectedName) =>
                        {
                            string _SelectedName = (string)__SelectedName;
                            //https://github.com/naudio/NAudio
                            try
                            {
                                using (var audioFile = new AudioFileReader(_SelectedName))
                                {
                                    int selDevice = -1;

                                    {
                                        for (int n = -1; n < WaveOut.DeviceCount; n++)
                                        {
                                            var caps = WaveOut.GetCapabilities(n);
                                            if (caps.ProductName.StartsWith(CURRENT_SPEAKER_VALUE))
                                            {
                                                selDevice = n;
                                                break;
                                            }
                                        }
                                    }
                                    Console.WriteLine("ree+ " + selDevice);
                                    using (var outputDevice = new WaveOutEvent()
                                    {
                                        DeviceNumber = selDevice
                                    })
                                    {
                                        outputDevice.Init(audioFile);
                                        outputDevice.Volume = (float)percentagevolume;
                                        outputDevice.Play();
                                        while (outputDevice.PlaybackState == PlaybackState.Playing)
                                        {
                                            Thread.Sleep(1000);
                                        }
                                    }
                                }
                            }
                            catch (System.Runtime.InteropServices.COMException e3)
                            { Console.WriteLine(e3); }
                        }));
                        thread.Start(SelectedName);
                    }
                    //////////
                    //now output from the sound file
                    using (var audioFile = new AudioFileReader(abusedFile))
                    {
                        int selDevice = -1;


                        {
                            Console.WriteLine("THIS SHOULD BE FIRST");
                            for (int n = -1; n < WaveOut.DeviceCount; n++)
                            {
                                var caps = WaveOut.GetCapabilities(n);
                                Console.WriteLine(caps.ProductName + ", " + CURRENT_MIC_VALUE);
                                if (caps.ProductName.StartsWith(CURRENT_MIC_VALUE))
                                {
                                    selDevice = n;
                                    break;
                                }
                            }
                        }
                        using (var outputDevice = new WaveOutEvent()
                        {
                            DeviceNumber = selDevice
                        })
                        {
                            // PressAppropriatePTTButton(true);
                            outputDevice.Init(audioFile);
                            outputDevice.Volume = (float)percentagevolume;
                            outputDevice.Play();
                            while (outputDevice.PlaybackState == PlaybackState.Playing)
                            {
                                Thread.Sleep(1000);
                            }
                            //  PressAppropriatePTTButton(false);
                        }
                    }
                    break;
                }
            }catch (Exception exception)
            {
                Log("ERROR:" + exception.Message + ": " + exception.StackTrace);
            }
        }
        private void PopDownAttachBoy()
        {
            if (sm_kp != _sm_kp.TTSMODE)
            {
                return;
            }
            attachboy.Hide();
            sm_kp = _sm_kp.NORMAL;
            attachboy.hwndobject.SendMessage(WindowScrape.Constants.WM.ACTIVATE, 0, 0);
            attachboy.hwndobject.SendMessage(WindowScrape.Constants.WM.SETFOCUS, 0, 0);
            //now speak the text!)
            string text = (string)(attachboy.StebinTextBox.Text);

//            hwndobject.

            if (text == "")
            {
                return;
            }
            if (MoonbaseCheckbox.IsChecked == true)
            {
                text = memetext(text);
            }

            PressAppropriatePTTButton(true);

            new Thread(new ThreadStart(() =>
            {
                //save as a sound file
                const string abusedFile = "abusedFile_overlay.wav";
                using (var tts = new FonixTalkEngine())
                {
                    tts.Voice = (TtsVoice)Enum.Parse(typeof(TtsVoice), CURRENT_VOICESELECTOR_VALUE);


                    tts.SpeakToWavFile(abusedFile, text);
                }

                if (OVERLAYPLAYBACKCHECKBOXCHECKED)
                {
                    //System.IO.File.Copy(abusedFile, "copyboy", true);
                    //playback on speaker
                    string SelectedName = abusedFile;
                    Thread thread       = new Thread(new ParameterizedThreadStart((__SelectedName) =>
                    {
                        string _SelectedName = (string)__SelectedName;
                        //https://github.com/naudio/NAudio
                        try
                        {
                            using (var audioFile = new AudioFileReader(_SelectedName))
                            {
                                int selDevice = -1;

                                {
                                    for (int n = -1; n < WaveOut.DeviceCount; n++)
                                    {
                                        var caps = WaveOut.GetCapabilities(n);
                                        if (caps.ProductName.StartsWith(CURRENT_SPEAKER_VALUE))
                                        {
                                            selDevice = n;
                                            break;
                                        }
                                    }
                                }
                                using (var outputDevice = new WaveOutEvent()
                                {
                                    DeviceNumber = selDevice
                                })
                                {
                                    outputDevice.Init(audioFile);
                                    outputDevice.Volume = (float)percentagevolume;
                                    outputDevice.Play();
                                    while (outputDevice.PlaybackState == PlaybackState.Playing)
                                    {
                                        Thread.Sleep(1000);
                                    }
                                }
                            }
                        }
                        catch (System.Runtime.InteropServices.COMException e3)
                        { Console.WriteLine(e3); }
                    }));
                    thread.Start(SelectedName);
                }


                //////////
                //now output from the sound file
                using (var audioFile = new AudioFileReader(abusedFile))
                {
                    int selDevice = -1;

                    {
                        for (int n = -1; n < WaveOut.DeviceCount; n++)
                        {
                            var caps = WaveOut.GetCapabilities(n);
                            if (caps.ProductName.StartsWith(CURRENT_MIC_VALUE))
                            {
                                selDevice = n;
                                break;
                            }
                        }
                    }
                    using (var outputDevice = new WaveOutEvent()
                    {
                        DeviceNumber = selDevice
                    })
                    {
                        outputDevice.Init(audioFile);
                        outputDevice.Volume = (float)percentagevolume;
                        outputDevice.Play();
                        while (outputDevice.PlaybackState == PlaybackState.Playing)
                        {
                            Thread.Sleep(1000);
                        }
                        PressAppropriatePTTButton(false);
                    }
                }
            })).Start();
        }
        public void Button_Click(object o, RoutedEventArgs e)
        {
            Button b = (Button)o;

            switch (b.Name)
            {
            case "GoButton":
                string text = TextBoxHandle.Text;


                TextBoxHandle.Text = "";
                Console.WriteLine(text);
                if ((automeme.IsChecked == true))
                {
                    text = memetext(text);
                }
                //save as a sound file
                const string fileName = "abusedFile.wav";

                /*using (var reader = new SpeechSynthesizer())
                 * {
                 *  foreach (var x in reader.GetInstalledVoices())
                 *      Console.WriteLine(x.VoiceInfo.Name);
                 *  reader.Rate = (int)-2;
                 *  reader.SetOutputToWaveFile(fileName);
                 *  //https://stackoverflow.com/questions/16021302/c-sharp-save-text-to-speech-to-mp3-file
                 *  reader.Speak(text);
                 * }*/

                using (var tts = new FonixTalkEngine())
                {
                    tts.Voice = (TtsVoice)Enum.Parse(typeof(TtsVoice), VoiceSelector.Text);


                    tts.SpeakToWavFile(fileName, text);
                }



                //////////
                //now output from the sound file
                using (var audioFile = new AudioFileReader(fileName))
                {
                    int selDevice = -1;
                    for (int n = -1; n < WaveOut.DeviceCount; n++)
                    {
                        var caps = WaveOut.GetCapabilities(n);
                        if (caps.ProductName.Contains("CABLE Input"))
                        {
                            selDevice = n;
                            break;
                        }
                    }
                    using (var outputDevice = new WaveOutEvent()
                    {
                        DeviceNumber = selDevice
                    })
                    {
                        outputDevice.Init(audioFile);
                        outputDevice.Volume = (float)percentagevolume;
                        outputDevice.Play();
                        while (outputDevice.PlaybackState == PlaybackState.Playing)
                        {
                            Thread.Sleep(1000);
                        }
                    }
                }



                break;

            case "CloseButton":
                Environment.Exit(0);
                break;
            }
        }
Beispiel #8
0
        void IModule.Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;

            _client.ServerAvailable += (s, e) =>
            {
                _client.Log.Debug("Server added to audioInfos: " + e.Server.Name + " " + e.Server.Id.ToString(), null);
                if (!audioInfos.Any(x => x.id.Equals(e.Server.Id)))
                {
                    AudioInfo aI = new AudioInfo()
                    {
                        id = e.Server.Id, softpause = false, skip = false, stopped = false, playing = false, songPath = "", QueuedSongs = new Queue <string>(), SongNames = new Queue <string>()
                    };
                    audioInfos.Add(aI);
                }
            };

            manager.CreateCommands("", group =>
            {
                group.PublicOnly();

                group.CreateCommand("join")
                .Description("Summons Dapper Bot to an audio channel.")
                .Alias("get in here")
                .MinPermissions((int)PermissionLevel.User)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();

                    var voiceChannel = e.User.VoiceChannel;
                    await _client.GetService <AudioService>().Join(voiceChannel);
                    if (e.Server.Id.Equals(129649392943628288))
                    {
                        aI.volume = 100;

                        tts.SpeakToWavFile(@"..\sounds\voice.wav", "Sup bitches.");

                        aI.songPath = @"..\sounds\voice.wav";

                        await e.Message.Delete();
                        await e.Channel.SendMessage(":speech_balloon: " + "Sup bitches.");

                        await SendMusic(e.Server.GetAudioClient(), e.Server.GetAudioClient().CancelToken);
                        aI.volume = 20;
                    }
                });

                group.CreateCommand("volume")
                .Description("Sets how loud Dapper Bot can be. (Use with no parameters to get volume.)")
                .MinPermissions((int)PermissionLevel.User)
                .Parameter("Level", ParameterType.Optional)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();
                    if (e.GetArg("Level").Equals("") || e.GetArg("Level") == null)
                    {
                        string vol = ":loud_sound:Volume: [";
                        for (int i = 0; i < (int)aI.volume / 10; i++)
                        {
                            vol = vol + ":black_medium_small_square:";
                        }
                        for (int i = 0; i < (int)(100 - aI.volume) / 10; i++)
                        {
                            vol = vol + ":white_medium_small_square:";
                        }
                        vol = vol + "] " + e.Args[0] + "%";

                        await e.Message.Delete();
                        await e.Channel.SendMessage(vol);
                    }
                    else
                    {
                        aI.volume = int.Parse(e.Args[0]);

                        string vol = ":loud_sound:Volume: [";
                        for (int i = 0; i < (int)aI.volume / 10; i++)
                        {
                            vol = vol + ":black_medium_small_square:";
                        }
                        for (int i = 0; i < (int)(100 - aI.volume) / 10; i++)
                        {
                            vol = vol + ":white_medium_small_square:";
                        }
                        vol = vol + "] " + e.Args[0] + "%";

                        await e.Message.Delete();
                        await e.Channel.SendMessage(vol);
                    }
                });

                group.CreateCommand("play")
                .Description("Plays a song or resumes after stopping.")
                .Parameter("url", Discord.Commands.ParameterType.Optional)
                .MinPermissions((int)PermissionLevel.User)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();

                    if (aI.playing)
                    {
                        await AddToQueue(e);
                        RunQueue(e.Server.GetAudioClient());
                    }
                    else if (aI.stopped && aI.QueuedSongs.Count > 0)
                    {
                        aI.stopped   = false;
                        aI.playing   = true;
                        aI.skip      = false;
                        aI.softpause = false;
                        await e.Channel.SendMessage("Resuming song playback.");
                    }
                    else
                    {
                        string url = e.Args[0];
                        string path;

                        await e.Message.Delete();
                        aI.stopped   = false;
                        aI.playing   = true;
                        aI.skip      = false;
                        aI.softpause = false;

                        if (url.StartsWith("http"))
                        {
                            new Task(async() =>
                            {
                                VideoInfo vInfo = DownloadUrlResolver.GetDownloadUrls(url).First();
                                string song     = vInfo.Title;
                                await e.Channel.SendMessage("**NOW PLAYING:**\n" + "*" + song + "*\n");
                                _client.SetGame(song);
                            }).RunSynchronously();

                            path = ResolveVideoUri(url);
                        }
                        else
                        {
                            await e.Channel.SendMessage("**NOW PLAYING:**\n" + "*" + url + "*\n");
                            path = "..\\sounds\\" + url;
                            path.Replace('/', '\\');
                        }

                        _client.Log.Debug("voice", "Got video at path: " + url);
                        aI.songPath = path;

                        IAudioClient audioClient = e.Server.GetAudioClient();

                        await SendMusic(audioClient, audioClient.CancelToken);
                        aI.playing = false;
                    }
                });

                group.CreateCommand("pause")
                .Description("Pauses currently playing song.")
                .MinPermissions((int)PermissionLevel.User)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();

                    await e.Message.Delete();
                    await e.Channel.SendMessage(":pause_button:Paused song.");

                    aI.softpause = !aI.softpause;
                });

                group.CreateCommand("resume")
                .Description("Resumes playback.")
                .MinPermissions((int)PermissionLevel.User)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();
                    await e.Message.Delete();
                    await e.Channel.SendMessage(":arrow_forward:Resuming playback.");
                    if (aI.softpause)
                    {
                        aI.softpause = !aI.softpause;
                    }
                });

                group.CreateCommand("stop")
                .Description("Ends music playback.")
                .MinPermissions((int)PermissionLevel.User)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();
                    await e.Message.Delete();
                    await e.Channel.SendMessage(":stop_button:Stopping music playback.");
                    aI.stopped = true;
                    aI.playing = false;
                });

                group.CreateCommand("skip")
                .Description("Skips to the next song.")
                .MinPermissions((int)PermissionLevel.User)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();
                    await e.Message.Delete();
                    await e.Channel.SendMessage(":track_next:Skipping to next song.");
                    aI.skip = true;
                });

                group.CreateCommand("queue")
                .Description("Displays the queue.")
                .MinPermissions((int)PermissionLevel.User)
                .Do(async e =>
                {
                    await e.Message.Delete();

                    AudioInfo aI    = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();
                    string queueMes = "";

                    List <string> videoList = aI.QueuedSongs.ToList <string>();
                    List <string> nameList  = aI.SongNames.ToList <string>();
                    int i = 1;
                    foreach (string s in videoList)
                    {
                        string addMes = "";
                        addMes       += "**Queue #" + i + "**\n";
                        addMes       += "    **Title: **" + nameList[i - 1] + "\n";

                        if (queueMes.Length + addMes.Length > 2000)
                        {
                            await e.Channel.SendMessage(queueMes);
                            queueMes = addMes;
                        }
                        else
                        {
                            queueMes += addMes;
                        }

                        i++;
                    }
                    await e.Channel.SendMessage(queueMes);
                });

                group.CreateCommand("enqueue")
                .Description("Adds songs to audio queue.")
                .MinPermissions((int)PermissionLevel.User)
                .Parameter("Song URL")
                .Do(async e =>
                {
                    await AddToQueue(e);
                    RunQueue(e.Server.GetAudioClient());
                });

                group.CreateCommand("Speak")
                .Description("Talk using FonixTalk")
                .Parameter("Words", Discord.Commands.ParameterType.Multiple)
                .MinPermissions((int)PermissionLevel.User)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();

                    if (!aI.stopped)
                    {
                        string speechText = String.Join(" ", e.Args);
                        Console.WriteLine("Saying " + speechText + " using FonixTalk");
                        tts.SpeakToWavFile(@"..\sounds\voice.wav", speechText);

                        aI.songPath = @"..\sounds\voice.wav";

                        await e.Message.Delete();
                        await e.Channel.SendMessage(":speech_balloon: " + speechText);

                        await SendMusic(e.Server.GetAudioClient(), e.Server.GetAudioClient().CancelToken);
                    }
                });
                group.CreateCommand("Queue Clear")
                .Description("Empties the queue")
                .MinPermissions((int)PermissionLevel.ServerAdmin)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();

                    aI.QueuedSongs.Clear();
                    aI.SongNames.Clear();

                    await e.Message.Delete();
                    await e.Channel.SendMessage("**Queue Cleared**");
                });

                group.CreateCommand("Shuffle")
                .Description("Shuffles the queue")
                .MinPermissions((int)PermissionLevel.ServerAdmin)
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();

                    List <string> QueuedSongsList    = aI.QueuedSongs.ToList();
                    List <string> QueuedSongNameList = aI.SongNames.ToList();
                    aI.QueuedSongs.Clear();
                    aI.SongNames.Clear();

                    Random ran = new Random();

                    while (QueuedSongsList.Count > 0)
                    {
                        int random = ran.Next(0, QueuedSongsList.Count);
                        aI.QueuedSongs.Enqueue(QueuedSongsList[random]);
                        aI.SongNames.Enqueue(QueuedSongNameList[random]);
                        QueuedSongsList.Remove(QueuedSongsList[random]);
                        QueuedSongNameList.Remove(QueuedSongNameList[random]);
                    }
                    await e.Message.Delete();
                    await e.Channel.SendMessage("**Queue Shuffled**");
                });

                group.CreateCommand("Airhorn")
                .Alias("Airhorm")
                .MinPermissions((int)PermissionLevel.User)
                .Description("For you tony. <3")
                .Do(async e =>
                {
                    AudioInfo aI = audioInfos.Where(x => x.id.Equals(e.Server.Id)).FirstOrDefault();

                    string path = "..\\sounds\\airhorn.mp3";
                    aI.songPath = path;

                    aI.playing = true;
                    await SendMusic(e.Server.GetAudioClient(), e.Server.GetAudioClient().CancelToken);

                    aI.playing = false;
                    _client.Log.Debug("voice", "Finished sending voice");
                });
            });
        }