Search This Blog

Friday, November 20, 2020

C#- AI-Programming

using Microsoft.Office.Core;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Configuration;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Runtime.InteropServices;

using System.Speech.Recognition;

using System.Speech.Synthesis;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace CTestEBoard

{

    public partial class Form1 : Form

    {  // Create a new SpeechRecognitionEngine instance.

        SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));

 

        SpeechSynthesizer s = new SpeechSynthesizer();

        Choices list = new Choices();

        public void say(string h)

        {

            s.Speak(h);

        }

        private void rec_SpeachRecognized(object sender, SpeechRecognizedEventArgs e)

        {

            String r = e.Result.Text;

            //what you say

            if (r == "hello")

            {

                // what it says

                say("hi");

            }

            //what you say

            if (r == "Please exit the window")

            {

                // what it says

                say("Great, !");

                this.Close();

            }

        }

        public Form1()

        {

            SpeechRecognitionEngine rec = new SpeechRecognitionEngine();

            list.Add(new String[] { "hello", "Please exit the window" });

 

            Grammar gr = new Grammar(new GrammarBuilder(list));

 

            try

            {

                rec.RequestRecognizerUpdate();

                rec.LoadGrammar(gr);

                rec.SpeechRecognized += rec_SpeachRecognized;

                rec.SetInputToDefaultAudioDevice();

                rec.RecognizeAsync(RecognizeMode.Multiple);

            }

            catch { return; }

            s.SelectVoiceByHints(VoiceGender.Female);

 

            s.Speak("Welcome to Production, Excellence Board");

 

            InitializeComponent();         

         

        }

 

     

 

 

 

    }

}


No comments:

Post a Comment