IT rekvalifikace s garancí práce. Seniorní programátoři vydělávají až 160 000 Kč/měsíc a rekvalifikace je prvním krokem. Zjisti, jak na to!
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

BOT

Robot

C# .NET

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Speech.Synthesis;
using System.Globalization;
using System.Threading;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        
        SpeechSynthesizer speech;
        public Form1()
        {
            InitializeComponent();

            speech = new SpeechSynthesizer();
            speech.SelectVoice("Microsoft Jakub");
            CultureInfo.CurrentCulture = new CultureInfo("cs-CZ",true); //Funguje jen "en-US"        
            SpeechRecognitionEngine reco = new SpeechRecognitionEngine(new CultureInfo("cs-CZ"));          
            try
            {
                
                reco.RequestRecognizerUpdate();
                reco.LoadGrammar(new DictationGrammar());
                reco.SpeechRecognized += Reco_SpeechRecognized;
                reco.SetInputToDefaultAudioDevice();
                reco.RecognizeAsync(RecognizeMode.Multiple);
            }
            catch 
            {

                
            }
        }


        bool ok = true;
        private void Reco_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            //Sendtext(e.Result.Text);
            if (ok)
            {
                
                speech.Speak(e.Result.Text);

            }

            if (e.Result.Text.Contains("A double") || e.Result.Text.Contains("a double"))
            {
               

                try

                {

                    SpeechSynthesizer a = new SpeechSynthesizer();
                    a.SelectVoice("Microsoft Jakub");
                    a.Speak("Dobře, co mam dělat");
                    ok = false;
                   
                }

                catch

                {

                    return;

                }




            }


            if (!ok)
            {
                if (e.Result.Text.Contains("opens") || e.Result.Text.Contains("e-mail"))
                {
                    Process p = new Process();
                    ProcessStartInfo proc = new ProcessStartInfo();

                    proc.UseShellExecute = true;

                    proc.WorkingDirectory = Environment.CurrentDirectory;

                    proc.FileName = Application.ExecutablePath;

                    try

                    {

                        SpeechSynthesizer a = new SpeechSynthesizer();
                        a.Speak("Ok");                  
                        Process.Start("https://mail.google.com/mail/u/0/?tab=rm&ogbl#inbox");
                      
                    }

                    catch

                    {

                        return;

                    }

                }
                if (e.Result.Text.Contains("local") || e.Result.Text.Contains("Kenya"))
                {
                    Process p = new Process();
                    ProcessStartInfo proc = new ProcessStartInfo();

                    proc.UseShellExecute = true;

                    proc.WorkingDirectory = Environment.CurrentDirectory;

                    proc.FileName = Application.ExecutablePath;

                    try

                    {

                        SpeechSynthesizer a = new SpeechSynthesizer();
                        a.Speak("Ok");
                        Process.Start("E:\\lol\\LeagueClient.exe");
                        
                        

                    }

                    catch

                    {

                        return;

                    }


                    

                }

                if (e.Result.Text.Contains("phrase") || e.Result.Text.Contains("books") || e.Result.Text.Contains("base"))
                {

                    try

                    {


                        System.Diagnostics.Process.Start("https://facebook.com");

                    }

                    catch

                    {

                        return;

                    }



                }


                if (e.Result.Text.Contains("new program") || e.Result.Text.Contains("program"))
                {

                    try

                    {

                        
                        SpeechSynthesizer a = new SpeechSynthesizer();
                        a.SelectVoice(comboBox1.Text);
                        Application.Exit();

                    }

                    catch

                    {

                        return;

                    }



                }



            }
          
        }


        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
        const int WM_SETTEXT = 0x000C;

        static void Sendtext(string h)
        {
            Process notepadProccess = Process.GetProcessesByName("notepad")[0];
            IntPtr notepadTextbox = FindWindowEx(notepadProccess.MainWindowHandle, IntPtr.Zero, "Edit", null);
            SendMessage(notepadTextbox, WM_SETTEXT, 0, h);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
       
            foreach (var voice in speech.GetInstalledVoices())
            {
                comboBox1.Items.Add(voice.VoiceInfo.Name);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            speech.SelectVoice(comboBox1.Text);
        }
    }
}

Neformátovaný

Přidáno: 30.5.2020
Expirace: Neuvedeno

Avatar
Autor: Senpai
Aktivity