Пример #1
0
        /// <summary>
        /// Builder to create a Registration controller. Creates a connection to the database
        /// and loads profiles using the collection of associated user emails. Takes required
        /// arguments for the list of emails of already registered users.
        ///
        /// By default, has "en-us" enrollment locale
        /// and a delay between concurrent requests specified by SPEAKER_RECOGNITION_API_INTERVAL
        /// </summary>
        /// <param name="dbConnectionString"></param>
        /// <param name="userEmails"></param>
        /// <param name="speakerIDKeySub"></param>
        public static RegistrationController BuildController(string dbConnectionStr, List <string> registeredEmails,
                                                             string speakerIDSubKey = "", string enrollmentLocale = "en-us",
                                                             int apiInterval        = SPEAKER_RECOGNITION_API_INTERVAL)
        {
            SpeakerIdentificationServiceClient enrollmentClient = new SpeakerIdentificationServiceClient(speakerIDSubKey);
            List <User> userProfiles = new List <User>();

            Console.WriteLine(">\tLoading All Attendees' Voice Profiles From Database...");
            string email = "";

            foreach (var curEmail in registeredEmails)
            {
                try
                {
                    email = curEmail;
                    DatabaseController.Initialize(dbConnectionStr);
                    User curUser = DatabaseController.LoadUser(curEmail);
                    if (curUser is null)
                    {
                        continue;
                    }

                    curUser.AudioStream = AudioFileSplitter.Resample(curUser.AudioStream, 16000);

                    userProfiles.Add(curUser);
                    Console.WriteLine($"\t-\t[Load Succeeded]\t{email}");
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine($"\t-\t[Load Failed]\t{email} Reason: {ex.Message}");
                }
            }
            return(new RegistrationController(userProfiles, enrollmentClient, enrollmentLocale, apiInterval));
        }
Пример #2
0
        /// <summary>
        /// Async check if a profile is regsitered for the email address.
        /// Returns true if so, false otherwise.
        ///
        ///
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        private async Task <User> CheckProfileExists(string email)
        {
            var taskComplete = new TaskCompletionSource <User>();

            /*Try to load a user with this email */
            User registeredUser = DatabaseController.LoadUser(email);

            if (registeredUser == null)
            {
                return(null);
            }

            taskComplete.SetResult(registeredUser);
            return(registeredUser);
        }