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 ShouldSetTheSpeechVolumeOnPredefinedValue(SpeechVolume volume, string expected) { string speech = new Speech() .Say("Normal volume for the first sentence.") .Say("Different volume for the second sentence") .WithVolume(volume) .Say(".") .Build(); speech.Should().Be($"<speak>Normal volume for the first sentence. <prosody volume=\"{expected}\">Different volume for the second sentence</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, SpeechVolume volume) { _writer = writer; _volume = volume; }
public ISpeech WithVolume(SpeechVolume volume) { _writer = new ProsodyWriter(_writer, volume); 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)); }