Advertisement
2019PASTEBIN2019

Untitled

Jul 4th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.40 KB | None | 0 0
  1. //------------------------------------------------------------------------------
  2. // <copyright file="MainWindow.xaml.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. //------------------------------------------------------------------------------
  6.  
  7. // This module contains code to do Kinect NUI initialization,
  8. // processing, displaying players on screen, and sending updated player
  9. // positions to the game portion for hit testing.
  10.  
  11. namespace ShapeGame
  12. {
  13. using System;
  14. using System.Collections.Generic;
  15. using System.ComponentModel;
  16. using System.Linq;
  17. using System.Media;
  18. using System.Runtime.InteropServices;
  19. using System.Threading;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Data;
  23. using System.Windows.Threading;
  24. using Microsoft.Kinect;
  25. using Microsoft.Kinect.Toolkit;
  26. using Microsoft.Samples.Kinect.WpfViewers;
  27. using ShapeGame.Speech;
  28. using ShapeGame.Utils;
  29.  
  30. /// <summary>
  31. /// Interaction logic for MainWindow.xaml
  32. /// </summary>
  33. ///
  34. public partial class MainWindow : Window
  35. {
  36. public static readonly DependencyProperty KinectSensorManagerProperty =
  37. DependencyProperty.Register(
  38. "KinectSensorManager",
  39. typeof(KinectSensorManager),
  40. typeof(MainWindow),
  41. new PropertyMetadata(null));
  42.  
  43. #region Private State
  44. private const int TimerResolution = 2; // ms
  45. private const int NumIntraFrames = 3;
  46. private const int MaxShapes = 80;
  47. private const double MaxFramerate = 70;
  48. private const double MinFramerate = 15;
  49. private const double MinShapeSize = 12;
  50. private const double MaxShapeSize = 90;
  51. private const double DefaultDropRate = 2.5;
  52. private const double DefaultDropSize = 32.0;
  53. private const double DefaultDropGravity = 1.0;
  54.  
  55. private readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
  56. private readonly SoundPlayer popSound = new SoundPlayer();
  57. private readonly SoundPlayer hitSound = new SoundPlayer();
  58. private readonly SoundPlayer squeezeSound = new SoundPlayer();
  59. private readonly KinectSensorChooser sensorChooser = new KinectSensorChooser();
  60.  
  61. private double dropRate = DefaultDropRate;
  62. private double dropSize = DefaultDropSize;
  63. private double dropGravity = DefaultDropGravity;
  64. private DateTime lastFrameDrawn = DateTime.MinValue;
  65. private DateTime predNextFrame = DateTime.MinValue;
  66. private double actualFrameTime;
  67.  
  68.  
  69.  
  70. private Skeleton[] skeletonData;
  71.  
  72. // Player(s) placement in scene (z collapsed):
  73. private Rect playerBounds;
  74. private Rect screenRect;
  75.  
  76. private double targetFramerate = MaxFramerate;
  77. private int frameCount;
  78. private bool runningGameThread;
  79. private FallingThings myFallingThings;
  80. private int playersAlive;
  81. //$$$$$$$$$$$$$$$$
  82. int numOfPlayers = 0;
  83.  
  84. //$$$$$$$$$$$$$$$
  85.  
  86.  
  87. private SpeechRecognizer mySpeechRecognizer;
  88. #endregion Private State
  89.  
  90. #region ctor + Window Events
  91.  
  92. public MainWindow()
  93. {
  94.  
  95.  
  96.  
  97. this.KinectSensorManager = new KinectSensorManager();
  98. this.KinectSensorManager.KinectSensorChanged += this.KinectSensorChanged;
  99. this.DataContext = this.KinectSensorManager;
  100.  
  101. InitializeComponent();
  102.  
  103. this.SensorChooserUI.KinectSensorChooser = sensorChooser;
  104. sensorChooser.Start();
  105.  
  106. // Bind the KinectSensor from the sensorChooser to the KinectSensor on the KinectSensorManager
  107. var kinectSensorBinding = new Binding("Kinect") { Source = this.sensorChooser };
  108. BindingOperations.SetBinding(this.KinectSensorManager, KinectSensorManager.KinectSensorProperty, kinectSensorBinding);
  109.  
  110. this.RestoreWindowState();
  111. }
  112.  
  113. public KinectSensorManager KinectSensorManager
  114. {
  115. get { return (KinectSensorManager)GetValue(KinectSensorManagerProperty); }
  116. set { SetValue(KinectSensorManagerProperty, value); }
  117. }
  118.  
  119. // Since the timer resolution defaults to about 10ms precisely, we need to
  120. // increase the resolution to get framerates above between 50fps with any
  121. // consistency.
  122. [DllImport("Winmm.dll", EntryPoint = "timeBeginPeriod")]
  123. private static extern int TimeBeginPeriod(uint period);
  124.  
  125. private void RestoreWindowState()
  126. {
  127. // Restore window state to that last used
  128. Rect bounds = Properties.Settings.Default.PrevWinPosition;
  129. if (bounds.Right != bounds.Left)
  130. {
  131. this.Top = bounds.Top;
  132. this.Left = bounds.Left;
  133. this.Height = bounds.Height;
  134. this.Width = bounds.Width;
  135. }
  136.  
  137. this.WindowState = (WindowState)Properties.Settings.Default.WindowState;
  138. }
  139.  
  140. private void WindowLoaded(object sender, EventArgs e)
  141. {
  142. playfield.ClipToBounds = true;
  143.  
  144. this.myFallingThings = new FallingThings(MaxShapes, this.targetFramerate, NumIntraFrames);
  145.  
  146. this.UpdatePlayfieldSize();
  147.  
  148. this.myFallingThings.SetGravity(this.dropGravity);
  149. this.myFallingThings.SetDropRate(this.dropRate);
  150. this.myFallingThings.SetSize(this.dropSize);
  151. this.myFallingThings.SetPolies(PolyType.All);
  152. this.myFallingThings.SetGameMode(GameMode.Off);
  153.  
  154. this.popSound.Stream = Properties.Resources.Pop_5;
  155. this.hitSound.Stream = Properties.Resources.Hit_2;
  156. this.squeezeSound.Stream = Properties.Resources.Squeeze;
  157.  
  158. this.popSound.Play();
  159.  
  160. TimeBeginPeriod(TimerResolution);
  161. var myGameThread = new Thread(this.GameThread);
  162. myGameThread.SetApartmentState(ApartmentState.STA);
  163. myGameThread.Start();
  164.  
  165. FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), "Shapes!");
  166. }
  167.  
  168. private void WindowClosing(object sender, CancelEventArgs e)
  169. {
  170. sensorChooser.Stop();
  171.  
  172. this.runningGameThread = false;
  173. Properties.Settings.Default.PrevWinPosition = this.RestoreBounds;
  174. Properties.Settings.Default.WindowState = (int)this.WindowState;
  175. Properties.Settings.Default.Save();
  176. }
  177.  
  178. private void WindowClosed(object sender, EventArgs e)
  179. {
  180. this.KinectSensorManager.KinectSensor = null;
  181. }
  182.  
  183. #endregion ctor + Window Events
  184.  
  185. #region Kinect discovery + setup
  186.  
  187. private void KinectSensorChanged(object sender, KinectSensorManagerEventArgs<KinectSensor> args)
  188. {
  189. if (null != args.OldValue)
  190. {
  191. this.UninitializeKinectServices(args.OldValue);
  192. }
  193.  
  194. // Only enable this checkbox if we have a sensor
  195. enableAec.IsEnabled = null != args.NewValue;
  196.  
  197. if (null != args.NewValue)
  198. {
  199. this.InitializeKinectServices(this.KinectSensorManager, args.NewValue);
  200. }
  201. }
  202.  
  203. // Kinect enabled apps should customize which Kinect services it initializes here.
  204. private void InitializeKinectServices(KinectSensorManager kinectSensorManager, KinectSensor sensor)
  205. {
  206. // Application should enable all streams first.
  207. kinectSensorManager.ColorFormat = ColorImageFormat.RgbResolution640x480Fps30;
  208. kinectSensorManager.ColorStreamEnabled = true;
  209.  
  210. sensor.SkeletonFrameReady += this.SkeletonsReady;
  211. kinectSensorManager.TransformSmoothParameters = new TransformSmoothParameters
  212. {
  213. Smoothing = 0.5f,
  214. Correction = 0.5f,
  215. Prediction = 0.5f,
  216. JitterRadius = 0.05f,
  217. MaxDeviationRadius = 0.04f
  218. };
  219. kinectSensorManager.SkeletonStreamEnabled = true;
  220. kinectSensorManager.KinectSensorEnabled = true;
  221.  
  222. if (!kinectSensorManager.KinectSensorAppConflict)
  223. {
  224. // Start speech recognizer after KinectSensor started successfully.
  225. this.mySpeechRecognizer = SpeechRecognizer.Create();
  226.  
  227. if (null != this.mySpeechRecognizer)
  228. {
  229. this.mySpeechRecognizer.SaidSomething += this.RecognizerSaidSomething;
  230. this.mySpeechRecognizer.Start(sensor.AudioSource);
  231. }
  232.  
  233. enableAec.Visibility = Visibility.Visible;
  234. this.UpdateEchoCancellation(this.enableAec);
  235. }
  236. }
  237.  
  238. // Kinect enabled apps should uninitialize all Kinect services that were initialized in InitializeKinectServices() here.
  239. private void UninitializeKinectServices(KinectSensor sensor)
  240. {
  241. sensor.SkeletonFrameReady -= this.SkeletonsReady;
  242.  
  243. if (null != this.mySpeechRecognizer)
  244. {
  245. this.mySpeechRecognizer.Stop();
  246. this.mySpeechRecognizer.SaidSomething -= this.RecognizerSaidSomething;
  247. this.mySpeechRecognizer.Dispose();
  248. this.mySpeechRecognizer = null;
  249. }
  250.  
  251. enableAec.Visibility = Visibility.Collapsed;
  252. }
  253.  
  254. #endregion Kinect discovery + setup
  255.  
  256. #region Kinect Skeleton processing
  257. private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e)
  258. {
  259. using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
  260. {
  261. if (skeletonFrame != null)
  262. {
  263. int skeletonSlot = 0;
  264.  
  265. if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
  266. {
  267. this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
  268. }
  269.  
  270. skeletonFrame.CopySkeletonDataTo(this.skeletonData);
  271.  
  272.  
  273. //$$$$$$$$$$$$$
  274. //if(skeletonData.Length==0)
  275. //{
  276. // ;
  277. //}
  278. //else
  279. //{
  280. // ;
  281. //}
  282. //$$$$$$$$$$$$$
  283.  
  284.  
  285. //$$$$$$$$$$int l = skeletonData.Length;
  286.  
  287. this.numOfPlayers = 0;
  288. foreach (Skeleton skeleton in this.skeletonData)
  289. {
  290.  
  291. if (SkeletonTrackingState.Tracked == skeleton.TrackingState)
  292. {
  293. Player player;
  294. if (this.players.ContainsKey(skeletonSlot))
  295. {
  296. player = this.players[skeletonSlot];
  297. }
  298. else
  299. {
  300. if (this.numOfPlayers==0)
  301. {
  302. var x = "s";
  303.  
  304. this.numOfPlayers++;
  305. }
  306.  
  307.  
  308. }
  309.  
  310. player.LastUpdated = DateTime.Now;
  311.  
  312. // Update player's bone and joint positions
  313. if (skeleton.Joints.Count > 0)
  314. {
  315. player.IsAlive = true;
  316.  
  317. // Head, hands, feet (hit testing happens in order here)
  318. player.UpdateJointPosition(skeleton.Joints, JointType.Head);
  319. player.UpdateJointPosition(skeleton.Joints, JointType.HandLeft);
  320. player.UpdateJointPosition(skeleton.Joints, JointType.HandRight);
  321. player.UpdateJointPosition(skeleton.Joints, JointType.FootLeft);
  322. player.UpdateJointPosition(skeleton.Joints, JointType.FootRight);
  323.  
  324. // Hands and arms
  325. player.UpdateBonePosition(skeleton.Joints, JointType.HandRight, JointType.WristRight);
  326. player.UpdateBonePosition(skeleton.Joints, JointType.WristRight, JointType.ElbowRight);
  327. player.UpdateBonePosition(skeleton.Joints, JointType.ElbowRight, JointType.ShoulderRight);
  328.  
  329. player.UpdateBonePosition(skeleton.Joints, JointType.HandLeft, JointType.WristLeft);
  330. player.UpdateBonePosition(skeleton.Joints, JointType.WristLeft, JointType.ElbowLeft);
  331. player.UpdateBonePosition(skeleton.Joints, JointType.ElbowLeft, JointType.ShoulderLeft);
  332.  
  333. // Head and Shoulders
  334. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.Head);
  335. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderLeft, JointType.ShoulderCenter);
  336. player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.ShoulderRight);
  337.  
  338. // Legs
  339. player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.KneeLeft);
  340. player.UpdateBonePosition(skeleton.Joints, JointType.KneeLeft, JointType.AnkleLeft);
  341. player.UpdateBonePosition(skeleton.Joints, JointType.AnkleLeft, JointType.FootLeft);
  342.  
  343. player.UpdateBonePosition(skeleton.Joints, JointType.HipRight, JointType.KneeRight);
  344. player.UpdateBonePosition(skeleton.Joints, JointType.KneeRight, JointType.AnkleRight);
  345. player.UpdateBonePosition(skeleton.Joints, JointType.AnkleRight, JointType.FootRight);
  346.  
  347. player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.HipCenter);
  348. player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.HipRight);
  349.  
  350. // Spine
  351. player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.ShoulderCenter);
  352. }
  353. }
  354.  
  355. skeletonSlot++;
  356. }
  357. }
  358. }
  359. }
  360.  
  361. private void CheckPlayers()
  362. {
  363. foreach (var player in this.players)
  364. {
  365.  
  366. if (!player.Value.IsAlive)
  367. {
  368. // Player left scene since we aren't tracking it anymore, so remove from dictionary
  369. this.players.Remove(player.Value.GetId());
  370. break;
  371. }
  372. }
  373.  
  374. // Count alive players
  375. int alive = this.players.Count(player => player.Value.IsAlive);
  376.  
  377. if (alive != this.playersAlive)
  378. {
  379. if (alive == 2)
  380. {
  381. this.myFallingThings.SetGameMode(GameMode.TwoPlayer);
  382. }
  383. else if (alive == 1)
  384. {
  385. this.myFallingThings.SetGameMode(GameMode.Solo);
  386. }
  387. else if (alive == 0)
  388. {
  389. this.myFallingThings.SetGameMode(GameMode.Off);
  390. }
  391.  
  392. if ((this.playersAlive == 0) && (this.mySpeechRecognizer != null))
  393. {
  394. BannerText.NewBanner(
  395. Properties.Resources.Vocabulary,
  396. this.screenRect,
  397. true,
  398. System.Windows.Media.Color.FromArgb(200, 255, 255, 255));
  399. }
  400.  
  401. this.playersAlive = alive;
  402. }
  403. }
  404.  
  405. private void PlayfieldSizeChanged(object sender, SizeChangedEventArgs e)
  406. {
  407. this.UpdatePlayfieldSize();
  408. }
  409.  
  410. private void UpdatePlayfieldSize()
  411. {
  412. // Size of player wrt size of playfield, putting ourselves low on the screen.
  413. this.screenRect.X = 0;
  414. this.screenRect.Y = 0;
  415. this.screenRect.Width = this.playfield.ActualWidth;
  416. this.screenRect.Height = this.playfield.ActualHeight;
  417.  
  418. BannerText.UpdateBounds(this.screenRect);
  419.  
  420. this.playerBounds.X = 0;
  421. this.playerBounds.Width = this.playfield.ActualWidth;
  422. this.playerBounds.Y = this.playfield.ActualHeight * 0.2;
  423. this.playerBounds.Height = this.playfield.ActualHeight * 0.75;
  424.  
  425. foreach (var player in this.players)
  426. {
  427. player.Value.SetBounds(this.playerBounds);
  428. }
  429.  
  430. Rect fallingBounds = this.playerBounds;
  431. fallingBounds.Y = 0;
  432. fallingBounds.Height = playfield.ActualHeight;
  433. if (this.myFallingThings != null)
  434. {
  435. this.myFallingThings.SetBoundaries(fallingBounds);
  436. }
  437. }
  438. #endregion Kinect Skeleton processing
  439.  
  440. #region GameTimer/Thread
  441. private void GameThread()
  442. {
  443. this.runningGameThread = true;
  444. this.predNextFrame = DateTime.Now;
  445. this.actualFrameTime = 1000.0 / this.targetFramerate;
  446.  
  447. // Try to dispatch at as constant of a framerate as possible by sleeping just enough since
  448. // the last time we dispatched.
  449. while (this.runningGameThread)
  450. {
  451. // Calculate average framerate.
  452. DateTime now = DateTime.Now;
  453. if (this.lastFrameDrawn == DateTime.MinValue)
  454. {
  455. this.lastFrameDrawn = now;
  456. }
  457.  
  458. double ms = now.Subtract(this.lastFrameDrawn).TotalMilliseconds;
  459. this.actualFrameTime = (this.actualFrameTime * 0.95) + (0.05 * ms);
  460. this.lastFrameDrawn = now;
  461.  
  462. // Adjust target framerate down if we're not achieving that rate
  463. this.frameCount++;
  464. if ((this.frameCount % 100 == 0) && (1000.0 / this.actualFrameTime < this.targetFramerate * 0.92))
  465. {
  466. this.targetFramerate = Math.Max(MinFramerate, (this.targetFramerate + (1000.0 / this.actualFrameTime)) / 2);
  467. }
  468.  
  469. if (now > this.predNextFrame)
  470. {
  471. this.predNextFrame = now;
  472. }
  473. else
  474. {
  475. double milliseconds = this.predNextFrame.Subtract(now).TotalMilliseconds;
  476. if (milliseconds >= TimerResolution)
  477. {
  478. Thread.Sleep((int)(milliseconds + 0.5));
  479. }
  480. }
  481.  
  482. this.predNextFrame += TimeSpan.FromMilliseconds(1000.0 / this.targetFramerate);
  483.  
  484. this.Dispatcher.Invoke(DispatcherPriority.Send, new Action<int>(this.HandleGameTimer), 0);
  485. }
  486. }
  487.  
  488. private void HandleGameTimer(int param)
  489. {
  490. // Every so often, notify what our actual framerate is
  491. if ((this.frameCount % 100) == 0)
  492. {
  493. this.myFallingThings.SetFramerate(1000.0 / this.actualFrameTime);
  494. }
  495.  
  496. // Advance animations, and do hit testing.
  497. for (int i = 0; i < NumIntraFrames; ++i)
  498. {
  499. foreach (var pair in this.players)
  500. {
  501. HitType hit = this.myFallingThings.LookForHits(pair.Value.Segments, pair.Value.GetId());
  502. if ((hit & HitType.Squeezed) != 0)
  503. {
  504. this.squeezeSound.Play();
  505. }
  506. else if ((hit & HitType.Popped) != 0)
  507. {
  508. this.popSound.Play();
  509. }
  510. else if ((hit & HitType.Hand) != 0)
  511. {
  512. this.hitSound.Play();
  513. }
  514. }
  515.  
  516. this.myFallingThings.AdvanceFrame();
  517. }
  518.  
  519. // Draw new Wpf scene by adding all objects to canvas
  520. playfield.Children.Clear();
  521. this.myFallingThings.DrawFrame(this.playfield.Children);
  522. foreach (var player in this.players)
  523. {
  524. //if (players.Count > 1)
  525. // numOfPlayers= players.Count;
  526. player.Value.Draw(playfield.Children);
  527. }
  528.  
  529. BannerText.Draw(playfield.Children);
  530. FlyingText.Draw(playfield.Children);
  531.  
  532. this.CheckPlayers();
  533. }
  534. #endregion GameTimer/Thread
  535.  
  536. #region Kinect Speech processing
  537. private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
  538. {
  539. FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), e.Matched);
  540. switch (e.Verb)
  541. {
  542. case SpeechRecognizer.Verbs.Pause:
  543. this.myFallingThings.SetDropRate(0);
  544. this.myFallingThings.SetGravity(0);
  545. break;
  546. case SpeechRecognizer.Verbs.Resume:
  547. this.myFallingThings.SetDropRate(this.dropRate);
  548. this.myFallingThings.SetGravity(this.dropGravity);
  549. break;
  550. case SpeechRecognizer.Verbs.Reset:
  551. this.dropRate = DefaultDropRate;
  552. this.dropSize = DefaultDropSize;
  553. this.dropGravity = DefaultDropGravity;
  554. this.myFallingThings.SetPolies(PolyType.All);
  555. this.myFallingThings.SetDropRate(this.dropRate);
  556. this.myFallingThings.SetGravity(this.dropGravity);
  557. this.myFallingThings.SetSize(this.dropSize);
  558. this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
  559. this.myFallingThings.Reset();
  560. break;
  561. case SpeechRecognizer.Verbs.DoShapes:
  562. this.myFallingThings.SetPolies(e.Shape);
  563. break;
  564. case SpeechRecognizer.Verbs.RandomColors:
  565. this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
  566. break;
  567. case SpeechRecognizer.Verbs.Colorize:
  568. this.myFallingThings.SetShapesColor(e.RgbColor, false);
  569. break;
  570. case SpeechRecognizer.Verbs.ShapesAndColors:
  571. this.myFallingThings.SetPolies(e.Shape);
  572. this.myFallingThings.SetShapesColor(e.RgbColor, false);
  573. break;
  574. case SpeechRecognizer.Verbs.More:
  575. this.dropRate *= 1.5;
  576. this.myFallingThings.SetDropRate(this.dropRate);
  577. break;
  578. case SpeechRecognizer.Verbs.Fewer:
  579. this.dropRate /= 1.5;
  580. this.myFallingThings.SetDropRate(this.dropRate);
  581. break;
  582. case SpeechRecognizer.Verbs.Bigger:
  583. this.dropSize *= 1.5;
  584. if (this.dropSize > MaxShapeSize)
  585. {
  586. this.dropSize = MaxShapeSize;
  587. }
  588.  
  589. this.myFallingThings.SetSize(this.dropSize);
  590. break;
  591. case SpeechRecognizer.Verbs.Biggest:
  592. this.dropSize = MaxShapeSize;
  593. this.myFallingThings.SetSize(this.dropSize);
  594. break;
  595. case SpeechRecognizer.Verbs.Smaller:
  596. this.dropSize /= 1.5;
  597. if (this.dropSize < MinShapeSize)
  598. {
  599. this.dropSize = MinShapeSize;
  600. }
  601.  
  602. this.myFallingThings.SetSize(this.dropSize);
  603. break;
  604. case SpeechRecognizer.Verbs.Smallest:
  605. this.dropSize = MinShapeSize;
  606. this.myFallingThings.SetSize(this.dropSize);
  607. break;
  608. case SpeechRecognizer.Verbs.Faster:
  609. this.dropGravity *= 1.25;
  610. if (this.dropGravity > 4.0)
  611. {
  612. this.dropGravity = 4.0;
  613. }
  614.  
  615. this.myFallingThings.SetGravity(this.dropGravity);
  616. break;
  617. case SpeechRecognizer.Verbs.Slower:
  618. this.dropGravity /= 1.25;
  619. if (this.dropGravity < 0.25)
  620. {
  621. this.dropGravity = 0.25;
  622. }
  623.  
  624. this.myFallingThings.SetGravity(this.dropGravity);
  625. break;
  626. }
  627. }
  628.  
  629. private void EnableAecChecked(object sender, RoutedEventArgs e)
  630. {
  631. var enableAecCheckBox = (CheckBox)sender;
  632. this.UpdateEchoCancellation(enableAecCheckBox);
  633. }
  634.  
  635. private void UpdateEchoCancellation(CheckBox aecCheckBox)
  636. {
  637. this.mySpeechRecognizer.EchoCancellationMode = aecCheckBox.IsChecked != null && aecCheckBox.IsChecked.Value
  638. ? EchoCancellationMode.CancellationAndSuppression
  639. : EchoCancellationMode.None;
  640. }
  641.  
  642. #endregion Kinect Speech processing
  643. }
  644. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement