Ejemplo n.º 1
0
Archivo: VI.cs Proyecto: jjonj/AVPI
        public void load_listen(VI_Profile profile, VI_Settings settings, ListView statusContainer)
        {
            this.profile = profile;
            this.settings = settings;
            this.statusContainer = statusContainer;

            vi_syn = profile.synth;
            vi_syn.SelectVoice(settings.voice_info);
            vi_sre = new SpeechRecognitionEngine(settings.recognizer_info);

            GrammarBuilder phrases_grammar = new GrammarBuilder();
            List<string> glossory = new List<string>();

            foreach (VI_Phrase trigger in profile.Profile_Triggers)
            {
                glossory.Add(trigger.value);
            }
            if (glossory.Count == 0)
            {
                MessageBox.Show("You need to add at least one Trigger");
                return;
            }
            phrases_grammar.Append(new Choices(glossory.ToArray()));

            vi_sre.LoadGrammar(new Grammar(phrases_grammar));
            //set event function
            vi_sre.SpeechRecognized += phraseRecognized;
            vi_sre.SpeechRecognitionRejected += _recognizer_SpeechRecognitionRejected;
            vi_sre.SetInputToDefaultAudioDevice();
            vi_sre.RecognizeAsync(RecognizeMode.Multiple);
        }
Ejemplo n.º 2
0
        public frmSettings(VI_Settings vi_settings)
        {
            InitializeComponent();
            MaximizeBox = false;
            this.vi_settings = vi_settings;

            populate_fields();

            // Update fields to show settings loaded from file
            populate_from_settings();
        }
Ejemplo n.º 3
0
        public frmSettings(VI_Settings vi_settings)
        {
            InitializeComponent();
            MaximizeBox      = false;
            this.vi_settings = vi_settings;

            populate_fields();

            // Update fields to show settings loaded from file
            populate_from_settings();
        }
Ejemplo n.º 4
0
        public frmSettings(VI_Settings vi_settings)
        {
            InitializeComponent();
            MaximizeBox      = false;
            this.vi_settings = vi_settings;

            List <String> localizations = new List <String>();

            foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
            {
                localizations.Add(ri.Culture.Name);
            }
            cbSettingsLanguage.DataSource = localizations;

            List <String>     voices      = new List <string>();
            SpeechSynthesizer synthesizer = new SpeechSynthesizer();

            foreach (InstalledVoice voice in synthesizer.GetInstalledVoices())
            {
                voices.Add(voice.VoiceInfo.Name);
            }
            cbSettingsSynthesizer.DataSource = voices;

            List <string> audio_devices = new List <string>();

            //TODO: actually enumerate audio devices.
            audio_devices.Add("Default Directsound device");

            cbSettingsRecordingDevice.DataSource = audio_devices;

            List <string> pushtotalk_mode_list = new List <string>();

            pushtotalk_mode_list.Add("Off");
            pushtotalk_mode_list.Add("Hold");
            pushtotalk_mode_list.Add("PressOnce");
            cbSettingsPushToTalkMode.DataSource   = pushtotalk_mode_list;
            cbSettingsPushToTalkMode.SelectedItem = vi_settings.pushtotalk_mode;

            cbSettingsPushToTalkKey.DataSource   = Enum.GetValues(typeof(Keys)).Cast <Keys>();
            cbSettingsPushToTalkKey.SelectedItem = Enum.Parse(typeof(Keys), vi_settings.pushtotalk_key);
        }
Ejemplo n.º 5
0
        static void Main()
        {
            //  Instantiate a log that maintains a running record of the recognised voice commands.  This log
            //  will be displayed within a ListBox in the main form, frmGAVPI.  We specify a callback method so
            //  that we may inform an already open frmGAVPI to update the ListBox with the log content.

            try {
                Log = new Logging <string>(GAVPI.OnLogMessage);
            } catch (Exception) { throw; }

            vi_settings = new VI_Settings();
            vi_profile  = new VI_Profile(null);

            vi = new InputEngine();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //
            //  To ensure that only a single instance of the application can be executed at a time, we'll use
            //  Mutex ownership to determine if we're already running.  I used http://www.guidgenerator.com/
            //  to create a Globally Unique ID (GUID) as the name of a Mutex, which the application will attempt
            //  to secure before running proper.  If the Mutex can't be secured it means our application is
            //  already running.
            //

            Mutex LockApplicationInstance;
            bool  OnlyApplicationInstance = false;

            //
            //  We'll do something useful if the application is already running by sending it a message asking
            //  it to show itself.  This may be achieved through the native Win32 API PostMessage (an asynchronous
            //  call).  But regardless of whether another instance of the application is running or now, we should
            //  request a message that is unique to our application.
            //

            if ((WM_OPEN_EXISTING_INSTANCE = Win32_APIs.RegisterWindowMessage("WM_OPEN_EXISTING_INSTANCE")) == 0)
            {
                throw new Win32Exception();
            }

            //  Now we can check to see if our application already running...

            if (((LockApplicationInstance = new Mutex(true, APPLICATION_ID, out OnlyApplicationInstance)) != null) &&
                !OnlyApplicationInstance)
            {
                //
                //  It is already running.  Now assuming the user wants to do something productive, let's bring the
                //  existing instance to the front.  PostMessage is non-blocking native Win32 call, so will return
                //  immediately, whose intent is picked up in the frmGAVPI.WndProc() method of the existing instance.
                //

                Win32_APIs.PostMessage((IntPtr)Win32_APIs.HWND_BROADCAST,
                                       WM_OPEN_EXISTING_INSTANCE,
                                       IntPtr.Zero,
                                       IntPtr.Zero);

                //  We can happily quit now.

                return;
            }  //  if()

            //
            //  A system tray icon and associated menu offers an alternative UI, providing the key functionality
            //  of the application in a convenient menu.
            //
            //  So, let's set the Tray Icon's tooltip name, use an instance of the application's icon (from the
            //  project's resources, and provide a handler for when a user double-clicks the system tray icon.

            sysTrayIcon = new NotifyIcon();

            sysTrayIcon.Icon         = Properties.Resources.gavpi;
            sysTrayIcon.Visible      = true;
            sysTrayIcon.DoubleClick += new System.EventHandler(OnDoubleClickIcon);
            sysTrayIcon.Text         = APPLICATION_TITLE;

            //  Our system tray icon's context menu consists of items that may be enabled or disabled depending
            //  on the available workflow.  By default, however, their initial states should be as declared.

            sysTrayMenu = new ContextMenu();

            //  Our MRU menu.  We'll add it to the top of the system tray icon's context menu.

            ProfileMRU = new MRU("Recent", OnMRUListItem);

            sysTrayMenu.MenuItems.Add(ProfileMRU.GetMenu());
            sysTrayMenu.MenuItems.Add("Open Profile", LoadProfile);
            sysTrayMenu.MenuItems.Add("Modify", OpenProfileEditor).Enabled = false;
            sysTrayMenu.MenuItems.Add("-");
            sysTrayMenu.MenuItems.Add("Show Log", OpenMainWindow);
            sysTrayMenu.MenuItems.Add("-");
            sysTrayMenu.MenuItems.Add("Listen", StartListening).Enabled = false;
            sysTrayMenu.MenuItems.Add("Stop", StopListening).Enabled    = false;
            sysTrayMenu.MenuItems.Add("-");
            sysTrayMenu.MenuItems.Add("Settings", OpenSettings);
            sysTrayMenu.MenuItems.Add("-");
            sysTrayMenu.MenuItems.Add("Exit", Exit);

            //  And now we can attach the menu to the system tray icon.

            sysTrayIcon.ContextMenu = sysTrayMenu;

            //  Now let's load the MRU items before running the application propper.

            ProfileMRU.Deserialize();

            //  Let's commence monitoring process startup and automatically open Profiles if any have been
            //  associated with an executable and the option to do so has been set.

            if (Properties.Settings.Default.EnableAutoOpenProfile)
            {
                EnableAutoOpenProfile(null, null);
            }

            //  And display the main window upon start if specified in the configuration.

            if (Properties.Settings.Default.ShowGAVPI)
            {
                OpenMainWindow(null, null);
            }

            Application.Run();

            //  We don't want the garbage collector to think our Mutex is up for grabs before we close the program,
            //  so let's protect it.

            GC.KeepAlive(LockApplicationInstance);

            LockApplicationInstance.ReleaseMutex();
        }  //  static void Main()
Ejemplo n.º 6
0
        static void Main()
        {

            //  Instantiate a log that maintains a running record of the recognised voice commands.  This log
            //  will be displayed within a ListBox in the main form, frmGAVPI.  We specify a callback method so
            //  that we may inform an already open frmGAVPI to update the ListBox with the log content.

            try { 

                Log = new Logging< string >( GAVPI.OnLogMessage );

            } catch( Exception ) { throw; }

            vi_settings = new VI_Settings();
            vi_profile = new VI_Profile( null );

            vi = new InputEngine();
            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //
            //  To ensure that only a single instance of the application can be executed at a time, we'll use
            //  Mutex ownership to determine if we're already running.  I used http://www.guidgenerator.com/
            //  to create a Globally Unique ID (GUID) as the name of a Mutex, which the application will attempt
            //  to secure before running proper.  If the Mutex can't be secured it means our application is
            //  already running.
            //

            Mutex LockApplicationInstance;
            bool OnlyApplicationInstance = false;
            
            //
            //  We'll do something useful if the application is already running by sending it a message asking
            //  it to show itself.  This may be achieved through the native Win32 API PostMessage (an asynchronous
            //  call).  But regardless of whether another instance of the application is running or now, we should
            //  request a message that is unique to our application.
            //

            if( ( WM_OPEN_EXISTING_INSTANCE = Win32_APIs.RegisterWindowMessage( "WM_OPEN_EXISTING_INSTANCE" ) ) == 0 ) {

                throw new Win32Exception();

            }
     
            //  Now we can check to see if our application already running...

            if( ( ( LockApplicationInstance = new Mutex( true, APPLICATION_ID, out OnlyApplicationInstance ) ) != null ) &&
                !OnlyApplicationInstance ) {

                //
                //  It is already running.  Now assuming the user wants to do something productive, let's bring the
                //  existing instance to the front.  PostMessage is non-blocking native Win32 call, so will return
                //  immediately, whose intent is picked up in the frmGAVPI.WndProc() method of the existing instance.
                //

                Win32_APIs.PostMessage( (IntPtr)Win32_APIs.HWND_BROADCAST,
                                        WM_OPEN_EXISTING_INSTANCE,
                                        IntPtr.Zero,
                                        IntPtr.Zero );

                //  We can happily quit now.

                return;

            }  //  if()

            //
            //  A system tray icon and associated menu offers an alternative UI, providing the key functionality
            //  of the application in a convenient menu.
            //
            //  So, let's set the Tray Icon's tooltip name, use an instance of the application's icon (from the
            //  project's resources, and provide a handler for when a user double-clicks the system tray icon.

            sysTrayIcon = new NotifyIcon();

            sysTrayIcon.Icon  = Properties.Resources.gavpi;
            sysTrayIcon.Visible = true;
            sysTrayIcon.DoubleClick += new System.EventHandler( OnDoubleClickIcon );
            sysTrayIcon.Text = APPLICATION_TITLE;

            //  Our system tray icon's context menu consists of items that may be enabled or disabled depending
            //  on the available workflow.  By default, however, their initial states should be as declared.

            sysTrayMenu = new ContextMenu();

            //  Our MRU menu.  We'll add it to the top of the system tray icon's context menu.

            ProfileMRU = new MRU( "Recent", OnMRUListItem );
            
            sysTrayMenu.MenuItems.Add( ProfileMRU.GetMenu() );
            sysTrayMenu.MenuItems.Add( "Open Profile", LoadProfile );
            sysTrayMenu.MenuItems.Add( "Modify", OpenProfileEditor ).Enabled = false;
            sysTrayMenu.MenuItems.Add( "-" );
            sysTrayMenu.MenuItems.Add( "Show Log", OpenMainWindow );
            sysTrayMenu.MenuItems.Add( "-" );
            sysTrayMenu.MenuItems.Add( "Listen", StartListening ).Enabled = false;
            sysTrayMenu.MenuItems.Add( "Stop", StopListening ).Enabled = false;
            sysTrayMenu.MenuItems.Add( "-" );
            sysTrayMenu.MenuItems.Add( "Settings", OpenSettings);
            sysTrayMenu.MenuItems.Add( "-" );
            sysTrayMenu.MenuItems.Add( "Exit", Exit );

            //  And now we can attach the menu to the system tray icon.

            sysTrayIcon.ContextMenu = sysTrayMenu;

            //  Now let's load the MRU items before running the application propper.

            ProfileMRU.Deserialize();

            //  Let's commence monitoring process startup and automatically open Profiles if any have been
            //  associated with an executable and the option to do so has been set.

            if( Properties.Settings.Default.EnableAutoOpenProfile ) EnableAutoOpenProfile( null, null );

            //  And display the main window upon start if specified in the configuration.

            if( Properties.Settings.Default.ShowGAVPI ) OpenMainWindow( null, null );

            Application.Run();          

            //  We don't want the garbage collector to think our Mutex is up for grabs before we close the program,
            //  so let's protect it.

            GC.KeepAlive( LockApplicationInstance );

            LockApplicationInstance.ReleaseMutex();

        }  //  static void Main()
Ejemplo n.º 7
0
Archivo: GAVPI.cs Proyecto: ALyman/AVPI
        static void Main()
        {
            vi_settings = new VI_Settings();
            vi_profile  = new VI_Profile(null);

            vi = new VI();

            //
            //  To ensure that only a single instance of the application can be executed at a time, we'll use
            //  Mutex ownership to determine if we're already running.  I used http://www.guidgenerator.com/
            //  to create a Globally Unique ID (GUID) as the name of a Mutex, which the application will attempt
            //  to secure before running proper.  If the Mutex can't be secured it means our application is
            //  already running.
            //

            Mutex LockApplicationInstance;
            bool  OnlyApplicationInstance = false;

            //
            //  We'll do something useful if the application is already running by sending it a message asking
            //  it to show itself.  This may be achieved through the native Win32 API PostMessage (an asynchronous
            //  call).  But regardless of whether another instance of the application is running or now, we should
            //  request a message that is unique to our application.
            //

            if ((WM_OPEN_EXISTING_INSTANCE = Win32_APIs.RegisterWindowMessage("WM_OPEN_EXISTING_INSTANCE")) == 0)
            {
                throw new Win32Exception();
            }

            //  Now we can check to see if our application already running...

            if (((LockApplicationInstance = new Mutex(true, APPLICATION_ID, out OnlyApplicationInstance)) != null) &&
                !OnlyApplicationInstance)
            {
                //
                //  It is already running.  Now assuming the user wants to do something productive, let's bring the
                //  existing instance to the front.  PostMessage is non-blocking native Win32 call, so will return
                //  immediately, whose intent is picked up in the frmGAVPI.WndProc() method of the existing instance.
                //

                Win32_APIs.PostMessage((IntPtr)Win32_APIs.HWND_BROADCAST,
                                       WM_OPEN_EXISTING_INSTANCE,
                                       IntPtr.Zero,
                                       IntPtr.Zero);

                //  We can happily quit now.

                return;
            }  //  if()

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmGAVPI());

            //  We don't want the garbage collector to think our Mutex is up for grabs before we close the program,
            //  so let's protect it.

            GC.KeepAlive(LockApplicationInstance);

            LockApplicationInstance.ReleaseMutex();
        }  //  static void Main()