Click here to Skip to main content
Click here to Skip to main content

Tagged as

Starting Speech Recognition on Device Events

, 7 Jan 2013 CPOL
Starting Speech Recognition on device events.

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.

 

I just started at Plantronics and started learning the Spokes SDK not too long ago.

Just to show how simple it is to use it and to give some idea on how many cool things can be done, I challenged myself to build this simple plugin that will start the Windows Speech Recognition tool when the headset is placed on (device event Don), and stop the application when the headset is removed (device event Doff).

Here's my IPlugin implementation (pretty much based on the sample code and cleaned up to use only what's needed):

using System;
using System.Windows.Forms;
using System.Threading;
using Plantronics.Device.Common;
using Plantronics.UC.Common;
using System.Diagnostics;
namespace Plantronics.Plugin.Sample.SpeechReco
{
 public class SpeechRecoPlugin : IPlugin
 {
        ISession m_session = null;
        IDevice m_device = null;

       
        public string Name
        {
            get { return "Plantronics SDK Speech Recognition Plugin"; }
        }
        
        public bool Init()
        {
            m_session = SessionManager.Instance.Register(Name);
            if (m_session != null)

            {
                m_device = m_session.ActiveDevice;
                if (m_device != null)
                {
                    // looking for Don and Doff only
                    // Don - start windows speech recognition app
                    // Doff - exits the app
                    m_device.DeviceListener.HeadsetStateChanged += new DeviceListenerEventHandler(
                        DeviceListener_HeadsetStateChanged);
                }

            }
            return true;
        }
         // Exit code
        public void Exit()
        {   
            if (m_device != null)
            {

                m_device.DeviceListener.HeadsetStateChanged -= DeviceListener_HeadsetStateChanged;
            }
            SessionManager.Instance.UnRegister(m_session);
        }
        #region DeviceListener events
        void DeviceListener_HeadsetStateChanged(object sender, DeviceListenerEventArgs e)
        {
            if (e.HeadsetStateChange == HeadsetStateChange.Don)
            {

                // check if speech reco tool is already running
                Boolean isSapiRunning = false;
                foreach (Process clsProcess in Process.GetProcesses())
                {
                    if (clsProcess.ProcessName.Contains("sapisvr"))
                    {
                        isSapiRunning = true;
                        break;
                    }

                }
                // start msft speech reco tool
                if (!isSapiRunning)
                {
                    Process p = Process.Start(@"C:\Windows\Speech\Common\sapisvr.exe",
                        @"-SpeechUX");
                }
            }
            else if (e.HeadsetStateChange == HeadsetStateChange.Doff)
            {

                foreach (Process clsProcess in Process.GetProcesses())
                {
                    if (clsProcess.ProcessName.Contains("sapisvr"))
                    {
                        clsProcess.CloseMainWindow();
                        break;
                    }
                }
            }

        }
 
        #endregion DeviceListener events
 }
}

The same code can be used to start and stop any other application, and other events could be used to automate other tasks on your PC as well.

Here's are some pointers from Microsoft on speech recognition:

http://windows.microsoft.com/en-US/windows7/What-can-I-do-with-Speech-Recognition

And I highly recommend (this is really a must do) setting up your headset as the microphone to be used for speech recognition.

http://windows.microsoft.com/en-US/windows7/Set-up-your-microphone-for-Speech-Recognition

I hope you enjoy, and keep us posted on all sort of other cool things you are doing with the SDK.

This article was written by Ricardo de Andrade. Ricardo is a Systems Architect and Evangelist at Plantronics helping the developer community, clients and partners with the Spokes SDK and building solutions around current and future offerings. Ricardo has an extensive background in software and cloud distributed architectures, and in specific telecommunications. Ricardo previously worked for Microsoft where he helped clients and partners to develop cloud based speech recognition applications and integrate their web services into the Microsoft Tellme services.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Plantronics

United States United States
Today’s smart devices and applications have untapped potential in the realm of context-aware computing. Plantronics is making it possible for its audio devices to deliver contextual information to a range of applications through Plantronics headsets. The Plantronics Spokes SDK allows developers to create a range of business applications that will have the power to change the way we communicate and collaborate.

Please check out our DevZone for more info on the Spokes SDK:
http://developer.plantronics.com/community/devzone

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 7 Jan 2013
Article Copyright 2012 by Plantronics
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid