deepender singla

deepender singla

  • NA
  • 113
  • 76.8k

Speech in power point

Sep 29 2011 9:31 AM
 i have two programs one is this which is speech controlled:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Speech.Recognition;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;










namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
           
        }








        private void Form1_Load(object sender, EventArgs e)
        {
          //
            // Create a new SpeechRecognizer instance.
            sr = new SpeechRecognizer();
           








            // Create a simple grammar that recognizes "red", "green", or "blue".
            Choices colors = new Choices();
         
            colors.Add("ppt");
            colors.Add("Send");




           












            GrammarBuilder gb = new GrammarBuilder();
            gb.Append(colors);




            // private string command = "#";








            // Create the actual Grammar instance, and then load it into the speech recognizer.
            Grammar g = new Grammar(gb);
            sr.LoadGrammar(g);








            // Register a handler for the SpeechRecognized event.
            sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);
           
        }




     
       
        // Simple handler for the SpeechRecognized event.
        private void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result.Text == "ppt")
            {
                Process.Start("F://Desktop//MICRO_-_lecture1.pptx");
                Thread.Sleep(2000);
             //   SendKeys.Send(" ");

}

 private SpeechRecognizer sr;


            }
    }


   


 when i run this program and when i say ppt ppt gets open now i want that when i say next , next ppt comes and when i say previous previous ppt comes and my second program in which i am  controlling through ppt button is this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;




namespace WindowsFormsApplication10
{
   public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);
       
        private Process p;


        private string fileName = "F://Desktop//MICRO_-_lecture1.pptx"; // insert your Powerpoint file name here


        public Form1()
        {
            InitializeComponent();
            btnLaunch.Click += btnLaunch_Click;
   btnNext.Click += btnNext_Click;
   btnPrevious.Click += btnPrevious_Click;
}




        private void btnLaunch_Click(object sender, EventArgs e)
        {
            // launch Powerpoint slide show
            p = Process.Start(fileName);
            btnNext.Enabled = true;
            btnPrevious.Enabled = true;
            btnLaunch.Enabled = false;
        }


        private void btnNext_Click(object sender, EventArgs e)
        {
            SetForegroundWindow(p.MainWindowHandle);
            p.WaitForInputIdle();
            SendKeys.Send("{PGDN}");
        }


        private void btnPrevious_Click(object sender, EventArgs e)
        {
            SetForegroundWindow(p.MainWindowHandle);
            p.WaitForInputIdle();
            SendKeys.Send("{PGUP}");
        }


        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            p.CloseMainWindow();
            p.Dispose();
        }


        private void Form1_Load(object sender, EventArgs e)
        {


        }    
    }
}
 how i can combine both program ?


 

i tried to combine both program and made this program it is not showing any error but also it is not taking any speech command, the program is this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.VisualBasic;
using System.Collections;
using System.Threading;
using System.Speech.Recognition;


namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);


        private Process p;


        private string fileName = "F://Desktop//MICRO_-_lecture1.pptx"; // insert your Powerpoint file name here


        private void Form1_Load(object sender, EventArgs e)
        {
            //
            // Create a new SpeechRecognizer instance.
            sr = new SpeechRecognizer();










            // Create a simple grammar that recognizes "red", "green", or "blue".
            Choices colors = new Choices();
            // colors.Add("red");
            // colors.Add("green");
            colors.Add("Time");
            colors.Add("Next");
            colors.Add("Previous");
           














            GrammarBuilder gb = new GrammarBuilder();
            gb.Append(colors);




            // private string command = "#";








            // Create the actual Grammar instance, and then load it into the speech recognizer.
            Grammar g = new Grammar(gb);
            sr.LoadGrammar(g);








            // Register a handler for the SpeechRecognized event.
            sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);


        }








        // Simple handler for the SpeechRecognized event.
        private void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result.Text == "Time")
            {
                p = Process.Start(fileName);
            }
            else if (e.Result.Text == "Next")
            {
                SetForegroundWindow(p.MainWindowHandle);
                p.WaitForInputIdle();
                SendKeys.Send("{PGDN}");
            }
            else if (e.Result.Text == "Previous")
            {
                SetForegroundWindow(p.MainWindowHandle);
                p.WaitForInputIdle();
                SendKeys.Send("{PGUP}");
            }
        }
           
        private SpeechRecognizer sr;


    }
}
plz help how i can have appropiate result...



Answers (1)