Beispiel #1
0
        //private void disposeMic()
        //{
        //this.micClient.EndMicAndRecognition();
        //this.micClient.Dispose();
        //this.micClient = null;
        //}

        private void btnNormalLogin_Click(object sender, RoutedEventArgs e)
        {
            if (String.Equals(txtUsername.Text, "Username") || String.Equals(txtUsername.Text.Trim(), ""))
            {
                MessageBox.Show("Please enter your username!", "Error", MessageBoxButton.OK);
            }
            else
            {
                //Login
                UserTableDataContext dataContext = new UserTableDataContext();
                var usr = dataContext.Users.SingleOrDefault(x => x.username == txtUsername.Text && x.password == txtPassword.Password);
                if (usr != null)
                {
                    MessageBox.Show("Login successful", "Login successful", MessageBoxButton.OK);
                    txtUsername.Focus();
                    //GC.Collect();
                    //disposeMic();

                    MainMenuWIthLights ss = new MainMenuWIthLights(usr);
                    ss.Show();
                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Login Failed", "Login Failed", MessageBoxButton.OK);
                }
            }
        }
Beispiel #2
0
        private void speakResponse(string text)
        {
            string howWarmQuestion = "How warm do you want your home to be?";

            if ((text.ToLower().Contains("degree") || text.ToLower().Contains("temperature"))
                //(text.ToLower().Contains("has") || text.ToLower().Contains("house") || text.ToLower().Contains("home"))
                )
            {
                string temp = Regex.Match(text.ToLower(), @"\d+").Value;
                if (String.IsNullOrEmpty(temp))
                {
                    lblAI.Content = howWarmQuestion;
                }
                else
                {
                    lblAI.Content = "Your default temprature has been set to " + temp + " degrees. Thank you!";
                    isResponded   = true;
                }
                talk(lblAI.Content.ToString());
            }
            else if (text.ToLower().Contains("log") && text.ToLower().Contains("out"))
            {
                logout();
            }
            else
            {
                if (!String.IsNullOrEmpty(Regex.Match(text.ToLower(), @"\d+").Value) && String.Equals(howWarmQuestion, lblAI.Content.ToString()))
                {
                    string temp = Regex.Match(text.ToLower(), @"\d+").Value;
                    lblAI.Content = "Your default temprature has been set to " + temp + " degrees. Thank you!";
                    isResponded   = true;
                    talk(lblAI.Content.ToString());
                }
                else
                {
                    lblAI.Content = "";
                    MessageBox.Show("Please notice: The only feature available at the moment is to set your home temperature.", "Warning", MessageBoxButton.OK);
                }
            }

            if (isResponded)
            {
                string temp = Regex.Match(text.ToLower(), @"\d+").Value;
                UserTableDataContext dataContext = new UserTableDataContext();
                User usr = dataContext.Users.SingleOrDefault(x => x.username == user.username);
                usr.defaulthometemprature = int.Parse(temp);
                dataContext.SubmitChanges();
            }
        }
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         UserTableDataContext dataContext = new UserTableDataContext();
         user = dataContext.Users.SingleOrDefault(x => x.username == user.username);
         user.defaulthometemprature = int.Parse(txtSetHouseTemperature.Text);
         dataContext.SubmitChanges();
         MessageBox.Show("Temperature setting has been updated!", "Successful");
     }
     catch (Exception ex)
     {
         MessageBox.Show("Invalid temperature format!\n" + ex.Message, "Failed", MessageBoxButton.OK);
     }
 }
 public LoginWithSpeakerRecognition(string username)
 {
     try
     {
         InitializeComponent();
         dataContext    = new UserTableDataContext();
         this.username  = username;
         label1.Content = "Hello " + username;
         user           = dataContext.Users.SingleOrDefault(x => x.username == this.username);
         if (user == null || user.speakerguid == null)
         {
             //Delay 2 seconds to check whether user exists or not
             var timer = new DispatcherTimer {
                 Interval = TimeSpan.FromSeconds(2)
             };
             timer.Start();
             timer.Tick += (sender, args) =>
             {
                 timer.Stop();
                 MessageBox.Show("User or Voice data is not found", "Error", MessageBoxButton.OK);
                 MainWindow mw = new MainWindow();
                 mw.Show();
                 this.Close();
                 return;
             };
         }
         else
         {
             string _savedSpeakerId = user.speakerguid;
             if (_savedSpeakerId != null)
             {
                 _speakerId = new Guid(_savedSpeakerId);
             }
             initializeRecorder();
             txtPhraseText.Text = user.speakerphrase;
             _serviceClient     = new SpeakerVerificationServiceClient(_subscriptionKey);
         }
     }
     catch (Exception gexp)
     {
         MessageBox.Show("Error: " + gexp.Message, "Error", MessageBoxButton.OK);
         btnRecord.IsEnabled = false;
     }
 }
Beispiel #5
0
        public UserRegistrationAudio(string username)
        {
            InitializeComponent();
            try
            {
                InitializeComponent();

                this.username = username;
                dataContext   = new UserTableDataContext();
                user          = dataContext.Users.SingleOrDefault(x => x.username == this.username);

                _serviceClient = new SpeakerVerificationServiceClient(_subscriptionKey);
                initializeRecorder();
                initializeSpeaker();
            }
            catch (Exception gexp)
            {
                MessageBox.Show("Error: " + gexp.Message, "Error", MessageBoxButton.OK);
                btnRecord.IsEnabled = false;
                btnReset.IsEnabled  = false;
            }
        }
        private async void btnCapture_Click(object sender, RoutedEventArgs e)
        {
            image2.Visibility = Visibility.Visible;
            image2.Source     = image1.Source;
            image1.Visibility = Visibility.Hidden;

            tempfilename = Helper.SaveTempImageCapture((BitmapSource)image2.Source);
            webcam.Stop();

            //Login
            UserTableDataContext dataContext = new UserTableDataContext();
            var usr = dataContext.Users.SingleOrDefault(x => x.username == this.username);

            ////label.Content = "Please wait...";
            if (usr != null)
            {
                FaceAPIHelper tempImage = new FaceAPIHelper();
                string        result    = await tempImage.UploadOneFace(tempfilename);

                if (String.IsNullOrEmpty(result))
                {
                    tempFaceCollection = tempImage.faceResultCollection;
                }
                else
                {
                    MessageBox.Show(result, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }


                //Get comparison face for verify
                //CHANGE HERE TO BE DYNAMIC
                string        imagepath = usr.photofile; // dt.Rows[0][0].ToString();
                FaceAPIHelper realImage = new FaceAPIHelper();
                result = await realImage.UploadOneFace(imagepath);

                if (String.IsNullOrEmpty(result))
                {
                    databaseFaceCollection = realImage.faceResultCollection;
                }
                else
                {
                    MessageBox.Show(result, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }

                //Verify
                string res = await realImage.Verify2Faces(tempFaceCollection, databaseFaceCollection);

                if (res.ToLower().Contains("successful"))
                {
                    MessageBox.Show(res, "Successful", MessageBoxButton.OK);
                    webcam.Stop();

                    MainMenuWIthLights ss = new MainMenuWIthLights(usr);
                    ss.Show();
                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show(res, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }
            }
            else
            {
                MessageBox.Show("User not found", "Error", MessageBoxButton.OK);
                MainWindow mw = new MainWindow();
                mw.Show();
                webcam.Stop();
                this.Close();
            }
        }