/// <summary> /// Restores default settings /// </summary> public void RestoreDefaults() { var settings = new SAPISettings(); Synthesizer.Rate = settings.Rate; Synthesizer.Volume = settings.Volume; }
/// <summary> /// Updates the UI with values from the settings object /// </summary> /// <param name="settings">the TTS settings object</param> private void updateUI(SAPISettings settings) { int selectedIndex = -1; if (!String.IsNullOrEmpty(settings.Voice)) { for (int index = 0; index < comboBoxSelectVoice.Items.Count; index++) { var voice = comboBoxSelectVoice.Items[index] as String; if (String.Compare(settings.Voice, voice, true) == 0) { selectedIndex = index; break; } } } if (comboBoxSelectVoice.Items.Count > 0) { comboBoxSelectVoice.SelectedIndex = (selectedIndex >= 0) ? selectedIndex : 0; } checkBoxSelectVoice.Checked = (selectedIndex >= 0); comboBoxGender.SelectedIndex = (settings.Gender == VoiceGender.Female) ? 0 : 1; setComboBoxStates(); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public SAPIEngine() { SAPISettings.PreferencesFilePath = UserManager.GetFullPath(SettingsFileName); SAPISettings = SAPISettings.Load(); Synthesizer.SetOutputToDefaultAudioDevice(); Synthesizer.BookmarkReached += speechSynthesizer_BookmarkReached; }
/// <summary> /// Form loader. Init settings and update the ui /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void SettingsForm_Load(object sender, EventArgs e) { float currentAspectRatio = (float)ClientSize.Height / ClientSize.Width; if (_designTimeAspectRatio != 0.0f && currentAspectRatio != _designTimeAspectRatio) { ClientSize = new System.Drawing.Size(ClientSize.Width, (int)(_designTimeAspectRatio * ClientSize.Width)); } TopMost = true; CenterToScreen(); _settings = SAPIEngine.SAPISettings; if (String.IsNullOrEmpty(SAPISettings.PreferencesFilePath)) { SAPISettings.PreferencesFilePath = UserManager.GetFullPath(SAPIEngine.SettingsFileName); } if (_settings == null) { _settings = SAPISettings.Load(); } _speechSynthesizer = new SpeechSynthesizer(); var ins = _speechSynthesizer.GetInstalledVoices(CultureInfo.DefaultThreadCurrentUICulture); foreach (InstalledVoice iv in ins) { comboBoxSelectVoice.Items.Add(iv.VoiceInfo.Name); } if (comboBoxSelectVoice.Items.Count == 0) { checkBoxSelectVoice.Checked = false; checkBoxSelectVoice.Enabled = false; } comboBoxSelectVoice.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxGender.Items.Clear(); comboBoxGender.Items.Add(VoiceGender.Female.ToString()); comboBoxGender.Items.Add(VoiceGender.Male.ToString()); comboBoxGender.DropDownStyle = ComboBoxStyle.DropDownList; updateUI(_settings); _dirty = false; }
/// <summary> /// User clicked on the Settings button. Show other /// settings for the TTS engine /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void buttonSettings_Click(object sender, EventArgs e) { Hide(); var form = new PreferencesEditForm { Title = Text, SupportsPreferencesObj = new SAPIEngine() }; form.ShowDialog(); Show(); _settings = SAPISettings.Load(); }
/// <summary> /// User clicked the Defaults button. Restore defaults and /// update the UI /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void buttonDefaults_Click(object sender, EventArgs e) { if (!confirm("Restore default settings?")) { return; } var settings = new SAPISettings(); updateUI(settings); checkBoxSelectVoice.Checked = false; if (comboBoxSelectVoice.Items.Count > 0) { comboBoxSelectVoice.SelectedIndex = 0; } comboBoxGender.SelectedIndex = 0; }