예제 #1
0
        SettingsFile GetDefault()
        {
            SettingsFile data       = null;
            bool         compressed = false;
            var          resource   = MainHelper.GetResource(FileName + ".gz");

            // If internal preset was found.
            if (resource != null)
            {
                compressed = true;
            }
            // Try to get uncompressed resource.
            else
            {
                resource = MainHelper.GetResource(FileName);
            }
            // If resource was found.
            if (resource != null)
            {
                var sr    = new StreamReader(resource);
                var bytes = default(byte[]);
                using (var memstream = new MemoryStream())
                {
                    sr.BaseStream.CopyTo(memstream);
                    bytes = memstream.ToArray();
                }
                if (compressed)
                {
                    bytes = SettingsHelper.Decompress(bytes);
                }
                data = Serializer.DeserializeFromXmlBytes <SettingsFile>(bytes);
            }
            return(data);
        }
예제 #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (ControlsHelper.IsDesignMode(this))
            {
                return;
            }
            SettingsFile.Current.Load();
            LastException = null;
            MessagesDataGridView.AutoGenerateColumns       = false;
            EffectsPresetsDataGridView.AutoGenerateColumns = false;
            MessagesDataGridView.DataSource = MessagesVoiceItems;
            // Load voices from settings.
            Global.LoadSettings();
            refreshPresets();
            VoicesPanel.InitializeVoices();
            if (MonitorsEnabledCheckBox.Checked)
            {
                ProgramComboBox.Enabled = false;
            }
            UpdateClipboardMonitor();
            // Load "JocysCom.TextToSpeech.Monitor.rtf" file
            var stream = MainHelper.GetResource("JocysCom.TextToSpeech.Monitor.rtf");
            var sr     = new StreamReader(stream);

            AboutRichTextBox.Rtf = sr.ReadToEnd();
            sr.Close();
            ResetHelpToDefault();
        }
예제 #3
0
        static void Main()
        {
            //var h = "6000000000aa06402a020c7fc4218f00cd3b5a2cb0ecc03f2a04e80050192273028cfafffefbf006";
            //var bytes = HexToBytes(h);
            //Network.Ip6Header header;
            //var p = Network.Ip6Header.TryParse(bytes, out header);

            // Update working directory.
            var fi = new System.IO.FileInfo(Application.ExecutablePath);

            System.IO.Directory.SetCurrentDirectory(fi.Directory.FullName);
            // Load embedded assemblies.
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            if (!RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully)
            {
                // Failed to enable useLegacyV2RuntimeActivationPolicy at runtime.
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            System.Windows.Forms.Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException       += CurrentDomain_UnhandledException;
            // Check if settings file is valid.
            if (!CheckSettings())
            {
                return;
            }
            try
            {
                Application.Run(new MainForm());
            }
            catch (Exception ex)
            {
                var message = "";
                MainHelper.AddExceptionMessage(ex, ref message);
                if (ex.InnerException != null)
                {
                    MainHelper.AddExceptionMessage(ex.InnerException, ref message);
                }
                var box = new JocysCom.ClassLibrary.Controls.MessageBoxForm();
                if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
                {
                    message += "===============================================================\r\n";
                    message += "You can click the link below to download Microsoft DirectX.";
                    box.MainLinkLabel.Text    = "http://www.microsoft.com/en-gb/download/details.aspx?id=8109";
                    box.MainLinkLabel.Visible = true;
                }
                var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Cancel)
                {
                    Application.Exit();
                }
            }
        }
예제 #4
0
        public MainForm()
        {
            Program.TopForm = this;
            ControlsHelper.InitInvokeContext();
            InitializeComponent();
            if (ControlsHelper.IsDesignMode(this))
            {
                return;
            }
            LoadSettings();
            Audio.Global.InitGlobal(Handle);

            Global.EffectsPlayer.BeforePlay += EffectsPlayer_BeforePlay;
            Global.AddingVoiceListItem      += AudioGlobal_AddingVoiceListItem;
            Global.ProcessedMessage         += AudioGlobal_ProcessedMessage;
            Global.HelpSuggested            += AudioGlobal_HelpSuggested;
            Global.EffectsPresetSelected    += Global_EffectsPresetSelected;

            MonitorsEnabledCheckBox.DataBindings.Add(nameof(MonitorsEnabledCheckBox.Checked), SettingsManager.Options, nameof(SettingsManager.Options.MonitorsEnabled));

            Audio.Global.playlist.ListChanged += Playlist_ListChanged;

            PlayListDataGridView.AutoGenerateColumns = false;
            PlayListDataGridView.DataSource          = Global.playlist;
            Text             = MainHelper.GetProductFullName();
            UpdateLabel.Text = "You are running " + MainHelper.GetProductFullName();
            // Add supported items.
            ProgramComboBox.DataSource    = Program.PlugIns;
            ProgramComboBox.DisplayMember = "Name";
            var name = SettingsManager.Options.ProgramComboBoxText;

            if (!string.IsNullOrEmpty(name))
            {
                ProgramComboBox.Text = name;
            }
            // If nothing is selected but list have values.
            if (ProgramComboBox.SelectedIndex == -1 && ProgramComboBox.Items.Count > 0)
            {
                // Select first one.
                ProgramComboBox.SelectedIndex = 0;
            }
            Program._ClipboardMonitor.StatusChanged += _Monitor_StatusChanged;
            Program._NetworkMonitor.StatusChanged   += _Monitor_StatusChanged;
            Program._UdpMonitor.StatusChanged       += _Monitor_StatusChanged;
            Program._NetworkMonitor.ProcessChanged  += _NetworkMonitor_ProcessChanged;
            ControlsHelper.ApplyImageStyle(MessagesTabControl);
        }
예제 #5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (ControlsHelper.IsDesignMode(this))
            {
                return;
            }
            SettingsFile.Current.Load();
            LastException = null;
            MessagesDataGridView.AutoGenerateColumns       = false;
            EffectsPresetsDataGridView.AutoGenerateColumns = false;
            MessagesDataGridView.DataSource = MessagesVoiceItems;
            // Load voices from settings.
            Global.LoadSettings();
            // If installed voices are missing then add all local voices.
            if (Global.InstalledVoices.Count == 0)
            {
                var voicesEx = Voices.VoiceHelper.GetLocalVoices();
                foreach (var item in voicesEx)
                {
                    item.Enabled = true;
                }
                Global.ImportVoices(Global.InstalledVoices, voicesEx);
            }
            refreshPresets();
            VoicesPanel.VoicesGridView.DataSource        = Global.InstalledVoices;
            VoicesPanel.VoicesGridView.SelectionChanged += VoicesDataGridView_SelectionChanged;
            VoicesDataGridView_SelectionChanged(null, null);
            Global.InstalledVoices.ListChanged += InstalledVoices_ListChanged;
            Global.VoiceChanged += AudioGlobal_VoiceChanged;
            InstalledVoices_ListChanged(null, null);
            if (MonitorsEnabledCheckBox.Checked)
            {
                ProgramComboBox.Enabled = false;
            }
            UpdateClipboardMonitor();
            // Load "JocysCom.TextToSpeech.Monitor.rtf" file
            var stream = MainHelper.GetResource("JocysCom.TextToSpeech.Monitor.rtf");
            var sr     = new StreamReader(stream);

            AboutRichTextBox.Rtf = sr.ReadToEnd();
            sr.Close();
            ResetHelpToDefault();
        }
예제 #6
0
        List <PlayItem> AddTextToPlaylist(string game, string text, bool addToPlaylist, string voiceGroup,
                                          // Optional properties for NPC character.
                                          string name   = null,
                                          string gender = null,
                                          string effect = null,
                                          // Optional propertied for player character
                                          string playerName        = null,
                                          string playerNameChanged = null,
                                          string playerClass       = null
                                          )
        {
            // It will take too long to convert large amount of text to WAV data and apply all filters.
            // This function will split text into smaller sentences.
            var  cs         = "[comment]";
            var  ce         = "[/comment]";
            var  items      = new List <PlayItem>();
            var  splitItems = MainHelper.SplitText(text, new string[] { ". ", "! ", "? ", cs, ce });
            var  sentences  = splitItems.Where(x => (x.Value + x.Key).Trim().Length > 0).ToArray();
            bool comment    = false;

            // Loop trough each sentence.
            for (int i = 0; i < sentences.Length; i++)
            {
                var block = sentences[i];
                // Combine sentence and separator.
                var sentence = block.Value + block.Key.Replace(cs, "").Replace(ce, "") + "";
                if (!string.IsNullOrEmpty(sentence.Trim('\r', '\n', ' ')))
                {
                    var item = new PlayItem(this)
                    {
                        Game = game,
                        // Set Player properties
                        PlayerName        = playerName,
                        PlayerNameChanged = playerNameChanged,
                        PlayerClass       = playerClass,
                        // Set NPC properties.
                        Name   = name,
                        Gender = gender,
                        Effect = effect,
                        // Set data properties.
                        Status    = JobStatusType.Parsed,
                        IsComment = comment,
                        Group     = voiceGroup,
                    };
                    item.Text = sentence;
                    if (SettingsManager.Options.CacheDataGeneralize)
                    {
                        item.Text = item.GetGeneralizedText();
                    }
                    item.Xml = ConvertTextToSapiXml(item.Text, comment);
                    items.Add(item);
                    if (addToPlaylist)
                    {
                        lock (playlistLock) { playlist.Add(item); }
                    }
                }
                ;
                if (block.Key == cs)
                {
                    comment = true;
                }
                if (block.Key == ce)
                {
                    comment = false;
                }
            }
            return(items);
        }
예제 #7
0
        void ProcessVoiceTextMessage(string text)
        {
            // If <message.
            if (!text.Contains("<message"))
            {
                return;
            }
            var v = Serializer.DeserializeFromXmlString <message>(text);
            // Override voice values.
            var name          = v.name;
            var overrideVoice = SettingsFile.Current.Defaults.FirstOrDefault(x => x.name == name);

            // if override was found and enabled then...
            if (overrideVoice != null)
            {
                v.UpdateMissingValuesFrom(overrideVoice);
            }

            //Set gender. "Male"(1), "Female"(2), "Neutral"(3).
            _Gender = string.IsNullOrEmpty(v.gender) || v.gender != "Male" && v.gender != "Female" && v.gender != "Neutral" ? GenderComboBox.Text : v.gender;
            var success = Enum.TryParse(_Gender, out gender);

            IncomingGenderTextBox.Text = string.IsNullOrEmpty(v.gender) ? "" : "gender=\"" + _Gender + "\"";

            // Set language. ----------------------------------------------------------------------------------------------------
            language = v.language;
            IncomingLanguageTextBox.Text = string.IsNullOrEmpty(language) ? "" : "language=\"" + language + "\"";

            // Set voice. ----------------------------------------------------------------------------------------------------
            SelectVoice(v.name, language, gender);
            IncomingNameTextBox.Text = string.IsNullOrEmpty(v.name) ? "" : "name=\"" + v.name + "\"";

            // Set pitch.
            var pitchIsValid = int.TryParse(v.pitch, out _Pitch);

            if (!pitchIsValid)
            {
                _Pitch = MainHelper.GetNumber(SettingsManager.Options.PitchMin, SettingsManager.Options.PitchMax, "pitch", v.name);
            }
            if (_Pitch < -10)
            {
                _Pitch = -10;
            }
            if (_Pitch > 10)
            {
                _Pitch = 10;
            }
            IncomingPitchTextBox.Text = pitchIsValid ? "pitch=\"" + _Pitch + "\"" : "";
            PitchTextBox.Text         = pitchIsValid ? PitchTextBox.Text = "" : _Pitch.ToString();

            // Set PitchComment.
            _PitchComment = _Pitch >= 0 ? -1 : 1;

            // Set rate.
            var rateIsValid = int.TryParse(v.rate, out _Rate);

            if (!rateIsValid)
            {
                _Rate = MainHelper.GetNumber(SettingsManager.Options.RateMin, SettingsManager.Options.RateMax, "rate", v.name);
            }
            if (_Rate < -10)
            {
                _Rate = -10;
            }
            if (_Rate > 10)
            {
                _Rate = 10;
            }
            IncomingRateTextBox.Text = rateIsValid ? "rate=\"" + _Rate + "\"" : "";
            RateTextBox.Text         = rateIsValid ? RateTextBox.Text = "" : _Rate.ToString();

            // Set effect.
            var effectValue = string.IsNullOrEmpty(v.effect) ? "Default" : v.effect;

            SelectEffectsPreset(effectValue);
            IncomingEffectTextBox.Text = !string.IsNullOrEmpty(v.effect) ? "effect=\"" + v.effect + "\"" : "";

            // Set volume.
            var volumeIsValid = int.TryParse(v.volume, out _Volume);

            if (!volumeIsValid)
            {
                _Volume = SettingsManager.Options.Volume;
            }
            if (_Volume < 0)
            {
                _Volume = 0;
            }
            if (_Volume > 100)
            {
                _Volume = 100;
            }
            IncomingVolumeTextBox.Text = volumeIsValid ? "volume=\"" + _Volume + "\"" : "";

            // Set group.
            var groupValue = string.IsNullOrEmpty(v.group) ? "" : v.group;

            IncomingGroupTextBox.Text = !string.IsNullOrEmpty(v.group) ? "group=\"" + v.group + "\"" : "";

            // Set command.
            IncomingCommandTextBox.Text = (string.IsNullOrEmpty(v.command)) ? "command value was not submitted!" : "command=\"" + v.command + "\"";
            if (string.IsNullOrEmpty(v.command))
            {
                return;
            }

            // commands.
            switch (v.command.ToLower())
            {
            case "copy":
                break;

            case "player":
                if (v.name != null)
                {
                    var playerNames = v.name.Split(',').Select(x => x.Trim()).ToArray();
                    _PlayerName        = playerNames.FirstOrDefault();
                    _PlayerNameChanged = playerNames.Skip(1).FirstOrDefault();
                    _PlayerClass       = playerNames.Skip(2).FirstOrDefault();
                }
                break;

            case "add":
                if (v.parts != null)
                {
                    buffer += string.Join("", v.parts);
                }
                break;

            case "sound":
                // Get WAV (name), selected as default.
                string introSound = SettingsManager.Options.DefaultIntroSoundComboBox;
                // If group is not submitted.
                if (string.IsNullOrEmpty(v.group))
                {
                    var stream = GetIntroSound(introSound);
                    if (stream != null)
                    {
                        AddIntroSoundToPlayList(introSound, v.group, stream);
                    }
                }
                // If group is submitted.
                else
                {
                    // Check if group is listed in [Intro Sounds] tab.
                    var Sound = SettingsFile.Current.Sounds.FirstOrDefault(x => x.group.ToLower() == v.group.ToLower());
                    // If group is not listed.
                    if (Sound == null)
                    {
                        // add group to list.
                        SoundsPanel.SoundsAddNewRecord(false, v.group);
                        SoundsPanel.SelectRow(v.group);
                        // play default (embedded) WAV.
                        var stream = GetIntroSound(introSound);
                        if (stream != null)
                        {
                            AddIntroSoundToPlayList(introSound, v.group, stream);
                        }
                    }
                    // If group is listed.
                    else
                    {
                        SoundsPanel.SelectRow(Sound.group);
                        if (Sound.enabled == false)
                        {
                            break;
                        }
                        // Get WAV name/path.
                        string wavToPlay = string.IsNullOrEmpty(Sound.file) ? introSound : Sound.file;
                        wavToPlay = MainHelper.ConvertFromSpecialFoldersPattern(wavToPlay);
                        //DefaultIntroSoundComboBox_SelectedIndexChanged(null, null, wavToPlay);
                        // byte[] wavData;
                        var stream = GetIntroSound(wavToPlay);
                        if (stream != null)
                        {
                            AddIntroSoundToPlayList(wavToPlay, v.group, stream);
                        }
                        else if (System.IO.File.Exists(wavToPlay))
                        {
                            stream = new System.IO.FileStream(wavToPlay, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            AddIntroSoundToPlayList(wavToPlay, v.group, stream);
                        }
                    }
                }
                break;

            case "play":
                if (v.parts != null)
                {
                    buffer += string.Join("", v.parts);
                }
                var decodedText = System.Web.HttpUtility.HtmlDecode(buffer);
                buffer = "";
                IncomingTextTextBox.Text = decodedText;
                // Add silence before message.
                int silenceIntBefore = Decimal.ToInt32(OptionsPanel.silenceBefore);
                if (silenceIntBefore > 0)
                {
                    AddTextToPlaylist(ProgramComboBox.Text, "<silence msec=\"" + silenceIntBefore.ToString() + "\" />", true, v.group);
                }
                // Add actual message to the playlist
                AddTextToPlaylist(ProgramComboBox.Text, decodedText, true, v.group,
                                  // Supply NCP properties.
                                  v.name, v.gender, v.effect,
                                  // Supply Player properties.
                                  _PlayerName, _PlayerNameChanged, _PlayerClass
                                  );
                // Add silence after message.
                int silenceIntAfter = Decimal.ToInt32(OptionsPanel.silenceAfter);
                if (silenceIntAfter > 0)
                {
                    AddTextToPlaylist(ProgramComboBox.Text, "<silence msec=\"" + silenceIntAfter.ToString() + "\" />", true, v.group);
                }
                break;

            case "stop":
                text = "";
                StopPlayer(v.group);
                IncomingRateTextBox.Text  = "";
                IncomingPitchTextBox.Text = "";
                break;

            case "save":
                if (!string.IsNullOrEmpty(v.name))
                {
                    VoiceDefaultsPanel.UpsertRecord(v);
                }
                break;

            default:
                break;
            }
        }