private void SpeakButton_Click(object sender, EventArgs e) { StatusTextBox.Text = ""; var promptBuilder = new System.Speech.Synthesis.PromptBuilder(); promptBuilder.AppendText(MessageTextBox.Text); var client = new Voices.AmazonPolly( SettingsManager.Options.AmazonAccessKey, SettingsManager.Options.AmazonSecretKey, SettingsManager.Options.AmazonRegionSystemName ); var voice = (Voice)((InstalledVoiceEx)VoicesComboBox.SelectedItem).Voice; Amazon.Polly.Engine engine = null; if (voice.SupportedEngines.Contains(Amazon.Polly.Engine.Neural)) { engine = Amazon.Polly.Engine.Neural; } var buffer = client.SynthesizeSpeech(voice.Id, promptBuilder.ToXml(), null, engine); var result = client.LastException == null ? "Success" : client.LastException.Message; StatusTextBox.Text = string.Format("{0:HH:mm:ss}: {1}", DateTime.Now, result); var item = Global.DecodeToPlayItem(buffer); Global.playlist.Add(item); }
private static void Say(System.Globalization.CultureInfo culture, string text) { var prompt = new System.Speech.Synthesis.PromptBuilder(culture); prompt.StartSentence(); prompt.AppendText(text); prompt.EndSentence(); speech.SpeakAsync(prompt); }
public System.IO.MemoryStream Speak(string phrase, string culture, string voice, int volume, int rate) { try { // paranoia here.. System.Speech.Synthesis.PromptBuilder pb; if (culture.Equals("Default")) { pb = new System.Speech.Synthesis.PromptBuilder(); } else { pb = new System.Speech.Synthesis.PromptBuilder(new System.Globalization.CultureInfo(culture)); } if (voice.Equals("Female", StringComparison.InvariantCultureIgnoreCase)) { pb.StartVoice(System.Speech.Synthesis.VoiceGender.Female); } else if (voice.Equals("Male", StringComparison.InvariantCultureIgnoreCase)) { pb.StartVoice(System.Speech.Synthesis.VoiceGender.Male); } else if (!voice.Equals("Default", StringComparison.InvariantCultureIgnoreCase)) { pb.StartVoice(voice); } else { pb.StartVoice(systemdefaultvoice); } synth.Volume = volume; synth.Rate = rate; //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Speak " + phrase + ", Rate " + rate + " culture " + culture); System.IO.MemoryStream stream = new System.IO.MemoryStream(); synth.SetOutputToWaveStream(stream); pb.AppendText(phrase); pb.EndVoice(); synth.Speak(pb); //System.Diagnostics.Debug.WriteLine("Speech " + stream.Length); return(stream); } catch { return(null); } }
private static void Say(string text) { if (speech.State == System.Speech.Synthesis.SynthesizerState.Speaking) { speech.SpeakAsyncCancelAll(); } var prompt = new System.Speech.Synthesis.PromptBuilder(); prompt.StartSentence(); prompt.AppendText(text); prompt.EndSentence(); speech.SpeakAsync(prompt); }
public System.IO.MemoryStream Speak(string phrase, string culture, string voice, int volume, int rate) { try { // paranoia here.. System.Speech.Synthesis.PromptBuilder pb; if (culture.Equals("Default")) { pb = new System.Speech.Synthesis.PromptBuilder(); } else { try { pb = new System.Speech.Synthesis.PromptBuilder(new System.Globalization.CultureInfo(culture)); // may except if crap culture for machine } catch { pb = new System.Speech.Synthesis.PromptBuilder(); } } if (voice.Equals("Female", StringComparison.InvariantCultureIgnoreCase)) { pb.StartVoice(System.Speech.Synthesis.VoiceGender.Female); } else if (voice.Equals("Male", StringComparison.InvariantCultureIgnoreCase)) { pb.StartVoice(System.Speech.Synthesis.VoiceGender.Male); } else if (!voice.Equals("Default", StringComparison.InvariantCultureIgnoreCase)) { pb.StartVoice(voice); } else { pb.StartVoice(systemdefaultvoice); } synth.Volume = volume; synth.Rate = rate; //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Speak " + phrase + ", Rate " + rate + " culture " + culture); System.IO.MemoryStream stream = new System.IO.MemoryStream(); synth.SetOutputToWaveStream(stream); string[] ssmlstart = new string[] { "<say-as ", "<emphasis", "<phoneme", "<sub", "<prosody", "<break", "<voice", "<lexicon" }; string[] ssmlend = new string[] { "</say-as>", "</emphasis>", "</phoneme>", "</sub>", "</prosody>", "/>", "</voice>", "/>" }; phrase = phrase.Trim(); while (phrase.Length > 0) { int ssmlindex; int foundpos = phrase.IndexOf(ssmlstart, out ssmlindex); // find one of the ssml phrases if (foundpos == -1) // no more, task on rest as normal text { pb.AppendText(phrase); break; } else { if (foundpos > 0) { pb.AppendText(phrase.Substring(0, foundpos)); // tack on front phrase = phrase.Substring(foundpos); } int indexofend = phrase.IndexOf(ssmlend[ssmlindex]); if (indexofend == -1) // allowed as a shortcut to drop the last one { indexofend = phrase.Length; phrase += ssmlend[ssmlindex]; } indexofend += ssmlend[ssmlindex].Length; // move to end of it string ssmlcmd = phrase.Substring(0, indexofend).Replace('\'', '"'); //System.Diagnostics.Debug.WriteLine("SSML " + ssmlcmd); try { pb.AppendSsmlMarkup(ssmlcmd); } catch // bad markup { pb.AppendText("Bad SSML Markup when added, contact developers"); } phrase = phrase.Substring(indexofend).Trim(); } } pb.EndVoice(); try { synth.Speak(pb); } catch { synth.Speak("Bad SSML Markup in phrase, your chosen voice may not support all options. See voice configuration menu to disable SSML"); } //System.Diagnostics.Debug.WriteLine("Speech " + stream.Length); return(stream); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception " + ex.ToString()); return(null); } }
private void ButtonVoiceSpecimenDescription_Click(object sender, RoutedEventArgs e) { using (System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer()) { synth.SetOutputToDefaultAudioDevice(); System.Speech.Synthesis.PromptBuilder builder = new System.Speech.Synthesis.PromptBuilder(); builder.AppendTextWithHint("S12", System.Speech.Synthesis.SayAs.NumberCardinal); builder.AppendTextWithHint("10456", System.Speech.Synthesis.SayAs.SpellOut); synth.Speak(builder); } }