/// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            this.InitializeComponent();
            // initialize the sensor chooser and UI
            this.sensorChooser = new KinectSensorChooser();
            this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
            this.sensorChooser.KinectChanged        += this.SensorChooserOnKinectChanged;
            this.sensorChooser.Start();
            this.drawingGroup = new DrawingGroup();

            // Create an image source that we can use in our image control
            this.imageSource = new DrawingImage(this.drawingGroup);

            // Display the drawing using our image control
            this.Image.Source = this.imageSource;


            //speech-in and -out
            reader = new SpeechSynthesizer();
            foreach (InstalledVoice voice in reader.GetInstalledVoices())
            {
                Console.WriteLine(voice.VoiceInfo.Description + " " + voice.VoiceInfo.Name);
            }
            reader.SelectVoice("Microsoft Zira Desktop");
            speechInteraction = new SpeechInteraction(this, reader);

            //Connection stuff here

            connectionManager = new ConnectionManager(BluetoothOn, reader, speechInteraction);

            lastSkeletonTimeStamp = DateTime.Now;
        }
示例#2
0
 public ConnectionManager(bool BluetoothOn, SpeechSynthesizer Reader, SpeechInteraction speechInteraction)
 {
     this.BluetoothOn       = BluetoothOn;
     this.Reader            = Reader;
     this.speechInteraction = speechInteraction;
     if (BluetoothOn)
     {
         if (BluetoothRadio.PrimaryRadio.Mode == RadioMode.Discoverable)
         {
             thisDevice = new BluetoothClient();
             BluetoothComponent bluetoothComponent = new BluetoothComponent(thisDevice);
             bluetoothComponent.DiscoverDevicesProgress += bluetoothComponent_DiscoverDevicesProgress;
             bluetoothComponent.DiscoverDevicesComplete += bluetoothComponent_DiscoverDevicesComplete;
             bluetoothComponent.DiscoverDevicesAsync(8, true, true, true, false, thisDevice);
             Console.WriteLine("Connectable");
         }
         else
         {
             Reader.Speak("Please turn on your Bluetooth adapter");
         }
     }
     else
     {
         asyncClient = new AsynchronousClient(speechInteraction);
         InitAsyncTCPClient();
     }
 }
 public AsynchronousClient(SpeechInteraction speechInteraction)
 {
     this.speechInteraction = speechInteraction;
 }
 public SpeechHandler(SpeechInteraction speechInteraction, KinectSensor sensor)
 {
     this.sensor            = sensor;
     this.speechInteraction = speechInteraction;
 }
示例#5
0
 public SkeletonHandler(KinectSensor sensor, SpeechInteraction speechInt)
 {
     this.speechInteraction = speechInt;
     this.sensor            = sensor;
 }
示例#6
0
        private void Connected(IAsyncResult result, SpeechInteraction speechInteraction)
        {
            if (result.IsCompleted)
            {
                if (thisDevice.Connected)
                {
                    Action lambdaConnected = () => speechInteraction.fsm.Fire(SpeechInteraction.Command.Connected);
                    Application.Current.Dispatcher.Invoke(
                        (Delegate)lambdaConnected);
                    // client is connected now :)
                    NetworkStream stream = thisDevice.GetStream();
                    if (stream.CanRead)
                    {
                        byte[]        myReadBuffer      = new byte[1024];
                        StringBuilder myCompleteMessage = new StringBuilder();
                        int           numberOfBytesRead = 0;

                        // Incoming message may be larger than the buffer size.
                        do
                        {
                            if (stream.DataAvailable)
                            {
                                numberOfBytesRead = stream.Read(myReadBuffer, 0, myReadBuffer.Length);

                                Console.WriteLine("Received Bytes");
                                Console.WriteLine(BitConverter.ToString(myReadBuffer));
                                int value = 0;
                                for (int i = 0; i < 4; i++)
                                {
                                    value = (value << 4) + (myReadBuffer[i] & 0xff);
                                }
                                Console.WriteLine("value " + value);
                                switch (value)
                                {
                                case 0:
                                    Console.WriteLine("Received input data from airbar");
                                    break;

                                case 1:
                                    int status = 0;
                                    for (int i = 4; i < 8; i++)
                                    {
                                        status = (status << 4) + (myReadBuffer[i] & 0xff);
                                    }
                                    Console.WriteLine("Status " + status);
                                    byte[] subArray = new byte[36];
                                    int    start    = sizeof(int) + sizeof(int);
                                    switch (status)
                                    {
                                    case 0:
                                        Console.WriteLine("Finished printing");
                                        Action lambda = () => speechInteraction.fsm.Fire(SpeechInteraction.Command.Printed);
                                        Application.Current.Dispatcher.Invoke(
                                            (Delegate)lambda);
                                        break;
                                    }
                                    break;
                                }
                            }
                        }while (stream.CanRead && thisDevice.Connected);
                    }
                    else
                    {
                        Console.WriteLine("could not connect");
                    }
                }
            }
            else
            {
                Console.WriteLine("Could not connect");
            }
        }