private void PopulateSource()
        {
            ToolStripMenuItem sm = new ToolStripMenuItem("マイク");

            devices.Clear();

            PXCMAudioSource source = session.CreateAudioSource();

            if (source != null)
            {
                source.ScanDevices();

                for (int i = 0; ; i++)
                {
                    PXCMAudioSource.DeviceInfo dinfo;
                    if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }

                    ToolStripMenuItem sm1 = new ToolStripMenuItem(dinfo.name, null, new EventHandler(Source_Item_Click));
                    devices[sm1] = dinfo;
                    sm.DropDownItems.Add(sm1);
                }

                source.Dispose();
            }

            if (sm.DropDownItems.Count > 0)
            {
                (sm.DropDownItems[0] as ToolStripMenuItem).Checked = true;
            }
            MainMenu.Items.RemoveAt(0);
            MainMenu.Items.Insert(0, sm);
        }
        public void OnImportsSatisfied()
        {
            FLogger.Log(LogType.Debug, "OnImport");
            this.descs = new List <PXCMSession.ImplDesc>();

            this.GetSessionAndSenseManager();

            pxcmStatus sts = pxcmStatus.PXCM_STATUS_NO_ERROR;

            PXCMAudioSource audio = this.session.CreateAudioSource();

            if (audio == null)
            {
                throw new Exception("Could not create audio source.");
            }

            // enumrate audio source
            // scan available devices
            this.deviceInfos = new List <PXCMAudioSource.DeviceInfo>();
            audio.ScanDevices();

            int deviceNum = audio.QueryDeviceNum();

            string[] deviceNames = new string[deviceNum];
            for (int i = 0; i < deviceNum; ++i)
            {
                PXCMAudioSource.DeviceInfo tmpDeviceInfo;
                sts = audio.QueryDeviceInfo(i, out tmpDeviceInfo);
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("Could not get audio device.");
                }

                FLogger.Log(LogType.Debug, "audio device info: " + tmpDeviceInfo.name);
                deviceNames[i] = tmpDeviceInfo.name;
                this.deviceInfos.Add(tmpDeviceInfo);
            }

            EnumManager.UpdateEnum("AudioDevice", deviceNames[0], deviceNames);
            audio.Dispose();


            PXCMSession.ImplDesc inDesc = new PXCMSession.ImplDesc();
            inDesc.cuids[0] = PXCMSpeechRecognition.CUID;

            for (int i = 0; ; ++i)
            {
                // get speech recognition engine
                PXCMSession.ImplDesc outDesc = null;
                sts = this.session.QueryImpl(inDesc, i, out outDesc);
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }

                FLogger.Log(LogType.Debug, "speech recognition engine: " + outDesc.friendlyName);
                this.descs.Add(outDesc);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // create client instance
            client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS));

            string clientId = Guid.NewGuid().ToString();

            client.Connect(clientId, "guest", "guest");

            SubscribeMessage();

            isActive = false;
            //Init speech recognizer
            session = PXCMSession.CreateInstance();
            SetupRecognizer(session);

            Console.WriteLine("Siap melayani boss...");
            Console.WriteLine("Teken 'x' kalau mau mecat saya");
            while (true)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                char           keychar    = pressedKey.KeyChar;
                if (keychar == 'x')
                {
                    break;
                }
            }

            Console.WriteLine("Selamat tinggal bos, senang melayani..");
            client.Disconnect();
            try
            {
                if (sr != null)
                {
                    sr.StopRec();
                    sr.Dispose();
                    sr = null;
                }
                if (source != null)
                {
                    source.Dispose();
                    source = null;
                }
                if (session != null)
                {
                    session.Dispose();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " : " + ex.StackTrace);
            }
        }
Beispiel #4
0
 void CleanUp()
 {
     if (sr != null)
     {
         sr.Dispose();
         sr = null;
     }
     if (source != null)
     {
         source.Dispose();
         source = null;
     }
 }
        private void ReleaseResources()
        {
            speechRecognition.StopRec();
            speechRecognition.Dispose();
            audioSource.Dispose();
            session.Dispose();
            // Stop the worker thread
            processingThread.Abort();

            // Release resources
            faceData.Dispose();
            senseManager.Dispose();
        }
Beispiel #6
0
    void Start()
    {
        session = PXCMSession.CreateInstance();
        source  = session.CreateAudioSource();
        if (source == null)
        {
            Debug.Log("Error Creating Audio Source");
        }

        int numOfDevices = 0;

        for (int i = 0; ; i++)
        {
            PXCMAudioSource.DeviceInfo dinfo;
            if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                break;
            }
            numOfDevices++;
        }

        if (numOfDevices == 0)
        {
            Debug.Log("No Audio Device Found!");
        }

        source.ScanDevices();
        AvailableSources = new string[numOfDevices];
        sourceDeviceInfo = new PXCMAudioSource.DeviceInfo[numOfDevices];

        for (int i = 0; i < numOfDevices; i++)
        {
            PXCMAudioSource.DeviceInfo dinfo;
            if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                AvailableSources[i] = "FailedToQueryDeviceInfo";
                sourceDeviceInfo[i] = null;
                Debug.Log("QueryDeviceInfo Failed for Index " + i.ToString());
            }
            else
            {
                sourceDeviceInfo[i] = dinfo;
                AvailableSources[i] = dinfo.name;
            }
        }
        source.Dispose();
        _isInitialized = true;
        stop           = false;
        reset          = false;
    }
        private void Uninitialize()
        {
            if (senseManager != null)
            {
                senseManager.Dispose();
                senseManager = null;
            }

            if (audioSource != null)
            {
                audioSource.Dispose();
                audioSource = null;
            }

            if (recognition != null)
            {
                recognition.Dispose();
                recognition = null;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Initializes the speech module.
        /// </summary>
        public bool InitalizeSpeech()
        {
            if (_isInitialized)
            {
                return(true);
            }

            ErrorDetected    = SpeechManagerErrorType.NoError;
            SpeechModuleMode = SpeechModuleModeType.CommandControl;

            _isInitialized = false;

            session = PXCMSession.CreateInstance();

            //Get Sources
            source = session.CreateAudioSource();
            if (source == null)
            {
                SetError(SpeechManagerErrorType.CreateAudioSourceFailed);
                return(false);;
            }

            int numOfDevices = 0;

            for (int i = 0; ; i++)
            {
                PXCMAudioSource.DeviceInfo dinfo;
                if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }
                numOfDevices++;
            }

            if (numOfDevices == 0)
            {
                Debug.Log("No Audio Device Found!");
                SetError(SpeechManagerErrorType.NoAudioDeviceFound);
                return(false);
            }

            source.ScanDevices();
            AvailableSources = new string[numOfDevices];
            sourceDeviceInfo = new PXCMAudioSource.DeviceInfo[numOfDevices];

            for (int i = 0; i < numOfDevices; i++)
            {
                PXCMAudioSource.DeviceInfo dinfo;
                if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    AvailableSources[i] = "FailedToQueryDeviceInfo";
                    sourceDeviceInfo[i] = null;
                    Debug.Log("QueryDeviceInfo Failed for Index " + i.ToString());
                    SetError(SpeechManagerErrorType.QueryDeviceInfoFailed);
                }
                else
                {
                    sourceDeviceInfo[i] = dinfo;
                    AvailableSources[i] = dinfo.name;
                }
            }
            source.Dispose();

            //Get Modules
            PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();
            int NumOfModules          = 0;

            PXCMSession.ImplDesc desc1;
            desc.cuids[0] = PXCMSpeechRecognition.CUID;
            for (int i = 0; ; i++)
            {
                if (session.QueryImpl(desc, i, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }
                NumOfModules++;
            }

            if (NumOfModules == 0)
            {
                Debug.Log("No Audio Modules Found!");
                SetError(SpeechManagerErrorType.NoAudioModulesFound);
                return(false);
            }

            AvailableModules = new string[NumOfModules];
            modulesIuID      = new int[NumOfModules];

            for (int i = 0; i < NumOfModules; i++)
            {
                if (session.QueryImpl(desc, i, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    AvailableModules[i] = "FailedToQueryModuleInfo";
                    Debug.Log("QueryImpl Failed for Index " + i.ToString());
                    SetError(SpeechManagerErrorType.QueryImplFailed);
                }
                else
                {
                    AvailableModules[i] = desc1.friendlyName;
                    modulesIuID[i]      = desc1.iuid;
                }
            }

            //Get Languages
            //PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();
            //desc.cuids[0] = PXCMSpeechRecognition.CUID;

            desc.iuid = -1;
            for (int i = 0; i < NumOfModules; i++)
            {
                if (!AvailableModules[i].Equals("FailedToQueryModuleInfo"))
                {
                    desc.iuid = modulesIuID[i];
                    break;
                }
            }

            if (desc.iuid == -1)
            {
                Debug.Log("No Valid Module Found!");
                SetError(SpeechManagerErrorType.NoValidModuleFound);
                return(false);
            }


            PXCMSpeechRecognition vrec;

            if (session.CreateImpl <PXCMSpeechRecognition>(desc, out vrec) < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Debug.Log("CreateImpl for Languages Failed!");
                SetError(SpeechManagerErrorType.CreateImplFailed);
                return(false);
            }

            int NumOfLanguages = 0;

            for (int i = 0; ; i++)
            {
                PXCMSpeechRecognition.ProfileInfo pinfo;
                if (vrec.QueryProfile(i, out pinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }
                NumOfLanguages++;
            }

            AvailableLanguages = new string[NumOfLanguages];
            for (int i = 0; i < NumOfLanguages; i++)
            {
                PXCMSpeechRecognition.ProfileInfo pinfo;
                if (vrec.QueryProfile(i, out pinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    AvailableLanguages[i] = "FailedToQueryProfile";
                    Debug.Log("QueryProfile for Languages Failed!");
                    SetError(SpeechManagerErrorType.QueryProfileFailed);
                }
                else
                {
                    AvailableLanguages[i] = LanguageToString(pinfo.language);
                }
            }
            vrec.Dispose();

            _isInitialized = true;

            return(true);
        }
        private void PopulateSource()
        {
            devices.Clear();
            Debug.Log("PopulateSource");
            source = session.CreateAudioSource();
            if (source != null)
            {
                source.ScanDevices();

                for (int i = 0; ; i++)
                {
                    PXCMAudioSource.DeviceInfo dinfo;
                    if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR) break;
                    devices[i] = dinfo;
                }
                sorceList = new string[devices.Count];
                for (int i = 0; i < devices.Count; i++)
                {
                    sorceList[i] = devices[i].name;
                }
                source.Dispose();
            }
        }
		/// <summary>
		/// Initializes the speech module.
		/// </summary>		
		public bool InitalizeSpeech()
		{
			if (_isInitialized)
			{
				return true;
			}
			
			ErrorDetected = SpeechManagerErrorType.NoError;
			SpeechModuleMode = SpeechModuleModeType.CommandControl;
			
			_isInitialized = false;
			
			session = PXCMSession.CreateInstance();
			
			//Get Sources
			source = session.CreateAudioSource();
			if (source == null)
            {
				SetError(SpeechManagerErrorType.CreateAudioSourceFailed);				
				return false;;
			}
			
			int numOfDevices = 0;
			for (int i=0; ; i++)
            {
                PXCMAudioSource.DeviceInfo dinfo;
                if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR) break;
				numOfDevices++;
			}
			
			if (numOfDevices == 0) 
			{
				Debug.Log("No Audio Device Found!");
				SetError(SpeechManagerErrorType.NoAudioDeviceFound);	
				return false;
			}
						
            source.ScanDevices();
			AvailableSources = new string[numOfDevices];		
			sourceDeviceInfo = new PXCMAudioSource.DeviceInfo[numOfDevices];
			
            for (int i=0; i<numOfDevices ; i++)
            {
                PXCMAudioSource.DeviceInfo dinfo;
                if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR) 
				{	
					AvailableSources[i] = "FailedToQueryDeviceInfo";
					sourceDeviceInfo[i] = null;
					Debug.Log("QueryDeviceInfo Failed for Index " + i.ToString());
					SetError(SpeechManagerErrorType.QueryDeviceInfoFailed);	
				}
				else 
				{
					sourceDeviceInfo[i] = dinfo;
					AvailableSources[i] = dinfo.name;
				}				
			}			
            source.Dispose();
            
			//Get Modules
			PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();			
			int NumOfModules = 0;
			
			PXCMSession.ImplDesc desc1;
            desc.cuids[0] = PXCMSpeechRecognition.CUID;
            for (int i = 0; ; i++)
            {                
				if (session.QueryImpl(desc, i, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR) break;
				NumOfModules++;
			}
			
			if (NumOfModules == 0)
			{
				Debug.Log("No Audio Modules Found!");
				SetError(SpeechManagerErrorType.NoAudioModulesFound);	
				return false;
			}
			
			AvailableModules = new string[NumOfModules];
			modulesIuID = new int[NumOfModules];
			
			for (int i=0; i<NumOfModules ; i++)
			{
                if (session.QueryImpl(desc, i, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR) 
				{
					AvailableModules[i] = "FailedToQueryModuleInfo";
					Debug.Log("QueryImpl Failed for Index " + i.ToString());
					SetError(SpeechManagerErrorType.QueryImplFailed);
				}
				else
				{
					AvailableModules[i] = desc1.friendlyName;					
					modulesIuID[i] = desc1.iuid;
				}                
            }
			
			//Get Languages
			//PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();
            //desc.cuids[0] = PXCMSpeechRecognition.CUID;
			
			desc.iuid = -1;
			for (int i=0; i<NumOfModules ; i++)
			{
				if (!AvailableModules[i].Equals("FailedToQueryModuleInfo")) {
					desc.iuid=modulesIuID[i];
					break;
				}
			}
			
			if (desc.iuid == -1)
			{
				Debug.Log("No Valid Module Found!");
				SetError(SpeechManagerErrorType.NoValidModuleFound);
				return false;
			}
            

            PXCMSpeechRecognition vrec;
            if (session.CreateImpl<PXCMSpeechRecognition>(desc, out vrec) < pxcmStatus.PXCM_STATUS_NO_ERROR) 
			{
				Debug.Log("CreateImpl for Languages Failed!");
				SetError(SpeechManagerErrorType.CreateImplFailed);				
				return false;
			}
    
			int NumOfLanguages = 0;
            for (int i=0; ; i++)
            {
                PXCMSpeechRecognition.ProfileInfo pinfo;
                if (vrec.QueryProfile(i,out pinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR) break;
				NumOfLanguages++;                
            }
			
			AvailableLanguages = new string[NumOfLanguages];
			for (int i=0; i<NumOfLanguages ; i++)
            {
                PXCMSpeechRecognition.ProfileInfo pinfo;
                if (vrec.QueryProfile(i,out pinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR) 
				{
					AvailableLanguages[i] = "FailedToQueryProfile";
					Debug.Log("QueryProfile for Languages Failed!");
					SetError(SpeechManagerErrorType.QueryProfileFailed);						
				}
				else
				{
					AvailableLanguages[i] = LanguageToString(pinfo.language);
				}
            }
            vrec.Dispose();
			
			_isInitialized = true;
			
			return true;
		}
    void Start()
    {
        session = PXCMSession.CreateInstance();
        source = session.CreateAudioSource();
        if (source == null)
        {
            Debug.Log("Error Creating Audio Source");
        }

        int numOfDevices = 0;
        for (int i = 0; ; i++)
        {
            PXCMAudioSource.DeviceInfo dinfo;
            if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR) break;
            numOfDevices++;
        }

        if (numOfDevices == 0)
        {
            Debug.Log("No Audio Device Found!");
        }

        source.ScanDevices();
        AvailableSources = new string[numOfDevices];
        sourceDeviceInfo = new PXCMAudioSource.DeviceInfo[numOfDevices];

        for (int i = 0; i < numOfDevices; i++)
        {
            PXCMAudioSource.DeviceInfo dinfo;
            if (source.QueryDeviceInfo(i, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                AvailableSources[i] = "FailedToQueryDeviceInfo";
                sourceDeviceInfo[i] = null;
                Debug.Log("QueryDeviceInfo Failed for Index " + i.ToString());
            }
            else
            {
                sourceDeviceInfo[i] = dinfo;
                AvailableSources[i] = dinfo.name;
            }
        }
        source.Dispose();
        _isInitialized = true;
        stop = false;
        reset = false;
    }