Ejemplo n.º 1
0
        public SoundDataProcessor(KeyboardInputProcessor keyboard)
        {
            ConfigureLogManager();
            keyboardProcessor = keyboard;
            kinectAudioResourse = new KinectAudioSource();
            kinectAudioResourse.FeatureMode = true;
            kinectAudioResourse.AutomaticGainControl = false; //Important to turn this off for speech recognition
            kinectAudioResourse.SystemMode = SystemMode.OptibeamArrayOnly; //No AEC for this sample

            ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == recognizerId).FirstOrDefault();

            if (ri == null)
            {
                Trace.WriteLine("Could not find speech recognizer: {0}. Please refer to the sample requirements.", recognizerId);
                throw new System.InvalidOperationException("Could not find speech recognizer: {0}. Please refer to the sample requirements." + recognizerId);
            }

            sre = new SpeechRecognitionEngine(ri.Id);
            speechCommands = new Choices();

            speechCommands.Add("jump");
            speechCommands.Add("reload");
            speechCommands.Add("aim");
            speechCommands.Add("knife");
            speechCommands.Add("grenade");

            speechCommands.Add("menu");
            speechCommands.Add("pause");
            speechCommands.Add("select");
            speechCommands.Add("okay");
            speechCommands.Add("enter");
            speechCommands.Add("up");
            speechCommands.Add("down");
            speechCommands.Add("left");
            speechCommands.Add("right");

            gb = new GrammarBuilder();
            gb.Culture = ri.Culture;
            gb.Append(speechCommands);

            grammar = new Grammar(gb);
            sre.LoadGrammar(grammar);

            audioSourceStream = kinectAudioResourse.Start();
            sre.SetInputToAudioStream(audioSourceStream,
                                                  new SpeechAudioFormatInfo(
                                                      EncodingFormat.Pcm, 16000, 16, 1,
                                                      32000, 2, null));
            sre.RecognizeAsync(RecognizeMode.Multiple);
            handleRequests = new Semaphore(0, (int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS);
            requestSoundData = new Semaphore((int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS, (int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS);

            dataQueue = new Queue<SoundData>();
            threadExit = false;

            soundProcessorThread = new Thread(SoundProcessorModule);
            soundProcessorThread.Name = "SoundProcessorThread";
            soundProcessorThread.SetApartmentState(ApartmentState.MTA);
            soundProcessorThread.Start();
        }
Ejemplo n.º 2
0
        public DepthDataProcessor(KeyboardInputProcessor keyboard)
        {
            keyboardProcessor = keyboard;
            handleRequests = new Semaphore(0, (int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS);
            requestDepthData = new Semaphore((int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS, (int)SemaphoreConstants.MAX_CONCURRENT_REQUESTS);

            dataQueue = new Queue<DepthData>();
            threadExit = false;
            depthProcessorThread = new Thread(DepthProcessorModule);
            depthProcessorThread.Name = "DepthProcessorThread";
            depthProcessorThread.Start();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets up the Kinect events and starts all the worker threads that do all the processing
        /// </summary>
        /// <param name="video">Iamge object from the GUI thread</param>
        /// <param name="skeleton">Canvas object from the GUI thread</param>
        /// <param name="transformedSkeleton">Second canvas object from the GUi thread</param>
        public KinectNuiInterface(Image video, Canvas skeleton, Canvas transformedSkeleton)
        {
            try
            {
                nuiRuntime = Runtime.Kinects[0];// new Runtime();
                ConfigureLogManager();
                kinectEventLogger.Info("Sucessfully configured log manager.");

            }
            catch(InvalidOperationException)
            {
                System.Windows.MessageBox.Show("Sorry!!!!!!Failed to configure the Logger");
            }

            try
            {
                kinectEventLogger.Info("Intializing nuiRuntime object");
                nuiRuntime.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor);
                //to experiment, toggle TransformSmooth between true & false
                // parameters used to smooth the skeleton data
                ///*
                nuiRuntime.SkeletonEngine.TransformSmooth = true;
                TransformSmoothParameters parameters = new TransformSmoothParameters();
                parameters.Smoothing = 0.0f;
                parameters.Correction = 0.0f;
                parameters.Prediction = 0.0f;
                parameters.JitterRadius = 0.0f;
                parameters.MaxDeviationRadius = 0.0f;
                //nuiRuntime.SkeletonEngine.SmoothParameters = parameters; ///*
            }

            catch (InvalidOperationException)
            {
                kinectEventLogger.Fatal("Error - Intialization failed, make sure Kinect is plugged in.");

                System.Windows.MessageBox.Show("Kinect NUI initialization failed. Please make sure Kinect device is plugged in.");
                nuiRuntime = null;
                return;
            }

            try
            {
                kinectEventLogger.Info("Sucessfully intialized Kinect runtime object");
                kinectEventLogger.Info("Opening the video and depth streams");
                nuiRuntime.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
                nuiRuntime.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
            }
            catch (InvalidOperationException)
            {
                kinectEventLogger.Fatal("Failed to open stream. Please make sure to specify a supported image type and resolution.");
                System.Windows.MessageBox.Show("Failed to open stream. Please make sure to specify a supported image type and resolution.");
                return;
            }

            try
            {
                kinectEventLogger.Debug("Signing up for the runtime events");
                //nuiRuntime.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nuiRuntime_DepthFrameReady);
                nuiRuntime.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nuiRuntime_SkeletonFrameReady);
                nuiRuntime.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nuiRuntime_VideoFrameReady);

                appStartTime = DateTime.Now;
                kinectEventLogger.Debug("App start time = " + appStartTime.TimeOfDay.ToString());

                kinectEventLogger.Debug("Creating KeyboardProcessor object");
                //create keyboard thread to process keyboard inputs
                keyboardProcessor = new KeyboardInputProcessor();

                //create mouse thread to process mouse input
                mouseProcessor = new MouseInputProcessor();

                //create the Depth processor object
                //depthProcessor = new DepthDataProcessor(keyboardProcessor);

                //create the video processor object
                kinectEventLogger.Debug("Creating videoProcessor object");
                videoProcessor = new VideoDataProcessor(video);

                //create object for skeleton processor
                kinectEventLogger.Debug("Creating skeletalProcessor object");
                skeletalProcessor = new SkeletalDataProcessor(nuiRuntime, skeleton, keyboardProcessor, mouseProcessor, transformedSkeleton);

                kinectEventLogger.Debug("Intializing Sound object intializer thread");
                Thread soundInitializerThread = new Thread(IntializerThreadFunc);
                soundInitializerThread.SetApartmentState(ApartmentState.MTA);
                soundInitializerThread.Start();

                soundInitializerThread.Join(); //Parent waiting on child to finish
                kinectEventLogger.Info("Successfully intialized all the runtime objects");
                kinectEventLogger.Info("Ready to receive events.......");

            }

            catch (Exception ex)
            {
                kinectEventLogger.Fatal("OOps!!! exception: " + ex.Message);
            }
        }
Ejemplo n.º 4
0
 void pressMuliple(int iterations, KeyboardInputProcessor.KeyboardData newKeyboardData)
 {
     for (int i = 0; i < iterations; i++)
     {
         keyboardProcessor.AddToQueue(newKeyboardData);
     }
 }