another90sm

TTS

Jul 19th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Speech.Synthesis;
  3.  
  4. namespace TTS
  5. {
  6.     public class StartUp
  7.     {
  8.         private static string message = "Enter text to be read or press Esc to exit";
  9.         private static string volumeMessage = "Enter volume from 0 to 100";
  10.         private static string speechSpeedMessage = "Enter speech speed from -10 to 10";
  11.  
  12.         public static void Main()
  13.         {
  14.             while (true)
  15.             {
  16.                 Console.WriteLine(message);
  17.  
  18.                 if (Console.ReadKey().Key == ConsoleKey.Escape)
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 string text = Console.ReadLine();
  24.  
  25.                 Console.WriteLine(volumeMessage);
  26.                 int volume = int.Parse(Console.ReadLine());
  27.  
  28.                 Console.WriteLine(speechSpeedMessage);
  29.                 int speechSpeed = int.Parse(Console.ReadLine());
  30.  
  31.                 using (SpeechSynthesizer synth = new SpeechSynthesizer())
  32.                 {
  33.                     synth.SetOutputToDefaultAudioDevice();
  34.                     synth.Rate = speechSpeed;
  35.                     synth.Volume = volume;
  36.                     synth.Speak(text);
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment