public void SelectItem(InstalledVoiceEx item) { // Select rows first. foreach (DataGridViewRow row in VoicesDataGridView.Rows) { if (row.DataBoundItem.Equals(item) && !row.Selected) { row.Selected = true; } } // Unselect rows. foreach (DataGridViewRow row in VoicesDataGridView.Rows) { if (!row.DataBoundItem.Equals(item) && row.Selected) { row.Selected = false; } } }
public static void LoadSettings() { var xml = SettingsManager.Options.VoicesData; InstalledVoiceEx[] savedVoices = null; if (!string.IsNullOrEmpty(xml)) { try { savedVoices = Serializer.DeserializeFromXmlString <InstalledVoiceEx[]>(xml); } catch (Exception) { } } if (savedVoices == null) { savedVoices = new InstalledVoiceEx[0]; } foreach (var voice in savedVoices) { // If voice is not missing information then... if (!string.IsNullOrEmpty(voice.SourceKeys)) { InstalledVoices.Add(voice); } } }
// Set voice. static InstalledVoiceEx SelectVoice(string name, string language, MessageGender gender) { // Get only enabled voices. var data = InstalledVoices.Where(x => x.Enabled).ToArray(); InstalledVoiceEx voice = null; var culture = Capturing.message.GetCultureInfo(language); // Order voices by putting matching gender with highest value first. OrderVoicesByGender(ref data, gender); var missing = ""; missing += "There are no voices enabled in \"{0}\" column with value \"{1}\". "; missing += "Set popularity value to 100 ( normal usage ) or 101 ( normal usage / favourite ) for at least one voice."; // Initial choice will be all enabled voices. InstalledVoiceEx[] choice = data; InstalledVoiceEx[] tmp; // If voice name was supplied then... if (!string.IsNullOrEmpty(name)) { // Select voices by name if exists ("IVONA 2 Amy"). tmp = data.Where(x => string.Equals(x.Name, name, StringComparison.InvariantCulture)).ToArray(); // If choice available then... if (tmp.Length > 0) { choice = tmp; } else { OnHelp(missing, "Name", name); } } // Filter by gender (more important than by culture). tmp = FilterVoicesByGender(choice, gender); // If choice available then... if (tmp.Length > 0) { choice = tmp; } else { OnHelp(missing, "Gender", gender); // Order by Male as default. OrderVoicesByGender(ref data, MessageGender.Male); } // If culture supplied. if (culture != null) { tmp = FilterVoicesByCulture(choice, culture); // If choice available then... if (tmp.Length > 0) { choice = tmp; } else { OnHelp(missing, "Culture", language); } } // If nothing to choose from then... if (choice.Length == 0) { return(null); } // Generate number for selecting voice. var number = MainHelper.GetNumber(0, choice.Length - 1, "name", name); voice = choice[number]; if (SelectedVoice != voice) { OnEvent(VoiceChanged, voice); } return(voice); }
static string GetSsmlXml(string text, InstalledVoiceEx vi, int volume, int pitch, int rate, bool isComment) { // <speak> // <amazon:breath duration="long" volume="x-loud"/> <prosody rate="120%"> <prosody volume="loud"> // Wow! <amazon:breath duration="long" volume="loud"/> </prosody> That was quite fast <amazon:breath // duration="medium" volume="x-loud"/>. I almost beat my personal best time on this track. </prosody> // </speak>; var query = System.Web.HttpUtility.ParseQueryString(vi.SourceKeys ?? ""); var isNeural = query[InstalledVoiceEx._KeyEngine] == Amazon.Polly.Engine.Neural; // Amazon Tags: https://docs.aws.amazon.com/polly/latest/dg/supportedtags.html var isAmazon = vi.Source == VoiceSource.Amazon; string xml; string name = vi.Name; var sw = new StringWriter(); var w = new XmlTextWriter(sw); w.Formatting = Formatting.Indented; w.WriteStartElement("speak"); w.WriteAttributeString("version", "1.0"); w.WriteAttributeString("xmlns", "http://www.w3.org/2001/10/synthesis"); w.WriteAttributeString("xml:lang", vi.CultureName); // <amazon:auto-breaths> //if (isAmazon && !isNeural) // w.WriteStartElement("amazon:auto-breaths"); // <amazon:domain name="news"> // Note: "News" effect supported by Neural Matthew or Joanna voices only. //if (isAmazon && isNeural && vi.Gender == VoiceGender.Neutral) //{ // w.WriteStartElement("amazon:domain"); // w.WriteAttributeString("name", "news"); //} //w.WriteStartElement("lang"); //w.WriteAttributeString("xml:lang", vi.Language); // Modify: Pitch. string pitchString = null; if (!SettingsManager.Options.ModifyLocallyPitch && !isNeural && pitch != 0) { if (isAmazon) { pitchString = string.Format("{0:+0;-0;0}%", pitch * 10); } else { pitchString = string.Format("{0:+0;-0;0}", pitch); } } // Modify: Rate. string rateString = null; if (!SettingsManager.Options.ModifyLocallyRate && rate != 0) { // Convert -10 0 +10 to 50% 100% 400% rateString = string.Format("{0:+0;-0;0}%", rate * 10); } // Neural voices do not support pitch. string volumeString = null; if (!SettingsManager.Options.ModifyLocallyVolume && volume < 100) { // Convert -10 0 +10 to -100% +100% // Convert 0 100 to -10dB 0dB if (isAmazon) { volumeString = string.Format("-{0}db", (100 - volume) / 10); } else { volumeString = string.Format("-{0}db", (100 - volume) / 10); } } if (rateString != null || pitchString != null || volumeString != null) { w.WriteStartElement("prosody"); if (pitchString != null) { w.WriteAttributeString("pitch", pitchString); } if (rateString != null) { w.WriteAttributeString("rate", rateString); } if (volumeString != null) { w.WriteAttributeString("volume", volumeString); } } // Replace acronyms with full values. text = SettingsManager.Current.ReplaceAcronyms(text); w.WriteRaw(text); if (rateString != null || pitchString != null) { w.WriteEndElement(); } // </amazon:domain> //if (isAmazon && isNeural && vi.Gender == VoiceGender.Neutral) // w.WriteEndElement(); // </amazon:auto-breaths> //if (isAmazon && !isNeural) // w.WriteEndElement(); w.WriteEndElement(); xml = sw.ToString(); w.Close(); return(xml); }
string GetVoices(RegionTaskSettings settings) { var reg = settings.Region; var engine = settings.Engine; var culture = settings.Culture; settings.Voices = new List <InstalledVoiceEx>(); //var engine = reg.e AmazonPolly client = null; try { client = new AmazonPolly( SettingsManager.Options.AmazonAccessKey, SettingsManager.Options.AmazonSecretKey, reg.SystemName ); } catch (Exception ex) { Console.WriteLine(ex); return(ex.Message); } var request = new DescribeVoicesRequest(); if (engine != null) { request.Engine = engine; } if (culture != null) { request.LanguageCode = culture.Name; } // Create stop watch to measure speed with the servers. var sw = new Stopwatch(); sw.Start(); var voices = client.GetVoices(request, 5000); var elapsed = sw.Elapsed; if (client.LastException != null) { return(string.Format("Exception: {0}", client.LastException.Message)); } var vex = 0; for (int v = 0; v < voices.Count; v++) { var voice = voices[v]; var cultureNames = new List <string>(); cultureNames.Add(voice.LanguageCode); cultureNames.AddRange(voice.AdditionalLanguageCodes); // Add extra cultures. foreach (var cultureName in cultureNames) { // Add engines. var c = new CultureInfo(cultureName); foreach (var engineName in voice.SupportedEngines) { var vx = new InstalledVoiceEx(voice); vx.SetCulture(c); vx.SourceRequestSpeed = elapsed; var keys = System.Web.HttpUtility.ParseQueryString(""); keys.Add(InstalledVoiceEx._KeySource, vx.Source.ToString()); keys.Add(InstalledVoiceEx._KeyRegion, reg.SystemName); keys.Add(InstalledVoiceEx._KeyCulture, cultureName); keys.Add(InstalledVoiceEx._KeyEngine, engineName); keys.Add(InstalledVoiceEx._KeyVoiceId, voice.Id); vx.SourceKeys = keys.ToString(); // Override Description. vx.Description = string.Format("{0}, {1}, {2}, {3}", vx.Source, reg.DisplayName, cultureName, engineName); // Add voice. settings.Voices.Add(vx); vex++; if (_CancelGetVoices) { return("Cancelled"); } } } } return(string.Format("Time (ms): {0,4}, Voices: {1,2}", (int)elapsed.Milliseconds, voices.Count)); }