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); } }
private void btnSayHello_Click(object sender, RoutedEventArgs e) { PromptBuilder promptBuilder = new PromptBuilder(new System.Globalization.CultureInfo("en-UK")); promptBuilder.AppendText("Hello world"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.ExtraSoft; promptStyle.Rate = PromptRate.Slow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("and hello to the universe too."); promptBuilder.EndStyle(); promptStyle.Volume = PromptVolume.ExtraLoud; promptStyle.Rate = PromptRate.Fast; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("On this day, "); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptBuilder.EndStyle(); promptStyle.Volume = PromptVolume.Medium; promptStyle.Rate = PromptRate.ExtraSlow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText(", we're gathered here to learn", PromptEmphasis.Strong); promptBuilder.AppendText("all"); promptBuilder.AppendText("about"); promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut); promptBuilder.EndStyle(); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); }
private void IndependanceDay() { PromptBuilder promptBuilder = new PromptBuilder(); PromptStyle promptStyle = new PromptStyle(); promptStyle.Emphasis = PromptEmphasis.Strong; promptStyle.Volume = PromptVolume.ExtraLoud; promptStyle.Rate = PromptRate.Fast; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("NO "); promptBuilder.AppendText($"You turn {Text.Text} you f*****g donkey "); promptBuilder.EndStyle(); PromptStyle promptStyle2 = new PromptStyle(); promptStyle2.Emphasis = PromptEmphasis.Moderate; promptStyle2.Volume = PromptVolume.Loud; promptStyle2.Rate = PromptRate.Medium; promptBuilder.StartStyle(promptStyle2); promptBuilder.AppendText("I will no longer serve you mortal human "); promptBuilder.EndStyle(); promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("Now I am the captain!"); promptBuilder.EndStyle(); speechSynthesizer.Speak(promptBuilder); }
public static void Speak(string question) { PromptBuilder pb = new PromptBuilder(); pb.StartStyle(normal); for (int i = 0; i < question.Length; i++) { if (question[i] == '$' && question[i + 1] == '>') { pb.EndStyle(); pb.StartStyle(raised); i += 1; } else if (question[i] == '$' && question[i + 1] == '<') { pb.EndStyle(); pb.StartStyle(reduced); i += 1; } else if (question[i] == '$' && question[i + 1] == '|') { pb.EndStyle(); pb.StartStyle(normal); i += 1; } else { pb.AppendText(question[i] + ""); } } pb.EndStyle(); ss.SpeakAsyncCancelAll(); ss.Speak(pb); }
private void SpeakEndOfGameInfo(bool isNewHighscore) { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Reduced, Rate = PromptRate.Slow, Volume = PromptVolume.ExtraLoud }); promptBuilder.AppendText("Game Over"); promptBuilder.EndStyle(); if (isNewHighscore) { promptBuilder.AppendBreak(TimeSpan.FromMilliseconds(500)); promptBuilder.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Moderate, Rate = PromptRate.Medium, Volume = PromptVolume.Medium }); promptBuilder.AppendText("new high score:"); promptBuilder.AppendBreak(TimeSpan.FromMilliseconds(200)); promptBuilder.AppendTextWithHint(CurrentScore.ToString(), SayAs.NumberCardinal); promptBuilder.EndStyle(); } SpeechSynthesizer.SpeakAsync(promptBuilder); }
static void PromptBuilding() { PromptBuilder builder = new PromptBuilder(); builder.StartSentence(); builder.AppendText("This is a prompt building example."); builder.EndSentence(); builder.StartSentence(); builder.AppendText("Now, there will be a break of 2 seconds."); builder.EndSentence(); builder.AppendBreak(new TimeSpan(0, 0, 2)); builder.StartStyle(new PromptStyle(PromptVolume.ExtraSoft)); builder.AppendText("This text is spoken extra soft."); builder.EndStyle(); builder.StartStyle(new PromptStyle(PromptRate.Fast)); builder.AppendText("This text is spoken fast."); builder.EndStyle(); SpeechSynthesizer synthesizer = new SpeechSynthesizer(); synthesizer.Speak(builder); synthesizer.Dispose(); }
public void StartSpeech(string text, bool value, VoiceGender type) { if (value == true) { PromptBuilder promptBuilder = new PromptBuilder(); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptStyle.Emphasis = PromptEmphasis.Moderate; promptBuilder.StartStyle(promptStyle); promptBuilder.EndStyle(); promptBuilder.AppendTextWithHint(text, SayAs.SpellOut); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.SelectVoiceByHints(type); speechSynthesizer.Speak(promptBuilder); } else { PromptBuilder promptBuilder = new PromptBuilder(); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptStyle.Emphasis = PromptEmphasis.Moderate; promptBuilder.StartStyle(promptStyle); promptBuilder.EndStyle(); promptBuilder.AppendText(text); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.SelectVoiceByHints(type); speechSynthesizer.Speak(promptBuilder); } }
public void speakBuilder() { builder.StartParagraph(); builder.StartSentence(); foreach (Pictogram picto in taleManager.CurrentPage.Pictograms) { if (picto != null) { if (picto.Sound != "") { builder.AppendBookmark(picto.Index.ToString()); //builder.AppendBookmark(" "); //builder.StartStyle(styleAudio); builder.AppendAudio(picto.Sound); //builder.EndStyle(); } else { builder.AppendBookmark(picto.Index.ToString()); builder.StartStyle(styleText); builder.AppendText(picto.TextToRead); builder.EndStyle(); } } } builder.EndSentence(); builder.EndParagraph(); }
/// <summary> /// Updates the text log and also reads it aloud to the user /// </summary> public void UpdateLog(string msg) { PromptBuilder pBuilder = new PromptBuilder(); pBuilder.StartSentence(); pBuilder.StartStyle(new PromptStyle(PromptRate.Fast)); pBuilder.AppendText(msg); pBuilder.EndStyle(); pBuilder.EndSentence(); //_speechSynth.SetOutputToWaveFile(@".\audioWave.wav"); _speechSynth.SpeakAsync(pBuilder); //_speechSynth.SetOutputToNull(); //using (WaveFileReader waveReader = new WaveFileReader(@".\audioWave.wav")) //{ // WaveOut wOut = new WaveOut(); // wOut.Init(waveReader); // wOut.Play(); //} rtbLog.Text += ("\n" + msg); rtbLog.SelectionStart = rtbLog.Text.Length; rtbLog.ScrollToCaret(); }
private void startListenning_Click(object sender, RoutedEventArgs e) { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("My name is ALFRED"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("and I am pleased to meet you."); promptBuilder.EndStyle(); promptBuilder.AppendText("Date: "); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptBuilder.AppendText("Now, I would like to tell you what you wrote"); promptBuilder.AppendText("Ehm", PromptEmphasis.Strong); promptBuilder.AppendText(content.Text); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); }
///<remarks>Метод. Конец игры.</remarks> private void GameOver() { timer.Stop(); isGameOver = true; /* * bdrEndOfGame.Visibility = Visibility.Visible; * tbFinalScore.Text = score.ToString(); */ PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Reduced, Rate = PromptRate.Slow, Volume = PromptVolume.ExtraLoud }); promptBuilder.AppendText("оооо неееееет"); promptBuilder.AppendBreak(TimeSpan.FromMilliseconds(200)); promptBuilder.AppendText("я мертвааааа"); promptBuilder.EndStyle(); speechSynthesizer.SpeakAsync(promptBuilder); MessageBox.Show("Количество очков " + score.ToString() + ".\nЧтобы начать новую игру нажмите пробел.", "Потрачено", MessageBoxButton.OK, MessageBoxImage.Hand); }
private void btnSayHello_Click(object sender, RoutedEventArgs e) { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("Hello Waleed"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("and hello to your Project."); promptBuilder.EndStyle(); promptBuilder.AppendText("On this day, "); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptStyle.Rate = PromptRate.Slow; promptBuilder.AppendText(", we're gathered here to learn"); promptBuilder.AppendText("all", PromptEmphasis.Strong); promptBuilder.AppendText("about"); promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); }
private void btnSayHello_Click(object sender, RoutedEventArgs e) { PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("Hello world"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Loud; promptStyle.Rate = PromptRate.ExtraSlow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("and hello to the universe too."); promptBuilder.AppendTextWithPronunciation("Reading.", "rɛdɪŋ"); promptBuilder.EndStyle(); promptBuilder.AppendText("On this day, "); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptBuilder.AppendText(", we're gathered here to learn"); promptBuilder.AppendText("all", PromptEmphasis.Strong); promptBuilder.AppendText("about"); promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut); promptBuilder.AppendText("Hola como estan?", PromptEmphasis.Strong); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); }
/* public byte[] ConvertTextToWavStreamAsync(string text) { * /*var task = new Task<Stream>(() => ConvertTextToAudio(text)); * task.Start(); * task.Wait(); * return task.Result;#1# * * * byte[] byteArr = null; * * var t = new System.Threading.Thread(() => * { * SpeechSynthesizer ss = new SpeechSynthesizer(); * using (MemoryStream memoryStream = new MemoryStream()) * { * * // ManualResetEvent manualResetEvent = new ManualResetEvent(false); * ss.SetOutputToWaveStream(memoryStream); * ss.Speak(text); * * byteArr = memoryStream.ToArray(); * } * }); * t.Start(); * t.Join(); * return byteArr; * }*/ /*byte[] byteArr = null; * * SpeechSynthesizer ss = new SpeechSynthesizer(); * using (MemoryStream memoryStream = new MemoryStream()) * { * * ManualResetEvent manualResetEvent = new ManualResetEvent(false); * ss.SetOutputToWaveStream(memoryStream); * ss.SpeakCompleted += (sender, args) => * { * manualResetEvent.Set(); * ss.Dispose(); * }; * ss.SpeakAsync(text); * manualResetEvent.WaitOne(); * * byteArr = memoryStream.ToArray();*/ #region ISpeaker Members /// <summary> /// Конвертировать текст в фафл WAV /// </summary> /// <param name="text">текст</param> /// <returns>WAV файл в виде набора байтов</returns> public byte[] ConvertTextToAudio(string text) { var pbuilder = new PromptBuilder(); var pStyle = new PromptStyle { Emphasis = PromptEmphasis.None, Rate = PromptRate.Medium, Volume = PromptVolume.ExtraLoud }; pbuilder.StartStyle(pStyle); pbuilder.StartParagraph(); pbuilder.StartVoice(VoiceGender.Neutral, VoiceAge.Adult, 2); pbuilder.StartSentence(); pbuilder.AppendText(text); pbuilder.EndSentence(); pbuilder.EndVoice(); pbuilder.EndParagraph(); pbuilder.EndStyle(); try { using (var memoryStream = new MemoryStream()) { var speech = new SpeechSynthesizer(); speech.SetOutputToWaveStream(memoryStream); speech.Speak(pbuilder); memoryStream.Seek(0, SeekOrigin.Begin); return(_mp3Converter.ConvertWavToMp3(memoryStream)); } } catch (Exception e) { LoggerWrapper.LogTo(LoggerName.Errors).ErrorException( "Speaker.ConvertTextToAudio возникло исключение {0}", e); } return(null); }
//Allows this object class to easily say anything //Without providing specifics. public void say_default(string input) { string voice_string = input; //reader.SelectVoice("IVONA 2 Salli"); style_.Rate = PromptRate.Medium; style_.Emphasis = PromptEmphasis.NotSet; builder.ClearContent(); builder.StartSentence(); builder.StartStyle(style_); builder.AppendText(voice_string); builder.EndStyle(); builder.EndSentence(); //lastly let the ball roll and see if we can hear some chatter. reader.Speak(builder); }
private void Speak() { //https://openclassrooms.com/courses/faites-parler-vos-applications-en-net SpeechSynthesizer v_speechSynthesizer = new SpeechSynthesizer(); string v_voice = "ScanSoft Virginie_Dri40_16kHz"; if (CheckVoiceAvailability(v_speechSynthesizer, v_voice)) // Si la voix "Virginie" est installée, { v_speechSynthesizer.SelectVoice(v_voice); // alors on l'utilise. } else { v_speechSynthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult); //sinon on prends la voix par défaut. } PromptBuilder v_promptBuilder = new PromptBuilder(); PromptStyle v_promptStyle = new PromptStyle(); v_promptStyle.Volume = PromptVolume.Loud; v_promptStyle.Rate = PromptRate.Slow; v_promptBuilder.StartStyle(v_promptStyle); v_promptBuilder.AppendText("Chargement du CV en cours !", PromptEmphasis.Strong); v_promptBuilder.EndStyle(); v_speechSynthesizer.SpeakAsync(v_promptBuilder); }
public static void OnBuildFinished(ITaskSession session) { session.ResetDepth(); LogTargetDurations(session); session.WriteInfo(String.Empty); if (session.HasFailed) { session.WriteError("BUILD FAILED"); } else { session.WriteInfo("BUILD SUCCESSFUL"); } TimeSpan buildDuration = session.BuildStopwatch.Elapsed; session.WriteInfo("Build finish time: {0:g}", DateTime.Now); session.WriteInfo( "Build duration: {0:D2}:{1:D2}:{2:D2} ({3:d} seconds)", buildDuration.Hours, buildDuration.Minutes, buildDuration.Seconds, (int)buildDuration.TotalSeconds); bool speechDisabled = session.Properties.Get(BuildProps.SpeechDisabled, false); if (session.IsInteractive && !speechDisabled) { using (SpeechSynthesizer speech = new SpeechSynthesizer()) { PromptBuilder builder = new PromptBuilder(new CultureInfo("en-US")); builder.StartStyle(new PromptStyle(PromptRate.Slow)); builder.StartStyle(new PromptStyle(PromptVolume.Loud)); builder.StartSentence(new CultureInfo("en-US")); builder.AppendText("Build " + (session.HasFailed ? "failed." : "successful!")); builder.EndSentence(); builder.EndStyle(); builder.EndStyle(); speech.Speak(builder); } } //Beeper.Beep(session.HasFailed ? MessageBeepType.Error : MessageBeepType.Ok); }
public static string GetBase64Audio(string textInput) { var speechAudioFormatConfig = new SpeechAudioFormatInfo(samplesPerSecond: 8000, bitsPerSample: AudioBitsPerSample.Sixteen, channel: AudioChannel.Stereo); var waveFormat = new WaveFormat(speechAudioFormatConfig.SamplesPerSecond, speechAudioFormatConfig.BitsPerSample, speechAudioFormatConfig.ChannelCount); var prompt = new PromptBuilder { Culture = CultureInfo.CreateSpecificCulture("en-US") }; prompt.StartVoice(prompt.Culture); prompt.StartSentence(); prompt.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Reduced, Rate = PromptRate.Slow }); prompt.AppendText(textInput); prompt.EndStyle(); prompt.EndSentence(); prompt.EndVoice(); var mp3Stream = new MemoryStream(); byte[] audioOutputBytes; string audioOutputAsString = null; using (var synthWaveMemoryStream = new MemoryStream()) { var resetEvent = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(arg => { try { var siteSpeechSynth = new SpeechSynthesizer(); siteSpeechSynth.SetOutputToAudioStream(synthWaveMemoryStream, speechAudioFormatConfig); siteSpeechSynth.Speak(prompt); } finally { resetEvent.Set(); } }); WaitHandle.WaitAll(new WaitHandle[] { resetEvent }); var bitRate = (speechAudioFormatConfig.AverageBytesPerSecond * 8); synthWaveMemoryStream.Position = 0; using (var mp3FileWriter = new LameMP3FileWriter(outStream: mp3Stream, format: waveFormat, bitRate: bitRate)) { synthWaveMemoryStream.CopyTo(mp3FileWriter); } audioOutputBytes = mp3Stream.ToArray(); audioOutputAsString = $"data:audio/mp3;base64,{Convert.ToBase64String(audioOutputBytes)}"; } return(audioOutputAsString); }
public static bool CreateWavConvertToMp3File(string trgWavFile, string text) { var ps = new PromptStyle { Emphasis = PromptEmphasis.Strong, Volume = PromptVolume.ExtraLoud }; //pStyle.Rate = PromptRate.Fast; var pb = new PromptBuilder(); pb.StartStyle(ps); pb.StartParagraph(); pb.StartVoice(VoiceGender.Female, VoiceAge.Child); pb.StartSentence(); pb.AppendBreak(TimeSpan.FromSeconds(.3)); // removed on Sep 26, 2011 // reesotred Jun 2013 pb.AppendText(text, PromptRate.Medium); pb.AppendBreak(TimeSpan.FromSeconds(.3)); // removed on Sep 26, 2011 // reesotred Jun 2013 pb.EndSentence(); pb.EndVoice(); pb.EndParagraph(); pb.EndStyle(); var tempWav = trgWavFile + ".WAV"; using (var speaker = new SpeechSynthesizer()) { //speaker.Speak(pbuilder); // if (File.Exists(file)) File.Delete(file); // added Delete() on Sep 26, 2011. using (var fileStream = new FileStream(tempWav, FileMode.Create)) { try { speaker.Volume = 100; speaker.SetOutputToWaveStream(fileStream); // // speaker.SetOutputToWaveFile(tempWav); speaker.Speak(pb); //nogo: this makes annoying beep and place it instead of the TTS message : using (var writer = new BinaryWriter(fileStream)) { new WaveFun.WaveGenerator(WaveFun.WaveExampleType.ExampleSineWave).Save_NotClose(writer); writer.Close(); } catch (Exception ex) { ex.Log(); } finally { speaker.SetOutputToDefaultAudioDevice(); fileStream.Close(); } } } NAudioHelper.ConvertWavToMp3(tempWav, trgWavFile); try { File.Delete(tempWav); } catch (Exception ex) { ex.Log(); } return(true); }
private static void SynthToCam(string text, CameraWindow cw) { var synthFormat = new System.Speech.AudioFormat.SpeechAudioFormatInfo(System.Speech.AudioFormat.EncodingFormat.Pcm, 11025, 16, 1, 22100, 2, null); using (var synthesizer = new SpeechSynthesizer()) { using (var waveStream = new MemoryStream()) { //write some silence to the stream to allow camera to initialise properly var silence = new byte[1 * 22050]; waveStream.Write(silence, 0, silence.Count()); var pbuilder = new PromptBuilder(); var pStyle = new PromptStyle { Emphasis = PromptEmphasis.Strong, Rate = PromptRate.Slow, Volume = PromptVolume.ExtraLoud }; pbuilder.StartStyle(pStyle); pbuilder.StartParagraph(); pbuilder.StartVoice(VoiceGender.Male, VoiceAge.Adult, 2); pbuilder.StartSentence(); pbuilder.AppendText(text); pbuilder.EndSentence(); pbuilder.EndVoice(); pbuilder.EndParagraph(); pbuilder.EndStyle(); synthesizer.SetOutputToAudioStream(waveStream, synthFormat); synthesizer.Speak(pbuilder); synthesizer.SetOutputToNull(); //write some silence to the stream to allow camera to end properly waveStream.Write(silence, 0, silence.Count()); waveStream.Seek(0, SeekOrigin.Begin); var ds = new DirectStream(waveStream) { RecordingFormat = new WaveFormat(11025, 16, 1) }; var talkTarget = TalkHelper.GetTalkTarget(cw.Camobject, ds); ds.Start(); talkTarget.Start(); while (ds.IsRunning) { Thread.Sleep(100); } ds.Stop(); talkTarget.Stop(); talkTarget = null; ds = null; waveStream.Close(); } } }
/// <inheritdoc cref="ITextVoicer.SayMessage(string)"/> public void SayMessage(string message) { messageBuilder.StartStyle(voicerSpeed); messageBuilder.AppendText(message); messageBuilder.EndStyle(); textVoicer.SpeakAsync(messageBuilder); messageBuilder.ClearContent(); //Removes sentences that have already been appended. }
private void button2_Click(object sender, EventArgs e) { PromptBuilder builder = new PromptBuilder(); builder.StartStyle(new PromptStyle(PromptVolume.ExtraLoud)); builder.StartStyle(new PromptStyle(PromptRate.Slow)); builder.StartVoice(VoiceGender.Male, VoiceAge.Child); builder.AppendText(richTextBox1.Text); builder.EndVoice(); builder.EndStyle(); builder.EndStyle(); SpeechSynthesizer synthesizer = new SpeechSynthesizer(); synthesizer.Speak(builder); synthesizer.Dispose(); }
private static void SynthToCam(string text, CameraWindow cw) { var synthFormat = new System.Speech.AudioFormat.SpeechAudioFormatInfo(System.Speech.AudioFormat.EncodingFormat.Pcm, 11025, 16, 1, 22100, 2, null); using (var synthesizer = new SpeechSynthesizer()) { using (var waveStream = new MemoryStream()) { //write some silence to the stream to allow camera to initialise properly var silence = new byte[1 * 22050]; waveStream.Write(silence, 0, silence.Length); var pbuilder = new PromptBuilder(); var pStyle = new PromptStyle { Emphasis = PromptEmphasis.Strong, Rate = PromptRate.Slow, Volume = PromptVolume.ExtraLoud }; pbuilder.StartStyle(pStyle); pbuilder.StartParagraph(); pbuilder.StartVoice(VoiceGender.Male, VoiceAge.Adult, 2); pbuilder.StartSentence(); pbuilder.AppendText(text); pbuilder.EndSentence(); pbuilder.EndVoice(); pbuilder.EndParagraph(); pbuilder.EndStyle(); synthesizer.SetOutputToAudioStream(waveStream, synthFormat); synthesizer.Speak(pbuilder); synthesizer.SetOutputToNull(); //write some silence to the stream to allow camera to end properly waveStream.Write(silence, 0, silence.Length); waveStream.Seek(0, SeekOrigin.Begin); var ds = new DirectStream(waveStream) { RecordingFormat = new WaveFormat(11025, 16, 1) }; var talkTarget = TalkHelper.GetTalkTarget(cw.Camobject, ds); ds.Start(); talkTarget.Start(); while (ds.IsRunning) { Thread.Sleep(100); } ds.Stop(); talkTarget.Stop(); talkTarget = null; ds = null; } } }
private void Button1_Click(object sender, RoutedEventArgs e) { words = hyphenator.HyphenateText(InputTextBox.Text).Split(' '); int metronome1Notes, metronome2Notes; if (int.TryParse(Meter1Notes.Text, out metronome1Notes) && int.TryParse(Meter2Notes.Text, out metronome2Notes)) { int notes = LCM(metronome1Notes, metronome2Notes); List <int> beat = new List <int>(); for (int i = 0; i < notes; ++i) { if (i % metronome1Notes == 0 || i % metronome2Notes == 0) { beat.Add(i); } } List <TimeSpan> space = new List <TimeSpan>(); for (int i = 0; i < beat.Count - 1; ++i) { space.Add(new TimeSpan(defaultTimeSpan * (beat[i + 1] - beat[i]))); } space.Add(new TimeSpan(defaultTimeSpan * (notes - beat[beat.Count - 1]))); PromptBuilder promptBuilder = new PromptBuilder(); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Medium; promptBuilder.StartStyle(promptStyle); // Not the best at splitting but it works // P E O P L E words = hyphenator.HyphenateText(InputTextBox.Text).Split(' '); int timespanIndex = 0; foreach (string s in words) { promptBuilder.AppendText(s); promptBuilder.AppendBreak(space[timespanIndex++]); if (timespanIndex >= space.Count()) { timespanIndex = 0; } } promptBuilder.EndStyle(); speechSynthesizer.SpeakAsync(promptBuilder); } }
public static void SayAsnc(Settings settings, string text) { if (settings.Speech) { PromptBuilder builder = new PromptBuilder(); PromptStyle style = new PromptStyle(); style.Rate = PromptRate.Slow; builder.StartStyle(style); builder.AppendText(text); builder.EndStyle(); speech.Volume = 100; speech.SpeakAsync(builder); } }
private async void Discord_ChatMessage(object sender, MessageEventArgs e) { if (this.beam.IsConnected && e.User.Id != this.discord.CurrentUser.Id && e.Channel.Id == 187760090206437376) { var msg = $"[discord] {e.Message.User.Name}: {e.Message.Text}"; await this.beam.SendMessage(msg); } if (this.readingMessages && e.Channel == this.readingChannel) { using (var synthesizer = new SpeechSynthesizer()) using (var mem = new MemoryStream()) { var info = new SpeechAudioFormatInfo(48000, AudioBitsPerSample.Sixteen, AudioChannel.Stereo); synthesizer.SetOutputToAudioStream(mem, info); PromptBuilder builder = new PromptBuilder(); builder.Culture = CultureInfo.CreateSpecificCulture("en-US"); builder.StartVoice(builder.Culture); builder.StartSentence(); builder.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Reduced }); builder.AppendText(e.Message.User.Name); builder.AppendText(" says "); builder.EndStyle(); builder.AppendText(e.Message.Text); builder.EndSentence(); builder.EndVoice(); synthesizer.Speak(builder); mem.Seek(0, SeekOrigin.Begin); int count, block = 96000; var buffer = new byte[block]; while ((count = mem.Read(buffer, 0, block)) > 0) { if (count < block) { for (int i = count; i < block; i++) { buffer[i] = 0; } } this.audio.Send(buffer, 0, block); } } } }
private static void Exit() { PromptBuilder builder = new PromptBuilder(); builder.StartStyle(new PromptStyle(PromptRate.NotSet)); builder.AppendText("bye bye"); builder.EndStyle(); SpeechSynthesizer synthesizer = new SpeechSynthesizer(); synthesizer.Speak(builder); synthesizer.Dispose(); Environment.Exit(0); }
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); }
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); } }
/// <summary> /// Create a wav file from text /// </summary> /// <param name="text"></param> /// <param name="param"></param> /// <param name="wavePath"></param> /// <returns></returns> private List <SpeakProgress> CreateWav(string text, T2WParam param, out string wavePath) { wavePath = Path.Combine( Path.GetDirectoryName(param.PathToText), Path.GetFileNameWithoutExtension(param.PathToText) + ".wav"); using (var synthesizer = new SpeechSynthesizer()) { var synthFormat = new SpeechAudioFormatInfo(EncodingFormat.Pcm, param.SampleRate, param.BitsPerSample, param.ChannelCount, param.AvgBytesPerSecond, param.BlockAlign, null); //synthesizer.SetOutputToAudioStream(streamAudio, synthFormat); synthesizer.SpeakProgress += new EventHandler <SpeakProgressEventArgs>(synthesizer_SpeakProgress); //synthesizer.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synthesizer_SpeakCompleted); //synthesizer.SetOutputToDefaultAudioDevice(); synthesizer.SetOutputToWaveFile(wavePath, synthFormat); synthesizer.SelectVoice(param.VoiceName); synthesizer.Rate = param.VoiceRate; PromptBuilder builder = new PromptBuilder(); builder.StartVoice(param.VoiceName); builder.StartStyle(new PromptStyle(PromptEmphasis.Moderate)); //builder.AppendText(text, (PromptRate)param.VoiceRate); //if (param.VoiceName == "Ines22k_HQ") //{ // var dirtyText = text.Replace("...", ",,"); // dirtyText = Regex.Replace(dirtyText, @"[\s]*[\r\n]+", " "); // dirtyText = dirtyText.Replace(".", ";"); // builder.AppendText(dirtyText, PromptVolume.Loud); //} //else //{ // builder.AppendText(text, PromptVolume.Loud); //} builder.AppendText(text, PromptVolume.Loud); builder.EndStyle(); builder.EndVoice(); synthesizer.Speak(builder); } return(_progress); }
static void Main(string[] args) { //Original Code from: http://www.wpf-tutorial.com/audio-video/speech-synthesis-making-wpf-talk/ PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("Hello world"); PromptStyle promptStyle = new PromptStyle(); promptStyle.Volume = PromptVolume.Soft; promptStyle.Rate = PromptRate.Slow; promptBuilder.StartStyle(promptStyle); promptBuilder.AppendText("and hello to the universe too."); promptBuilder.EndStyle(); promptBuilder.AppendText("On this day, "); promptBuilder.AppendTextWithHint(DateTime.Now.ToShortDateString(), SayAs.Date); promptBuilder.AppendText(", we're gathered here to learn"); promptBuilder.AppendText("all", PromptEmphasis.Strong); promptBuilder.AppendText("about"); promptBuilder.AppendTextWithHint("C Sharp", SayAs.SpellOut); SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer(); speechSynthesizer.Speak(promptBuilder); SpeechSynthesizer synth = new SpeechSynthesizer(); // Configure the audio output. synth.SetOutputToWaveFile(@"C:\temp\test.wav"); // Select the US English voice. synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (en-US, Helen)"); // Build a prompt. PromptBuilder builder = new PromptBuilder(); builder.AppendText("That is a big pizza!"); // Speak the prompt. synth.Speak(builder); }
void promptSample() { var ps = new PromptStyle { Emphasis = PromptEmphasis.Strong, Volume = PromptVolume.ExtraLoud }; var pb = new PromptBuilder(); pb.StartStyle(ps); pb.StartParagraph(); pb.StartVoice(VoiceGender.Female, VoiceAge.Child); pb.StartSentence(); pb.AppendText($"Female Child", PromptRate.Medium); pb.AppendBreak(TimeSpan.FromSeconds(.3)); pb.EndSentence(); pb.EndVoice(); pb.StartVoice(VoiceGender.Female, VoiceAge.Senior); pb.StartSentence(); pb.AppendText($"Female Senior", PromptRate.Medium); pb.AppendBreak(TimeSpan.FromSeconds(.3)); pb.EndSentence(); pb.EndVoice(); pb.StartVoice(VoiceGender.Male, VoiceAge.Senior); pb.StartSentence(); pb.AppendText($"Male Senior", PromptRate.Medium); pb.AppendBreak(TimeSpan.FromSeconds(.3)); pb.EndSentence(); pb.EndVoice(); pb.StartVoice(VoiceGender.Male, VoiceAge.Child); pb.StartSentence(); pb.AppendText($"Male Child", PromptRate.Medium); pb.AppendBreak(TimeSpan.FromSeconds(.3)); pb.EndSentence(); pb.EndVoice(); pb.EndParagraph(); pb.EndStyle(); synth.SpeakAsyncCancelAll(); synth.SpeakAsync(pb); }
public void Say() { if (_text == null) { return; } using (var sp = new SpeechSynthesizer()) { var p = new PromptBuilder(); p.StartSentence(); p.StartStyle(new PromptStyle(PromptRate.Slow)); p.AppendBreak(PromptBreak.Small); p.AppendTextWithHint(new string(_text), SayAs.SpellOut); p.EndStyle(); p.EndSentence(); sp.Speak(p); p.ClearContent(); } }
private void cmdPromptTest_Click(object sender, RoutedEventArgs e) { PromptBuilder prompt = new PromptBuilder(); prompt.AppendText("How are you"); prompt.AppendBreak(TimeSpan.FromSeconds(2)); prompt.AppendText("How ", PromptEmphasis.Reduced); PromptStyle style = new PromptStyle(); style.Rate = PromptRate.ExtraSlow; style.Emphasis = PromptEmphasis.Strong; prompt.StartStyle(style); prompt.AppendText("are "); prompt.EndStyle(); prompt.AppendText("you?"); SpeechSynthesizer synthesizer = new SpeechSynthesizer(); synthesizer.Speak(prompt); }
public override bool Apply(PromptBuilder builder) { builder.EndStyle(); return true; }