protected async override void OnNavigatedTo(NavigationEventArgs e) { // Set the page to standby mode to start off with this.GoToVisualState("Standby"); _ctsVideoMonitor = new CancellationTokenSource(); // Initialize the text-to-speech class instance. It uses the MediaElement on the page to play sounds thus you need to pass it a reference to. _tts = new TextToSpeech(this.media, this.Dispatcher); // Initialize the speech-to-text class instance which is used to recognize speech commands by the customer _speechToText = new SpeechToText( _SpeechToTextLanguageName, _SpeechToTextInitialSilenceTimeoutInSeconds, _SpeechToTextBabbleTimeoutInSeconds, _SpeechToTextEndSilenceTimeoutInSeconds); await _speechToText.InitializeRecognizerAsync(); _speechToText.OnHypothesis += _speechToText_OnHypothesis; _speechToText.CapturingStarted += _speechToText_CapturingStarted; _speechToText.CapturingEnded += _speechToText_CapturingEnded; // Landscape preference set to landscape DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; // Keeps the screen alive i.e. prevents screen from going to sleep _displayRequest = new DisplayRequest(); _displayRequest.RequestActive(); // Find all the video cameras on the device var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); // Choose the first externally plugged in camera found var preferredCamera = cameras.FirstOrDefault(deviceInfo => deviceInfo.EnclosureLocation == null); // If no external camera, choose the front facing camera ELSE choose the first available camera found if (preferredCamera == null) { preferredCamera = cameras.FirstOrDefault(deviceInfo => deviceInfo.EnclosureLocation?.Panel == Windows.Devices.Enumeration.Panel.Front) ?? cameras.FirstOrDefault(); } // No camera found on device if (preferredCamera == null) { Debug.WriteLine("No camera found on device!"); return; } // Initialize and start the camera video stream into the app preview window _mediaCapture = new MediaCapture(); await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings() { StreamingCaptureMode = StreamingCaptureMode.Video, VideoDeviceId = preferredCamera.Id }); videoPreview.Source = _mediaCapture; await _mediaCapture.StartPreviewAsync(); // Ensure state is clear await this.EndSessionAsync(); // Initiate monitoring of the video stream for faces _faceMonitoringTask = this.FaceMonitoringAsync(_ctsVideoMonitor.Token); base.OnNavigatedTo(e); }