private bool SetError(SpeechManagerErrorType error) { if ((ErrorDetected == SpeechManagerErrorType.NoError) || (ErrorDetected == SpeechManagerErrorType.AlertDetected)) { ErrorDetected = error; return(true); } return(false); }
private bool SetError(SpeechManagerErrorType error) { if ((ErrorDetected == SpeechManagerErrorType.NoError) || (ErrorDetected == SpeechManagerErrorType.AlertDetected)) { ErrorDetected = error; return true; } return false; }
/// <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); }
/// <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; }