Example #1
0
 internal Voice(ITerminal terminal)
 {
     synth      = new SpeechSynthesizer();
     m_Terminal = terminal;
 }
Example #2
0
 private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
 {
     maintxt = main;
     maintxt.Text = "You: " + e.Result.Text + "\r\n" + maintxt.Text;
     if (e.Result.Confidence > 0.5 && e.Result.Text == "алиса")
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         Random rnd = new Random();
         Debug.Print(rnd.Next(4).ToString());
         switch (rnd.Next(4))
         {
             case 0:
                 ss.Volume = 100;
                 ss.Rate = 3;
                 ss.SpeakAsync("Чего вам надобно, мой господин?");
                 maintxt.Text = "Me: " + "Чего вам надобно, мой господин?" + "\r\n" + maintxt.Text;
                 //l.Text = e.Result.Text;
                 flag = true;
                 break;
             case 1:
                 ss = new SpeechSynthesizer();
                 ss.Volume = 100;
                 ss.Rate = 3;
                 ss.SpeakAsync("Слушаю");
                 maintxt.Text = "Me: " + "Слушаю" + "\r\n" + maintxt.Text;
                 //l.Text = e.Result.Text;
                 flag = true;
                 break;
             case 2:
                 ss = new SpeechSynthesizer();
                 ss.Volume = 100;
                 ss.Rate = 3;
                 ss.SpeakAsync("Алло, директор?");
                 maintxt.Text = "Me: " + "Алло, директор?" + "\r\n" + maintxt.Text;
                 //l.Text = e.Result.Text;
                 flag = true;
                 break;
             case 3:
                 ss = new SpeechSynthesizer();
                 ss.Volume = 100;
                 ss.Rate = 3;
                 ss.SpeakAsync("Алло");
                 maintxt.Text = "Me: " + "Алло" + "\r\n" + maintxt.Text;
                 //l.Text = e.Result.Text;
                 flag = true;
                 break;
             case 4:
                 ss = new SpeechSynthesizer();
                 ss.Volume = 100;
                 ss.Rate = 3;
                 ss.SpeakAsync("Панки хой");
                 maintxt.Text = "Me: " + "Панки хой" + "\r\n" + maintxt.Text;
                 //l.Text = e.Result.Text;
                 flag = true;
                 break;
         }
     }
     else if (e.Result.Confidence > 0.8 && e.Result.Text == "включи свет" && flag == true && flag1 == true)
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         ss.SpeakAsync("Свет уже всключён, мой господин");
         maintxt.Text = "Me: " + "Свет уже всключён, мой господин" + "\r\n" + maintxt.Text;
         flag = false;
     }
     else if (e.Result.Confidence > 0.5 && e.Result.Text == "включи свет" && flag && !flag1)
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         ss.SpeakAsync("Включаю свет, мой господин");
         maintxt.Text = "Me: " + "Включаю свет, мой господин" +"\r\n" + maintxt.Text;
         try
         {
             using (SerialPort sp = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One))
             {
                 sp.Open();
                 sp.Write("1");
                 sp.Close();
             }
         }
         catch
         {
             
             Check();
         }
         flag = false;
         flag1 = true;
     }
     else if (e.Result.Confidence > 0.8 && e.Result.Text == "выключи свет" && flag == true && flag1 == false)
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         ss.SpeakAsync("Свет уже выключен, мой господин");
         maintxt.Text = "Me: " + "Свет уже выключен, мой господин" +"\r\n" + maintxt.Text;
         flag = false;
     }
     else if (e.Result.Confidence > 0.5 && e.Result.Text == "выключи свет" && flag == true)
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         ss.SpeakAsync("Выключаю свет, мой господин");
         maintxt.Text = "Me: " + "Выключаю свет, мой господин" +"\r\n" + maintxt.Text;
         try
         {
             using (SerialPort sp = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One))
             {
                 sp.Open();
                 sp.Write("0");
                 sp.Close();
             }
         }
         catch
         {
             Check();
         }
         flag = false;
         flag1 = false;
     }
     else if (e.Result.Confidence > 0.8 && e.Result.Text == "температура" && flag)
     {
         string temp;
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         try
         {
             using (SerialPort sp = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One))
             {
                 sp.Open();
                 sp.Write("2");
                 l.Text = sp.ReadLine();
                 sp.Close();
             }
         }
         catch
         {
             Check();
         }
         temp = "на данный момент в комнате температура равна " + l.Text;
         if (Convert.ToInt32(l.Text) % 10 == 1 && Convert.ToInt32(l.Text)/10 != 1)
         {
             temp += " градус, мой господин";
         }
         else if ((Convert.ToInt32(l.Text) % 10 == 2 || Convert.ToInt32(l.Text) % 10 == 3 || Convert.ToInt32(l.Text) % 10 == 4) && Convert.ToInt32(l.Text)/10 != 10)
         {
             temp += " градуса, мой господин";
         }
         else
         {
             temp += " градусов, мой господин";
         }
         ss.SpeakAsync(temp);
         maintxt.Text = "Me: " + temp +"\r\n" + maintxt.Text;
         flag = false;
     }
     else if (e.Result.Confidence > 0.8 && e.Result.Text == "влажность" && flag)
     {
         string temp;
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         try
         {
             using (SerialPort sp = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One))
             {
                 sp.Open();
                 sp.Write("3");
                 l.Text = sp.ReadLine();
                 sp.Close();
             }
         }
         catch
         {
             Check();
         }
         temp = "на данный момент в комнате влажность равна " + l.Text;
         if (Convert.ToInt32(l.Text) % 10 == 1)
         {
             temp += " процент, мой господин";
         }
         else if (Convert.ToInt32(l.Text) % 10 == 2 || Convert.ToInt32(l.Text) % 10 == 3 || Convert.ToInt32(l.Text) % 10 == 4)
         {
             temp += " процента, мой господин";
         }
         else
         {
             temp += " процентов, мой господин";
         }
         ss.SpeakAsync(temp);
         maintxt.Text = "Me: " + temp +"\r\n" + maintxt.Text;
         flag = false;
     }
     
     else if (e.Result.Confidence > 0.8 && e.Result.Text == "погода" && flag)
     {
         WebRequest request;
         request = WebRequest.Create(@"http://informer.gismeteo.ru/xml/34929_1.xml");
         using (var response = request.GetResponse())
         {
             using (var stream = response.GetResponseStream())
             using (var reader = new StreamReader(stream))
             {
                 string data = reader.ReadToEnd();
                 string temp, temp1;
                 string tempmin = null, tempmax = null;
                 Debug.WriteLine(data);
                 XmlDocument xdata = new XmlDocument();
                 xdata.LoadXml(data);
                 //Debug.WriteLine(xdata.InnerText);
                 XmlNodeList temperature = xdata.GetElementsByTagName("TEMPERATURE");
                 XmlNode tempmx = temperature[0].Attributes.GetNamedItem("max");
                 XmlNode tempmn = temperature[0].Attributes.GetNamedItem("min");
                 tempmax = tempmx.InnerText;
                 tempmin = tempmn.InnerText;
                 Debug.WriteLine(tempmax);
                 Debug.WriteLine(tempmin);
                 tempint = (Convert.ToInt32(tempmin) + Convert.ToInt32(tempmax)) / 2;
                 Debug.WriteLine(tempint);
                 SpeechSynthesizer ss = new SpeechSynthesizer();
                 ss.Volume = 100;
                 ss.Rate = 3;
                 temp = tempint.ToString();
                 temp1 = "на данный момент температура в Краснодаре равна " + temp;
                 if (tempint % 10 == 1 && (tempint > 19 || tempint < 10))
                 {
                     temp1 += " градус";
                 }
                 else if (tempint % 10 == 2 || tempint % 10 == 3 || tempint % 10 == 4 && (tempint > 19 || tempint < 10))
                 {
                     temp1 += " градуса";
                 }
                 else
                 {
                     temp1 += " градусов";
                 }
                 ss.SpeakAsync(temp1);
                 maintxt.Text = "Me: " + temp1 +"\r\n" + maintxt.Text;
                 flag = false;
             }
         } 
     }
     else if (e.Result.Confidence > 0.6 && e.Result.Text == "что по нгуену")
     {
         sp.Stream = Properties.Resources.durak;
         sp.Play();
     }
     else if (e.Result.Confidence > 0.7 && e.Result.Text == "горшок включи свет")
     {
         sp.Stream = Properties.Resources.svet;
         sp.Play();
     }
     else if (e.Result.Confidence > 0.7 && e.Result.Text == "горшок воскресни")
     {
         sp.Stream = Properties.Resources.hoy;
         sp.Play();
     }
     else if (e.Result.Confidence > 0.8 && e.Result.Text == "закройся")
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 2;
         ss.SpeakAsync("ариведерчи, надеюсь ты меня потом откроешь");
         maintxt.Text = "Me: " + "ариведерчи, надеюсь ты меня потом откроешь" +"\r\n" + maintxt.Text;
         flag = false;
         Process[] shpion = Process.GetProcessesByName("AIMP");
         if (shpion.Length > 0)
         {
             foreach (Process process in shpion)
             {
                 process.Kill();
             }
         }
         Process[] shpion2 = Process.GetProcessesByName("wmplayer");
         if (shpion2.Length > 0)
         {
             foreach (Process process in shpion2)
             {
                 process.Kill();
             }
         }
     }
     else if (e.Result.Confidence > 0.7 && e.Result.Text == "это что сейчас было")
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         ss.SpeakAsync("извините, мой господин, позволила себе лишнего, можете наказать меня как хотите");
         maintxt.Text = "Me: " + "извините, мой господин, позволила себе лишнего, можете наказать меня как хотите" +"\r\n" + maintxt.Text;
     }
     else if (e.Result.Confidence > 0.85 && e.Result.Text == "вруби музон" && music)
     {
         sp.Stream = Properties.Resources.music;
         sp.Play();
         Thread.Sleep(11500);
         Process.Start(@"C:\Program Files (x86)\AIMP\AIMP.exe");
     }
     else if(e.Result.Confidence > 0.7 && e.Result.Text == "вруби музон"  && !music)
     {
         Process.Start(@"C:\Program Files (x86)\AIMP\AIMP.exe");
     }
     else if (e.Result.Confidence > 0.5 && e.Result.Text == "будь как сбербанк на украине")
     {
         sp.Stream = Properties.Resources.nu_ladno;
         sp.Play();
         Thread.Sleep(2000);
         Application.Exit();
     }
     else if (e.Result.Confidence > 0.7 && e.Result.Text == "режим диско")
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         ss.SpeakAsync("ну ок");
         maintxt.Text = "Me: " + "ну ок" +"\r\n" + maintxt.Text;
         Process.Start(@"C://Users/Admin/Videos/disco.mp4");
     }
     else if (e.Result.Confidence > 0.7 && e.Result.Text == "без музыки")
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         ss.SpeakAsync("ок, поняла");
         maintxt.Text = "Me: " + "ок, поняла" +"\r\n" + maintxt.Text;
         music = false;
     }
     else if (e.Result.Confidence > 0.7 && e.Result.Text == "с музыкой"){
         music = true;
     }
     else if (e.Result.Confidence > 0.5 && e.Result.Text == "дэмэха")
     {
         SpeechSynthesizer ss = new SpeechSynthesizer();
         ss.Volume = 100;
         ss.Rate = 3;
         ss.SpeakAsync("дебил, ты его снёс");
         maintxt.Text = "Me: " + "дебил, ты его снёс" + "\r\n" + maintxt.Text;
         //Process.Start(@"C://Users/Admin/Videos/disco.mp4");
     }
 }
        public static void Main(string[] args)
        {
            int songNumber = -1;
            // Creating a new SpeechSynthesizer object called using System.Speech.Synthesis
            SpeechSynthesizer aSpeechSynthesizer = new SpeechSynthesizer();
            // Making a new song object
            Song aSong = new Song();

            // Array of song paths
            string[] anArrayOfSongPaths =
            { @"C:\Users\noahc\Desktop\Old School Stuff\CIS 122\Lecture Files\Songs\Gorgeous by Taylor Swift.txt",
              @"C:\Users\noahc\Desktop\Old School Stuff\CIS 122\Lecture Files\Songs\Grenade Bruno Mars.txt",
              @"C:\Users\noahc\Desktop\Old School Stuff\CIS 122\Lecture Files\Songs\Too Late by Weeknd.txt",
              @"C:\Users\noahc\Desktop\Old School Stuff\CIS 122\Lecture Files\Songs\Feel Good.txt" };


            // User data entry
            Console.WriteLine("List of songs:");
            Console.WriteLine("Enter 1 for Gorgeous by Taylor Swift");
            Console.WriteLine("Enter 2 for Grenade by Bruno Mars");
            Console.WriteLine("Enter 3 for Too Late by The Weeknd");
            Console.WriteLine("Enter 4 for Feel Good Inc");

            // Try/catch to make sure user enters an int.
            try
            {
                songNumber = Convert.ToInt32(Console.ReadLine());
            }
            catch (System.FormatException e)
            {
                Console.WriteLine("Input needs to be a number between 1 and 4.");
            }


            // Listing Installed Voices

            /*
             * foreach (var v in aSpeechSynthesizer.GetInstalledVoices().Select(v => v.VoiceInfo))
             * {
             *  Console.WriteLine("Name:{0}, Gender:{1}, Age:{2}", v.Description, v.Gender, v.Age);
             * }
             */
            Console.WriteLine();

            // Select a voice
            aSpeechSynthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);


            // Write each line to console and speak the lyrics
            try
            {
                for (int i = 0; i < aSong.GetSong(anArrayOfSongPaths[songNumber - 1]).Length; i++)
                {
                    Console.WriteLine(aSong.GetSong(anArrayOfSongPaths[songNumber - 1])[i]);
                    aSpeechSynthesizer.Speak(aSong.GetSong(anArrayOfSongPaths[songNumber - 1])[i]);
                }
            }
            catch (System.IndexOutOfRangeException e)
            {
                Console.WriteLine("Input needs to be a number between 1 and 4.");
            }

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();

            synth.Speak(" Anna is the most beautiful girl in the world");
        }
Example #5
0
 void _speechSynthesizer_BookmarkReached(SpeechSynthesizer sender, SpeechBookmarkReachedEventArgs args)
 {
     Dispatcher.BeginInvoke(() => MessageBox.Show(args.Bookmark + " Reached"));
 }