public override void Speak(SpeechClient.Speech speech) { try { PromptBuilder p = new PromptBuilder(); p.Culture = tts.Voice.Culture; p.StartVoice(p.Culture); p.StartSentence(); p.StartStyle(new PromptStyle(PromptEmphasis.None)); for (int i = 0; i < speech.Text.Length; i++) { if (speech.Bookmarks == null || speech.Bookmarks.Length < i + 1 || speech.Bookmarks[i]=="") { string s = ""; for (; i < speech.Text.Length; i++) s += speech.Text[i] + " "; p.AppendSsmlMarkup(s); break; } else { p.AppendSsmlMarkup(speech.Text[i]); p.AppendBookmark(speech.Bookmarks[i]); } } p.EndStyle(); p.EndSentence(); p.EndVoice(); currentSpeech = speech; if (speech.Id != "") ids.Add(tts.SpeakAsync(p), speech.Id); else tts.SpeakAsync(p); } catch (Exception e) { Console.WriteLine("WindowsTTS Failed: " + e.Message); } }
public void sayAppointment(string[] whatToSay) { //whatToSay[0] = index //whatToSay[1] = Subject //whatToSay[2] = Date string[] date = whatToSay[2].Split('/'); string newDate = date[1] + "/" + date[0]; //whatToSay[3] = Time string[] time = whatToSay[3].Split(':'); string newTime = time[0] + ":" + time[1]; //whatToSay[4] = Location PromptBuilder appointmentBuilder = new PromptBuilder(); appointmentBuilder.StartVoice("IVONA 2 Brian"); appointmentBuilder.AppendText("Appointment " + whatToSay[0]); appointmentBuilder.AppendText(", subject is: " + whatToSay[1]); appointmentBuilder.AppendSsmlMarkup(", on <say-as interpret-as=\"date_md\">" + newDate + "</say-as>"); appointmentBuilder.AppendSsmlMarkup(" <say-as interpret-as=\"time\">" + newTime + "</say-as>"); appointmentBuilder.AppendText(", at " + whatToSay[4]); appointmentBuilder.EndVoice(); JARVIS.Speak(appointmentBuilder); appointmentBuilder.ClearContent(); }
public static void PromptBuilder() { string SsmlNs = "\"http://schemas.microsoft.com/Speech/2003/03/PromptEngine\""; string SsmlStartOutTag = "<peml:prompt_output xmlns:peml=" + SsmlNs + ">"; string SsmlEndOutTag = "</peml:prompt_output>"; PromptBuilder builder; using (new ThreadCultureChange(null, CultureInfo.CreateSpecificCulture("ru-RU"))) { builder = new PromptBuilder(); Assert.Equal(CultureInfo.CurrentUICulture, builder.Culture); } using (new ThreadCultureChange(null, CultureInfo.CreateSpecificCulture("en-US"))) { builder = new PromptBuilder(); builder.AppendText("test"); builder.AppendTextWithPronunciation("foo", "bar"); builder.AppendSsmlMarkup(SsmlStartOutTag); builder.AppendSsmlMarkup("hello"); builder.AppendSsmlMarkup(SsmlEndOutTag); Assert.Contains("hello", builder.ToXml()); Assert.Equal(CultureInfo.CurrentUICulture, builder.Culture); Assert.False(builder.IsEmpty); string ssml = builder.ToXml(); builder.AppendSsml(XmlTextReader.Create(new StringReader(ssml))); } }
/// <summary> /// Receiver for audio data. /// </summary> /// <param name="utteranceText">A string containing the next utterance to synthesize.</param> /// <param name="e">The message envelope for the next utterance to synthesize.</param> protected override void Receive(string utteranceText, Envelope e) { // Construct the SSML for the text to speak. PromptBuilder pb = new PromptBuilder(); pb.AppendSsmlMarkup(string.Format("<prosody rate=\"{0}\" pitch=\"{1}\" volume=\"{2}\">", this.configuration.ProsodyRate, this.configuration.ProsodyPitch, this.configuration.ProsodyVolume)); pb.AppendText(utteranceText); pb.AppendSsmlMarkup("</prosody>"); // Speak synchronously this.speechSynthesizer.SpeakAsync(pb); }
protected override void HandleNotification(Notification notification, string displayName) { /* * string xml = @"<p> * <s>You have 4 new messages.</s> * <s>The first is from Stephanie Williams and arrived at <break/> 3:45pm. * </s> * <s> * The subject is <prosody rate=""-20%"">ski trip</prosody> * </s> * </p>"; * */ PromptBuilder pb = new PromptBuilder(); // handle title if (notification.CustomTextAttributes != null && notification.CustomTextAttributes.ContainsKey("Notification-Title-SSML")) { pb.AppendSsmlMarkup(notification.CustomTextAttributes["Notification-Title-SSML"]); } else { pb.AppendText(notification.Title, PromptEmphasis.Strong); } pb.AppendBreak(); // handle text if (notification.CustomTextAttributes != null && notification.CustomTextAttributes.ContainsKey("Notification-Text-SSML")) { pb.AppendSsmlMarkup(notification.CustomTextAttributes["Notification-Text-SSML"]); } else { pb.AppendText(notification.Description); } try { ss.Speak(pb); } catch (Exception ex) { Growl.CoreLibrary.DebugInfo.WriteLine("Unable to speak input: " + ex.Message); // fall back to plain text (if the plain text is what failed the first time, it wont work this time either but wont hurt anything) pb.ClearContent(); pb.AppendText(notification.Title, PromptEmphasis.Strong); pb.AppendBreak(); pb.AppendText(notification.Description); ss.Speak(pb); } }
/// <summary> /// Start speaking the supplied text, or cancel the in-progress speech /// </summary> public void SpeakSsml(IEnumerable <string> ssmls, Action onComplete, int?volume = null, int?rate = null, string voice = null) { Log.Info("SpeakSsml called"); try { if (!ssmls.Any()) { return; } speechSynthesiser.Rate = rate ?? Settings.Default.SpeechRate; speechSynthesiser.Volume = volume ?? Settings.Default.SpeechVolume; speakCompleted = (sender, args) => { if (speakCompleted != null) { speechSynthesiser.SpeakCompleted -= speakCompleted; } speakCompleted = null; if (onComplete != null) { onComplete(); } }; speechSynthesiser.SpeakCompleted += speakCompleted; var pb = new PromptBuilder(); string voiceToUse = voice ?? Settings.Default.SpeechVoice; if (!string.IsNullOrWhiteSpace(voiceToUse)) { pb.AppendSsmlMarkup(string.Format("<voice name=\"{0}\">", voiceToUse)); } foreach (var ssml in ssmls) { pb.AppendSsmlMarkup(ssml); } if (!string.IsNullOrWhiteSpace(voiceToUse)) { pb.AppendSsmlMarkup("</voice>"); } Log.InfoFormat("Speaking prompt '{0}' with volume '{1}', rate '{2}' and voice '{3}'", pb.ToXml(), volume, rate, voice); speechSynthesiser.SpeakAsync(pb); } catch (Exception exception) { PublishError(this, exception); } }
private void SpeakHelp() { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("Aby wybrać godzinę powiedz SALA"); promptBuilder.AppendSsmlMarkup("<prosody rate=\"slow\"><say-as interpret-as=\"characters\">K</say-as></prosody>"); promptBuilder.AppendText("GODZINA"); promptBuilder.AppendSsmlMarkup("<prosody rate=\"slow\"><say-as interpret-as=\"characters\">L</say-as></prosody>"); Prompt prompt = new Prompt(promptBuilder); Speak(prompt); Speak("Aby wrócić powiedz WRÓĆ."); }
private void SpeakHelp() { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("Aby wybrać miejsce powiedz WYBIERZ RZĄD"); promptBuilder.AppendSsmlMarkup("<prosody rate=\"slow\"><say-as interpret-as=\"characters\">K</say-as></prosody>"); promptBuilder.AppendText("MIEJSCE"); promptBuilder.AppendSsmlMarkup("<prosody rate=\"slow\"><say-as interpret-as=\"characters\">L</say-as></prosody>"); Prompt prompt = new Prompt(promptBuilder); Speak(prompt); Speak("Aby wrócić powiedz WRÓĆ."); }
public VoiceGenerator(ILogger logger, string text, [AllowNull] string sapiVoiceName) { this.sapiVoiceName = sapiVoiceName; this.logger = logger; promptBuilder = new PromptBuilder(System.Globalization.CultureInfo.CurrentCulture); promptBuilder.AppendSsmlMarkup(text); }
private void PlayButton_Click(object sender, EventArgs e) { sapi5engine.SpeakAsyncCancelAll(); sapi5engine.Resume(); PromptBuilder pb = new PromptBuilder(); if (XMLEnableButton.Checked) { if (MainTextBox.Text.Length == 0) { MessageBox.Show("Nothing to speak!"); return; } pb.AppendSsmlMarkup(MainTextBox.Text); } else { pb.AppendText(MainTextBox.Text); } offset = MainTextBox.Text.Length - pb.ToXml().Length + 8; //TODO: Find a better way to calculate the offset, if possible lengthOfText = MainTextBox.Text.Length; //MessageBox.Show($"Debug: Offset = {offset}; Length = {lengthOfText}"); //That was for debugging the offset functionality. ReadingFromMainTextBox = true; sapi5engine.SpeakAsync(pb); }
private void Answer(string ssmlText) { PromptBuilder builder = new PromptBuilder(); builder.AppendSsmlMarkup(ssmlText); synthesizer.Speak(builder); }
/// <summary> /// Append message in SSML format to main prompt. /// </summary> /// <param name="promptSsml"></param> public void MainPromptAppendSssml(string promptSsml) { if (m_pbMainPrompt == null) { m_pbMainPrompt = new PromptBuilder(); } m_pbMainPrompt.AppendSsmlMarkup(promptSsml); }
protected override void HandleNotification(Notification notification, string displayName) { /* string xml = @"<p> <s>You have 4 new messages.</s> <s>The first is from Stephanie Williams and arrived at <break/> 3:45pm. </s> <s> The subject is <prosody rate=""-20%"">ski trip</prosody> </s> </p>"; * */ PromptBuilder pb = new PromptBuilder(); // handle title if (notification.CustomTextAttributes != null && notification.CustomTextAttributes.ContainsKey("Notification-Title-SSML")) pb.AppendSsmlMarkup(notification.CustomTextAttributes["Notification-Title-SSML"]); else pb.AppendText(notification.Title, PromptEmphasis.Strong); pb.AppendBreak(); // handle text if (notification.CustomTextAttributes != null && notification.CustomTextAttributes.ContainsKey("Notification-Text-SSML")) pb.AppendSsmlMarkup(notification.CustomTextAttributes["Notification-Text-SSML"]); else pb.AppendText(notification.Description); try { ss.Speak(pb); } catch (Exception ex) { Growl.CoreLibrary.DebugInfo.WriteLine("Unable to speak input: " + ex.Message); // fall back to plain text (if the plain text is what failed the first time, it wont work this time either but wont hurt anything) pb.ClearContent(); pb.AppendText(notification.Title, PromptEmphasis.Strong); pb.AppendBreak(); pb.AppendText(notification.Description); ss.Speak(pb); } }
public static void VBRCharModeTTSSpeak(string dataReceived) { //reader.Rate = -3; PromptBuilder pb2 = new PromptBuilder(); string str2 = "<say-as interpret-as=\"characters\">" + dataReceived + "</say-as>"; pb2.AppendSsmlMarkup(str2); reader.SpeakAsync(pb2); //reader.Rate = 0; }
public void currentDate() { string dateString = DateTime.Now.ToShortDateString(); PromptBuilder dateBuilder = new PromptBuilder(); dateBuilder.StartVoice("IVONA 2 Brian"); dateBuilder.AppendText("The date is: "); dateBuilder.AppendSsmlMarkup(" <say-as interpret-as=\"date_md\">" + dateString + "</say-as>"); dateBuilder.EndVoice(); JARVIS.Speak(dateBuilder); }
public void currentTime() { string timeString = DateTime.Now.ToShortTimeString(); PromptBuilder timeBuilder = new PromptBuilder(); timeBuilder.StartVoice("IVONA 2 Brian"); timeBuilder.AppendText("The time is: "); timeBuilder.AppendSsmlMarkup(" <say-as interpret-as=\"time\">" + timeString + "</say-as>"); timeBuilder.EndVoice(); JARVIS.Speak(timeBuilder); }
/// <summary> /// テキストを読み上げる /// </summary> /// <param name="text">読み上げるテキスト</param> public void Speak( string text, PlayDevices playDevice = PlayDevices.Both, bool isSync = false, float?volume = null) { if (string.IsNullOrWhiteSpace(text)) { return; } // 現在の条件をハッシュ化してWAVEファイル名を作る var wave = this.GetCacheFileName( Settings.Default.TTS, text, this.Config.ToString()); lock (this) { if (!File.Exists(wave)) { using (var fs = new FileStream(wave, FileMode.Create)) using (var synth = new SpeechSynthesizer()) { // VOICEを設定する var voice = this.GetSynthesizer(this.Config.VoiceID); if (voice == null) { return; } synth.SelectVoice(voice.VoiceInfo.Name); synth.Rate = this.Config.Rate; synth.Volume = this.Config.Volume; // Promptを生成する var pb = new PromptBuilder(voice.VoiceInfo.Culture); pb.StartVoice(voice.VoiceInfo); pb.AppendSsmlMarkup( $"<prosody pitch=\"{this.Config.Pitch.ToXML()}\">{text}</prosody>"); pb.EndVoice(); synth.SetOutputToWaveStream(fs); synth.Speak(pb); } } } // 再生する SoundPlayerWrapper.Play(wave, playDevice, isSync, volume); }
public void currentDate() { string dateString = DateTime.Now.ToShortDateString(); PromptBuilder dateBuilder = new PromptBuilder(); dateBuilder.Culture = CultureInfo.GetCultureInfo("en-US"); dateBuilder.StartVoice(VoiceGender.Male, VoiceAge.NotSet, 0); dateBuilder.AppendText("The date is: "); dateBuilder.AppendSsmlMarkup("<say-as interpret-as=\"date_md\">" + dateString + "</say-as>"); dateBuilder.EndVoice(); Speaker.SelectVoiceByHints(VoiceGender.Male, VoiceAge.NotSet, 0, CultureInfo.GetCultureInfo("en-US")); Speaker.Speak(dateBuilder); }
public void Talk(Dictionary <string, string> sounds) { foreach (var pair in sounds) { SpeechSynthesizer synth = new SpeechSynthesizer(); synth.SetOutputToDefaultAudioDevice(); PromptBuilder pb4 = new PromptBuilder(); string str = "<phoneme alphabet=\"ipa\" ph=\"" + pair.Value + "\">" + pair.Key + "</phoneme>"; pb4.AppendSsmlMarkup(str); synth.Rate = -5; synth.Speak(pb4); } }
public void Speak(String phrase, List <String> timeStrings = null) { var speechBuilder = new PromptBuilder(); speechBuilder.AppendText(phrase); if (timeStrings != null && timeStrings.Count > 0) { foreach (var time in timeStrings) { speechBuilder.AppendSsmlMarkup(time); } } m_speechSynthesizer.Speak(speechBuilder); }
public void SaveToFile(List <string> phonemes, string path) { try { ssmlBuilder = new PromptBuilder(); ssmlBuilder.AppendSsmlMarkup(GetSsml(phonemes)); synthesizer.SetOutputToWaveFile(path); synthesizer.Speak(ssmlBuilder); } catch (Exception) { throw; } }
private void Start() { try { var pb1 = new PromptBuilder(); var pitch = SongProvider.song.GetNextNote().Pitch; string freqHz = pitch.Freq.ToString("0") + "Hz"; pb1.AppendSsmlMarkup("<prosody pitch=\"" + freqHz + "\" rate=\"slow\">" + Word + "</prosody >"); SpeechSynth.Speak(pb1); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.ToString()); } }
public void Say(string text, int volume, int rate) { //foreach (InstalledVoice voice in sp.GetInstalledVoices()) //{ // VoiceInfo info = voice.VoiceInfo; // Console.WriteLine(" Name: " + info.Name); // Console.WriteLine(" Culture: " + info.Culture); // Console.WriteLine(" Age: " + info.Age); // Console.WriteLine(" Gender: " + info.Gender); // Console.WriteLine(" Description: " + info.Description); // Console.WriteLine(" ID: " + info.Id); //} if (volume >= 0 && volume <= 100) sp.Volume = volume; else sp.Volume = 100; // rappresenta la velocità di lettura if (rate >= -10 && rate <= 10) sp.Rate = rate; else sp.Rate = 0; //CultureInfo culture = CultureInfo.CreateSpecificCulture("it-IT"); //spSynth.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Teen, 0, culture); //spSynth.SelectVoice("ScanSoft Silvia_Dri40_16kHz"); //spSynth.SelectVoice("Microsoft Elsa Desktop"); //spSynth.SelectVoice("Paola"); //spSynth.SelectVoice("Luca"); //spSynth.SelectVoice("Roberto"); PromptBuilder builder = new PromptBuilder(); builder.StartVoice("Luca"); builder.StartSentence(); builder.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Strong, Rate = PromptRate.Medium }); string high = "<prosody pitch=\"x-high\"> " + text + " </prosody >"; builder.AppendSsmlMarkup(high); builder.EndStyle(); builder.EndSentence(); builder.EndVoice(); // Asynchronous sp.SpeakAsync(builder); }
byte[] ITextToAudioProvider.ToAudio(Voice voice, string text) { var name = GetVoiceName(voice); var rate = voice == Voice.Word ? 1.0 / _settings.WordVoicingRate : 1; var volume = 10.0 * AppSettings.Instance.General.VoiceVolume; var builder = new PromptBuilder(); var document = new XmlDocument(); var voiceElement = document.CreateElement("voice"); var nameAttribute = document.CreateAttribute("name"); nameAttribute.Value = name; voiceElement.Attributes.Append(nameAttribute); var prosodyElement = document.CreateElement("prosody"); voiceElement.AppendChild(prosodyElement); var rateAttribute = document.CreateAttribute("rate"); rateAttribute.Value = rate.ToString(CultureInfo.InvariantCulture); prosodyElement.Attributes.Append(rateAttribute); var volumeAttribute = document.CreateAttribute("volume"); volumeAttribute.Value = volume.ToString(CultureInfo.InvariantCulture); prosodyElement.Attributes.Append(volumeAttribute); prosodyElement.InnerText = text; //builder.AppendSsmlMarkup($"<voice name=\"{name}\"><prosody rate=\"{rate}\" volume=\"{volume}\">{text}</prosody></voice>"); builder.AppendSsmlMarkup(voiceElement.OuterXml); var stream = new MemoryStream(); _semaphore.Wait(); _synthesizer.SetOutputToWaveStream(stream); _synthesizer.Speak(builder); _semaphore.Release(); var buffer = stream.ToArray(); return(buffer); }
public void SpeakStart(List <string> phonemes, bool async = true) { try { ssmlBuilder = new PromptBuilder(); ssmlBuilder.AppendSsmlMarkup(GetSsml(phonemes)); synthesizer.SetOutputToDefaultAudioDevice(); if (async) { synthesizer.SpeakAsync(ssmlBuilder); } else { synthesizer.Speak(ssmlBuilder); } } catch (Exception) { throw; } }
void PrepareRandomBuffer(int bufferListIndex) { if (bufferListIndex >= _sndFloatBufferList.Count) return; PromptBuilder pb = new PromptBuilder(); string toSay = ""; toSay = "<voice name='" + _currentSpeechVoice._voiceName + "'>"; string sRate = "default"; switch (_speechSynthData._promptRate) { case PromptRate.Slow: sRate = "slow"; break; case PromptRate.Medium: sRate = "medium"; break; case PromptRate.NotSet: sRate = "default"; break; case PromptRate.Fast: sRate = "fast"; break; case PromptRate.ExtraSlow: sRate = "x-slow"; break; case PromptRate.ExtraFast: sRate = "x-fast"; break; } toSay += "<prosody rate='" + sRate + "'>"; toSay += "<phoneme alphabet='x-microsoft-ups' ph='" + _consonantStrings[_rndGen.Next(_consonantStrings.Length)] + " " + _vowelStrings[_rndGen.Next(_vowelStrings.Length)] + " " + "'> A </phoneme>"; toSay += "</prosody>"; toSay += "</voice>"; pb.AppendSsmlMarkup(toSay); _sndFloatBufferList[bufferListIndex] = GetFloatBufferFromPrompt(pb); }
public void Speak(string text, dynamic playDevice, bool isSync, float?volume) { var settings = _plugin.Settings.SApi5Settings; // Calculate hash var wave = _plugin.Cache.GetOrCreateFile( this, text, "wav", settings.ToString(), f => { using (var fileStream = new FileStream( f, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite )) { using (var speechSynthesizer = new SpeechSynthesizer()) { // Get the selected voice var voice = speechSynthesizer.GetInstalledVoices() .FirstOrDefault(it => it.VoiceInfo.Id.ToLower() == settings.Voice); if (voice == null) { _plugin.Controller.NotifyLogMessageAppend(false, $"Unable to find voice {settings.Voice}"); return; } speechSynthesizer.SelectVoice(voice.VoiceInfo.Name); speechSynthesizer.Rate = settings.Rate; speechSynthesizer.Volume = settings.Volume; // Generate markup like "<prosody pitch="default">some text</prosody>" var writer = new StringWriter(); using (var xmlTextWriter = new XmlTextWriter(writer)) { xmlTextWriter.WriteStartElement("prosody"); xmlTextWriter.WriteAttributeString("pitch", ToMarkupValue(settings.Pitch)); xmlTextWriter.WriteString(text); xmlTextWriter.WriteEndElement(); xmlTextWriter.Flush(); } var content = writer.ToString(); var pb = new PromptBuilder(voice.VoiceInfo.Culture); pb.StartVoice(voice.VoiceInfo); pb.AppendSsmlMarkup(content); pb.EndVoice(); fileStream.SetLength(0L); speechSynthesizer.SetOutputToWaveStream(fileStream); speechSynthesizer.Speak(pb); fileStream.Flush(); } } }); _plugin.SoundPlayer.Play(wave, playDevice, isSync, volume); }
private void SpeechTheText(string msg) //最後發音部分 { //tps://msdn.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer%28v=vs.110%29.aspx // Initialize a new instance of the SpeechSynthesizer. if (Speak_pause == true) { return; } SpeechSynthesizer synth = new SpeechSynthesizer(); PromptBuilder pb = new PromptBuilder(); // Configure the audio output. //Win7 Verson.=================================== SpeechSynthesizer synth_J = new SpeechSynthesizer(); if (IsContainsJapanese(msg)) { Speech_Rate = Speech_Rate - 2; try { synth_J.SelectVoice("Microsoft Server Speech Text to Speech Voice (ja-JP, Haruka)"); } catch (Exception ex) { Push_A_message_to_Room("synth.SelectVoice錯誤 Error:" + ex.Message + "\n"); } } else { try { pb.ClearContent(); string prtn = "<voice name=\"Microsoft Server Speech Text to Speech Voice (zh-TW, HanHan)\"><prosody pitch=\"" + Speech_Pitch + "Hz\">" + msg + "</prosody ></voice>"; pb.AppendSsmlMarkup(prtn); } catch (Exception ex) { Push_A_message_to_Room("synth.SelectVoice錯誤 Error:" + ex.Message + "\n"); } } //=============================================== //Win8/10 Ver.=================================== /* * if (IsContainsJapanese(msg)) * { * Speech_Rate = Speech_Rate - 2; * try * { * string prtn = "<voice name=\"Microsoft Haruka Desktop\"><prosody pitch=\"" + Speech_Pitch + "Hz\">" + msg + "</prosody ></voice>"; * pb.AppendSsmlMarkup(prtn); * } * catch (Exception ex) * { * Push_A_message_to_Room("synth.SelectVoice錯誤 Error:" + ex.Message + "\n"); * } * } * else * { * try * { * string prtn = "<voice name=\"Microsoft Hanhan Desktop\"><prosody pitch=\"" + Speech_Pitch + "Hz\">" + msg + "</prosody ></voice>"; * pb.AppendSsmlMarkup(prtn); * } * catch (Exception ex) * { * Push_A_message_to_Room("synth.SelectVoice錯誤 Error:" + ex.Message + "\n"); * } * } */ //=============================================== synth.Volume = Speech_Volume; if (TTS_queue.Count >= 8) //依照Queue中的量控制說話速率 { synth.Rate = 10; } else if (TTS_queue.Count >= 5) { synth.Rate = Speech_Rate + 5; if (synth.Rate > 10) { synth.Rate = 10; } } else { if (Speech_Rate < -10) { synth.Rate = -10; } else { synth.Rate = Speech_Rate; } } // Speak the string. synth.SetOutputToDefaultAudioDevice(); //Win7 Ver.====================================== synth_J.SetOutputToDefaultAudioDevice(); if (IsContainsJapanese(msg)) { try { synth_J.Speak(msg); } catch (Exception ex) { Push_A_message_to_Room("synth.Speak()錯誤 Error:" + ex.Message + "\n"); } Speech_Rate = Speech_Rate + 2; } else { try { synth.Speak(pb); } catch (Exception ex) { Push_A_message_to_Room("synth.Speak()錯誤 Error:" + ex.Message + "\n"); } } synth_J.Dispose(); //=============================================== //Win8/10 Ver.=================================== /* * try * { * synth.Speak(pb); * //synth.Speak(msg); * //Push_A_message_to_Room(TTS_queue.Count + "\n"); * } * catch (Exception ex) * { * Push_A_message_to_Room("synth.Speak()錯誤 Error:" + ex.Message + "\n"); * } * * if (IsContainsJapanese(msg)) * Speech_Rate = Speech_Rate + 2; */ //=============================================== synth.Dispose(); }
private void Answer(string ssmlText) { PromptBuilder builder = new PromptBuilder(); builder.AppendSsmlMarkup(ssmlText); synthesizer.Speak(builder); }