private async void verificationButtonClicked(object sender, RoutedEventArgs e)
        {
            if (!newUser)
            {
                progressRing.IsActive = true;
                Verification verificationResult = await verificationController.VerifySpeaker(speakerID);

                progressRing.IsActive = false;
                if (verificationResult != null)
                {
                    if (verificationResult.Result.ToString().Equals("Accept") &&
                        (verificationResult.Confidence.ToString().Equals("High") || verificationResult.Confidence.ToString().Equals("Normal")))
                    {
                        if (!isAdmin)
                        {
                            if (user.access)
                            {
                                Synthesizer.Speak("Please come on in.");
                                //OPEN DOOR
                                MainPage.DLPin.Write(Windows.Devices.Gpio.GpioPinValue.High);
                                await Task.Delay(10000);

                                MainPage.DLPin.Write(Windows.Devices.Gpio.GpioPinValue.Low);
                                this.Frame.GoBack();
                            }
                            else
                            {
                                Synthesizer.Speak("I am sorry " + user.firstName + ", you are not allowed in this room. You should contact the Administrator.");
                                this.Frame.GoBack();
                            }
                        }
                        else
                        {
                            Synthesizer.Speak("Opening Administrator page.");
                            this.Frame.Navigate(typeof(AdminPage));
                        }
                    }
                    else
                    {
                        failedVerifications++;
                        if (failedVerifications < 3)
                        {
                            Synthesizer.Speak("I am sorry Dave, I'm afraid I cannot do that.");
                        }
                        else
                        {
                            SqliteTransactions.ModifyAccessByUserId(user.userId, false);
                            Synthesizer.Speak("For security purposes, I have to deny your access to the room. You should contact the Administrator.");
                            this.Frame.GoBack();
                        }
                    }
                }
            }
            else
            {
                Synthesizer.Speak("I need you to record your voice first.");
            }
        }
        private async void Timer_Tick(object sender, object e)
        {
            //This part of the code will be reached if a time equal to timer.Interval is exceded after reading a bit
            Debug.WriteLine(bitCount);
            Debug.WriteLine(ones);
            timer.Stop();
            //We are working wih 35 bit Cards
            if (bitCount == 35 && ones % 2 != 0)
            {
                bitCount = 0;
                progressRing.IsActive = true;
                //Get user information through the SOAP service using 6 bits Card Number
                String[] userData = await soapService.GetUserInfo(FormatCard());

                progressRing.IsActive = false;

                //If there is a user in IIT's database with that 6 digit card number
                if (userData != null)
                {
                    String lastName  = userData[0];
                    String firstName = userData[1];
                    String userId    = userData[3];
                    Debug.WriteLine(userId + ": " + firstName + " " + lastName);

                    //Check if user is already registered in the Speaker Recognition Database
                    User user = SqliteTransactions.GetUserByUserId(userId);

                    //if not
                    if (user == null)
                    {
                        //Create new user with user info and open Enrollment Page
                        user           = new User();
                        user.firstName = firstName;
                        user.lastName  = lastName;
                        user.userId    = userId;
                        user.access    = false;
                        OpenEnrollment(user);
                    }
                    else
                    {
                        OpenVerification(user);
                    }
                }
                else
                {
                    Debug.WriteLine("Card reading was wrong, or user not found.");
                    Synthesizer.Speak("Scan your card again.");
                }
            }
            else
            {
                //If the number of bits is different from 35 or odd number of ones, we will take it as a wrong read
                Synthesizer.Speak("Scan your card again.");
                bitCount = 0;
                FormatCard();
            }
        }
示例#3
0
        private async void doorButtonClicked(object sender, RoutedEventArgs e)
        {
            Synthesizer.Speak("Please come on in.");
            //OPEN DOOR!!!!
            MainPage.DLPin.Write(Windows.Devices.Gpio.GpioPinValue.High);
            await Task.Delay(10000);

            MainPage.DLPin.Write(Windows.Devices.Gpio.GpioPinValue.Low);
            this.Frame.Navigate(typeof(MainPage));
        }
示例#4
0
        public async Task <Enrollment> EnrollSpeaker()
        {
            if (profileCreated)
            {
                try
                {
                    //Get .wav file
                    var audioStream = await Recorder.GetStreamAsync();

                    //Enroll Speaker using API
                    Enrollment enrollmentResult = await serviceClient.EnrollAsync(audioStream.AsStream(), speakerId);

                    return(enrollmentResult);
                }
                catch (Microsoft.ProjectOxford.SpeakerRecognition.Contract.EnrollmentException e)
                {
                    if (e.Message.Equals("InvalidPhrase"))
                    {
                        if (firstEnrollment)
                        {
                            Synthesizer.Speak("I am sorry, I couldn't recognize a phrase from the list.");
                            Debug.WriteLine("I am sorry, I couldn't recognize a phrase from the list.");
                        }
                        else
                        {
                            Synthesizer.Speak("I am sorry, I need you to say the same phrase the three times.");
                            Debug.WriteLine("I am sorry, I need you to say the same phrase the three times.");
                        }
                    }
                    else if (e.Message.Equals("SpeechNotRecognized"))
                    {
                        Synthesizer.Speak("I am sorry, I couldn't recognize a human's voice. Please try again.");
                        Debug.WriteLine("I am sorry, I couldn't recognize a human's voice. Please try again.");
                    }
                    else
                    {
                        Debug.WriteLine("Couldn't enroll Speaker: " + e.Message);
                        Synthesizer.Speak("Something went wrong. Please try again.");
                    }
                    return(null);
                }
                catch (Exception e)
                {
                    Synthesizer.Speak("Something went wrong. Please try again.");
                    Debug.WriteLine("Couldn't enrollSpeaker: " + e.Message);
                    return(null);
                }
            }
            else
            {
                Debug.WriteLine("Create Profile first.");
                return(null);
            }
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     //Welcome the user when opening the page
     user = (User)e.Parameter;
     Synthesizer.Speak("Welcome. I need to make sure you are " + user.firstName + user.lastName);
     //Show the user the phrase he or she has to say
     phrase.Text = user.phrase;
     speakerID   = Guid.Parse(user.speakerId);
     if (user.userId.Equals("A20387795"))
     {
         enrollmentImage.Source = forwardArrow;
         isAdmin     = true;
         user.access = true;
     }
 }
        private async void enrollmentButtonClicked(object sender, RoutedEventArgs e)
        {
            if (!newUser)
            {
                if (recorded)
                {
                    progressRing.IsActive = true;
                    //Enroll speaker
                    Enrollment enrollmentResult = await enrollmentController.EnrollSpeaker();

                    progressRing.IsActive = false;
                    if (enrollmentResult != null)
                    {
                        enrollmentController.firstEnrollment = false;
                        int    remainingEnrollments = enrollmentResult.RemainingEnrollments;
                        string enrollmentStatus     = enrollmentResult.EnrollmentStatus.ToString();

                        if (!enrollmentStatus.Equals("Enrolled"))
                        {
                            if (remainingEnrollments == 1)
                            {
                                Synthesizer.Speak("The system needs " + remainingEnrollments + " last enrollment, please repeat the previous step.");
                            }
                            else
                            {
                                Synthesizer.Speak("The system needs " + remainingEnrollments + " more enrollments, please repeat the previous step.");
                            }
                            recorded = false;
                        }
                        else
                        {
                            //Add user to database
                            SqliteTransactions.AddUser(user);
                            Synthesizer.Speak("You have been succesfully enrolled. Contact the Administrator to get access to the room.");
                            this.Frame.GoBack();
                        }
                    }
                }
                else
                {
                    Synthesizer.Speak("I need a different audio sample. Please repeat the previous step.");
                }
            }
            else
            {
                Synthesizer.Speak("I need you to record your voice first.");
            }
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     //Welom the User when opening the page
     user = (User)e.Parameter;
     Synthesizer.Speak("Welcome " + user.firstName + " " + user.lastName + ". I will need you to select one of the phrases and record your voice.");
 }