public TextToSpeechAction(string speechText, SpeechRate speechRate, SpeechVolume speechVolume) : this() { this.SpeechText = speechText; this.SpeechRate = speechRate; this.SpeechVolume = speechVolume; }
public override ActionBase GetAction() { if (!string.IsNullOrEmpty(this.TextToSpeechMessageTextBox.Text) && this.TextToSpeechVolumeComboBox.SelectedIndex >= 0 && this.TextToSpeechRateComboBox.SelectedIndex >= 0) { SpeechVolume volume = EnumHelper.GetEnumValueFromString <SpeechVolume>(this.TextToSpeechVolumeComboBox.Text); SpeechRate rate = EnumHelper.GetEnumValueFromString <SpeechRate>(this.TextToSpeechRateComboBox.Text); return(new TextToSpeechAction(this.TextToSpeechMessageTextBox.Text, rate, volume)); } return(null); }
public void ShouldSetTheSpeechRateOnPredefinedValue(SpeechRate rate, string expected) { string speech = new Speech() .Say("When I wake up,") .Say("I can speak with different rate") .WithRate(rate) .Say(".") .Build(); speech.Should().Be($"<speak>When I wake up, <prosody rate=\"{expected}\">I can speak with different rate</prosody>.</speak>"); }
public async Task SayText(string text, SpeechRate rate, SpeechVolume volume) { PromptStyle style = new PromptStyle(); switch (rate) { case SpeechRate.ExtraFast: style.Rate = PromptRate.ExtraFast; break; case SpeechRate.Fast: style.Rate = PromptRate.Fast; break; case SpeechRate.Medium: style.Rate = PromptRate.Medium; break; case SpeechRate.Slow: style.Rate = PromptRate.Slow; break; case SpeechRate.ExtraSlow: style.Rate = PromptRate.ExtraSlow; break; } switch (volume) { case SpeechVolume.Default: style.Volume = PromptVolume.Default; break; case SpeechVolume.ExtraLoud: style.Volume = PromptVolume.ExtraLoud; break; case SpeechVolume.Loud: style.Volume = PromptVolume.Loud; break; case SpeechVolume.Medium: style.Volume = PromptVolume.Medium; break; case SpeechVolume.Soft: style.Volume = PromptVolume.Soft; break; case SpeechVolume.ExtraSoft: style.Volume = PromptVolume.ExtraSoft; break; } PromptBuilder prompt = new PromptBuilder(); prompt.StartStyle(style); prompt.AppendText(text); prompt.EndStyle(); SpeechSynthesizer synthesizer = new SpeechSynthesizer(); Prompt promptAsync = synthesizer.SpeakAsync(prompt); while (!promptAsync.IsCompleted) { await Task.Delay(1000); } }
public ProsodyWriter(ISpeechWriter writer, SpeechRate rate) { _writer = writer; _rate = rate; }
public ISpeech WithRate(SpeechRate rate) { _writer = new ProsodyWriter(_writer, rate); return(this); }
public Task SayText(string text, TextToSpeechVoice voice, SpeechRate rate, SpeechVolume volume) { PromptStyle style = new PromptStyle(); switch (rate) { case SpeechRate.ExtraFast: style.Rate = PromptRate.ExtraFast; break; case SpeechRate.Fast: style.Rate = PromptRate.Fast; break; case SpeechRate.Medium: style.Rate = PromptRate.Medium; break; case SpeechRate.Slow: style.Rate = PromptRate.Slow; break; case SpeechRate.ExtraSlow: style.Rate = PromptRate.ExtraSlow; break; } switch (volume) { case SpeechVolume.Default: style.Volume = PromptVolume.Default; break; case SpeechVolume.ExtraLoud: style.Volume = PromptVolume.ExtraLoud; break; case SpeechVolume.Loud: style.Volume = PromptVolume.Loud; break; case SpeechVolume.Medium: style.Volume = PromptVolume.Medium; break; case SpeechVolume.Soft: style.Volume = PromptVolume.Soft; break; case SpeechVolume.ExtraSoft: style.Volume = PromptVolume.ExtraSoft; break; } PromptBuilder prompt = new PromptBuilder(); prompt.StartStyle(style); prompt.AppendText(text); prompt.EndStyle(); Task.Run(async() => { try { using (SpeechSynthesizer synthesizer = new SpeechSynthesizer()) { if (voice == null) { voice = this.GetInstalledVoices().FirstOrDefault(); } if (voice != null) { synthesizer.SelectVoice(voice.Name); } Prompt promptAsync = synthesizer.SpeakAsync(prompt); while (!promptAsync.IsCompleted) { await Task.Delay(1000); } } } catch (Exception ex) { Logger.Log(ex); } }); return(Task.FromResult(0)); }