/// <summary>
        /// Retrieves all the speakers asynchronously and adds them to the list
        /// </summary>
        /// <returns>Task to track the status of the asynchronous task.</returns>
        public async Task UpdateAllSpeakersAsync()
        {
            SpeakerIdentificationServiceClient _serviceClient = new SpeakerIdentificationServiceClient("Paste your speaker recognition API key here");
            MainWindow window = (MainWindow)Application.Current.MainWindow;

            try
            {
                //window.Log("Retrieving All Profiles...");
                Title = String.Format("Retrieving All Profiles...");
                Profile[] allProfiles = await _serviceClient.GetProfilesAsync();

                //window.Log("All Profiles Retrieved.");
                Title = String.Format("All Profiles Retrieved.");
                enrollVoiceList.Clear();
                foreach (Profile profile in allProfiles)
                {
                    AddSpeaker(profile);
                }
                //_speakersLoaded = true;
            }
            catch (GetProfileException ex)
            {
                //window.Log("Error Retrieving Profiles: " + ex.Message);
                Title = String.Format("Error Retrieving Profiles: " + ex.Message);
            }
            catch (Exception ex)
            {
                //window.Log("Error: " + ex.Message);
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves all the speakers asynchronously and adds them to the list
        /// </summary>
        /// <returns>Task to track the status of the asynchronous task.</returns>
        public async Task UpdateAllSpeakersAsync()
        {
            MainWindow window = (MainWindow)Application.Current.MainWindow;

            try
            {
                window.Log("Retrieving All Profiles...");
                Profile[] allProfiles = await _serviceClient.GetProfilesAsync();

                window.Log("All Profiles Retrieved.");
                _speakersListView.Items.Clear();
                foreach (Profile profile in allProfiles)
                {
                    AddSpeaker(profile);
                }
                _speakersLoaded = true;
            }
            catch (GetProfileException ex)
            {
                window.Log("Error Retrieving Profiles: " + ex.Message);
            }
            catch (Exception ex)
            {
                window.Log("Error: " + ex.Message);
            }
        }
Esempio n. 3
0
        //To delete the speaker profile.
        private async void DeleteSpeaker()
        {
            try
            {
                SpeakerIdentificationServiceClient _serviceClient = new SpeakerIdentificationServiceClient(speakerAPISubscriptionKey);
                Title = String.Format("Deleting All Profiles...");
                Profile[] allProfiles = await _serviceClient.GetProfilesAsync();

                Title = String.Format("All Profiles Deleted.");
                int i = 0;
                foreach (Profile profile in allProfiles)
                {
                    i++;
                    Delete(profile);
                    if (i > 5)
                    {
                        return;
                    }
                }
                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
                GC.Collect();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Retrieves all the speakers asynchronously and adds them to the list
        /// </summary>
        /// <returns>Task to track the status of the asynchronous task.</returns>
        public async Task UpdateAllSpeakersAsync()
        {
            try
            {
                SpeakerIdentificationServiceClient _serviceClient = new SpeakerIdentificationServiceClient(speakerAPISubscriptionKey);
                Title = String.Format("Retrieving All Profiles...");
                Profile[] allProfiles = await _serviceClient.GetProfilesAsync();

                Title = String.Format("All Profiles Retrieved.");
                enrollVoiceList.Clear();
                foreach (Profile profile in allProfiles)
                {
                    AddSpeaker(profile);
                }
            }
            catch (GetProfileException ex)
            {
                Console.WriteLine("Error Retrieving Profiles: " + ex.Message);
                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                GC.Collect();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Adds speaker recognition dialog
        /// </summary>
        private void AddRecognizerDialog()
        {
            Add(Inputs.RecognizeThisPrompt, new AttachmentPrompt());

            Add(Dialogs.RecognizeSpeakerDialogName, new WaterfallStep[]
            {
                async(dc, args, next) =>
                {
                    await dc.Prompt(Inputs.RecognizeThisPrompt, "Please upload a .wav file", new PromptOptions());
                },
                async(dc, args, next) =>
                {
                    //Get attachment details
                    var attachment = ((List <Attachment>)args["Attachments"]).FirstOrDefault();

                    if (attachment == null)
                    {
                        await dc.Context.SendActivity("I didn't get the attachment...");
                        //we're done
                        await dc.Replace(Dialogs.MainDialogName);
                        return;
                    }

                    if (attachment.ContentType != "audio/wav" || string.IsNullOrWhiteSpace(attachment.ContentUrl))
                    {
                        await dc.Context.SendActivity($"I didn't get a .wav file attachment...");
                        //we're done
                        await dc.Replace(Dialogs.MainDialogName);
                        return;
                    }

                    var state = dc.Context.GetConversationState <ProfileState>();

                    string attachmentContentUrl = attachment.ContentUrl;

                    //Get all enrolled profiles
                    var profiles = await _client.GetProfilesAsync();
                    foreach (var profile in profiles)
                    {
                        if (profile.EnrollmentStatus == EnrollmentStatus.Enrolled &&
                            !state.AllSpeakers.Contains(profile.ProfileId))
                        {
                            state.AllSpeakers.Add(profile.ProfileId);
                        }
                    }

                    //send attachment in chunks to be analyzed
                    await dc.Context.SendActivity("Analyzing your voice...");

                    await AnalyzeWavFile(attachmentContentUrl, dc, state);

                    await dc.Context.SendActivity("Analysis complete.");
                    //we're done
                    await dc.Replace(Dialogs.MainDialogName);
                }
            });
        }
        //This loads the speakers from the Web Server and adds them to the grid. This will also load the "Name" for the user if it exists in the data.xml file
        //INPUT:
        //OUTPUT: Datatable
        public async Task <DataTable> UpdateAllSpeakers()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("SpeakerID", typeof(string));
            dt.Columns.Add("EnrollmentStatus", typeof(string));
            dt.Columns.Add("RemainingTime", typeof(string));
            dt.Columns.Add("SpeakerName", typeof(string));

            try
            {
                //Retrieve the profiles from the server
                Profile[] allProfiles = await _serviceClient.GetProfilesAsync();

                //Load the data from the database
                Database          db    = new Database();
                List <UserRecord> users = db.getUserList();

                //Add each profile loaded
                foreach (Profile profile in allProfiles)
                {
                    //Check if the ProfileID exists in the list
                    //Using LINQ we can search the users list for a matching profileID
                    UserRecord foundRow = users.Find(i => i.PROFILEID == profile.ProfileId.ToString());
                    //Create a temp variable for the username
                    string username = "";
                    int    ID       = -1;
                    //Only try assign the UserName to the variable if we found matching row (handles if we don't have a valid GUID)
                    if (foundRow != null)
                    {
                        username = foundRow.NAME;
                        ID       = foundRow.ID;
                    }
                    //Add the data to the datatable
                    if (ID >= 0)
                    {
                        dt.Rows.Add(ID, profile.ProfileId, profile.EnrollmentStatus, profile.RemainingEnrollmentSpeechSeconds, username);
                    }
                    else
                    {
                        dt.Rows.Add(DBNull.Value, profile.ProfileId, profile.EnrollmentStatus, profile.RemainingEnrollmentSpeechSeconds, username);
                    }
                }

                return(dt);
            }
            catch (GetProfileException ex)
            {
                return(dt);
            }
            catch (Exception ex)
            {
                return(dt);
            }
        }
Esempio n. 7
0
        private async void identifySpeaker(string _selectedFile)
        {
            SpeakerIdentificationServiceClient _serviceClient;
            OperationLocation processPollingLocation;

            _serviceClient = new SpeakerIdentificationServiceClient("e5404f463d1242ad8ce61c5422afc4bf");


            Profile[] allProfiles = await _serviceClient.GetProfilesAsync();

            Guid[] testProfileIds = new Guid[allProfiles.Length];
            for (int i = 0; i < testProfileIds.Length; i++)
            {
                testProfileIds[i] = allProfiles[i].ProfileId;
            }
            using (Stream audioStream = File.OpenRead(_selectedFile))
            {
                _selectedFile          = "";
                processPollingLocation = await _serviceClient.IdentifyAsync(audioStream, testProfileIds, true);
            }

            IdentificationOperation identificationResponse = null;
            int      numOfRetries       = 10;
            TimeSpan timeBetweenRetries = TimeSpan.FromSeconds(5.0);

            while (numOfRetries > 0)
            {
                await Task.Delay(timeBetweenRetries);

                identificationResponse = await _serviceClient.CheckIdentificationStatusAsync(processPollingLocation);

                if (identificationResponse.Status == Status.Succeeded)
                {
                    writeUser("User: "******"User: unknown");
                    break;
                }
                numOfRetries--;
            }
            if (numOfRetries <= 0)
            {
                writeUser("User: unknown");
            }
        }
Esempio n. 8
0
        async Task GetProfiles()
        {
            try // I don't want to disable buttons and for multiple clicks error catching
            {
                Profile[] profiles = await _serviceClient.GetProfilesAsync();

                lbProfiles.Items.Clear();
                foreach (Profile _profile in profiles)
                {
                    ListBoxItem lbi = new ListBoxItem();
                    lbi.Content = _profile.ProfileId;
                    lbProfiles.Items.Add(lbi);
                }
            }
            catch { }
        }
Esempio n. 9
0
        public async Task <IdentificationOperation> RecognizeSpeaker(string recordingFileName)
        {
            var srsc     = new SpeakerIdentificationServiceClient(Settings.Instance.SpeakerRecognitionApiKeyValue);
            var profiles = await srsc.GetProfilesAsync();

            //First we choose set of profiles we want to try match speaker of narration with
            Guid[] testProfileIds = new Guid[profiles.Length];
            for (int i = 0; i < testProfileIds.Length; i++)
            {
                testProfileIds[i] = profiles[i].ProfileId;
            }

            //IdentifyAsync is longer operation so we need to implement result polling mechanism
            OperationLocation processPollingLocation;

            using (Stream audioStream = File.OpenRead(recordingFileName))
            {
                processPollingLocation = await srsc.IdentifyAsync(audioStream, testProfileIds, true);
            }

            IdentificationOperation identificationResponse = null;
            int      numOfRetries       = 10;
            TimeSpan timeBetweenRetries = TimeSpan.FromSeconds(5.0);

            //
            while (numOfRetries > 0)
            {
                await Task.Delay(timeBetweenRetries);

                identificationResponse = await srsc.CheckIdentificationStatusAsync(processPollingLocation);

                if (identificationResponse.Status == Microsoft.ProjectOxford.SpeakerRecognition.Contract.Identification.Status.Succeeded)
                {
                    break;
                }
                else if (identificationResponse.Status == Microsoft.ProjectOxford.SpeakerRecognition.Contract.Identification.Status.Failed)
                {
                    throw new IdentificationException(identificationResponse.Message);
                }
                numOfRetries--;
            }
            if (numOfRetries <= 0)
            {
                throw new IdentificationException("Identification operation timeout.");
            }
            return(identificationResponse);
        }
Esempio n. 10
0
        public async Task IdentifySpeakers()
        {
            try
            {
                WriteLine("Getting all profiles");
                _allProfiles = await _serviceClient.GetProfilesAsync().ConfigureAwait(false);

                var testProfileIds = _allProfiles.Where(t => t.EnrollmentStatus == EnrollmentStatus.Enrolled).Select(
                    x =>
                {
                    WriteLine(
                        "Speaker Profile Id: " + x.ProfileId + " has been selected for streaming.");
                    return(x.ProfileId);
                })
                                     .ToArray();
                WriteLine("Streaming audio...");
                await StreamAudio(WindowSize, StepSize, testProfileIds.Where(x =>
                {
                    // Uncomment if you only want to specify select speakers
                    //var id = x.ToString();
                    //if (id.Contains("72041dcf-1ec5-4140-bfda-17e07a33898d") ||
                    //    id.Contains("db6999") ||
                    //    id.Contains("ce34b08c-3bf7-472b-a896-ff674ab576c9"))
                    //    return true;
                    //return false;
                    // ReSharper disable once ConvertToLambdaExpression
                    return(true);
                }).ToArray(), StreamAudioCancellationTokenSource.Token);
            }
            catch (GetProfileException ex)
            {
                WriteLine("Error Retrieving Profiles: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                WriteLine("Error: {0}", ex.Message);
            }
        }
        private async void voiceIdentification()
        {
            try
            {
                _identificationResultStckPnl.Visibility = Visibility.Hidden;
                if (_waveIn != null)
                {
                    _waveIn.StopRecording();
                }

                TimeSpan timeBetweenSaveAndIdentify = TimeSpan.FromSeconds(5.0);
                await Task.Delay(timeBetweenSaveAndIdentify);

                SpeakerIdentificationServiceClient _serviceClient = new SpeakerIdentificationServiceClient(speakerAPISubscriptionKey);

                List <Guid> list = new List <Guid>();
                Microsoft.ProjectOxford.SpeakerRecognition.Contract.Identification.Profile[] allProfiles = await _serviceClient.GetProfilesAsync();

                int itemsCount = 0;
                foreach (Microsoft.ProjectOxford.SpeakerRecognition.Contract.Identification.Profile profile in allProfiles)
                {
                    list.Add(profile.ProfileId);
                    itemsCount++;
                }
                Guid[] selectedIds = new Guid[itemsCount];
                for (int i = 0; i < itemsCount; i++)
                {
                    selectedIds[i] = list[i];
                }
                if (_selectedFile == "")
                {
                    throw new Exception("No File Selected.");
                }

                speechSynthesizer.SpeakAsync("Please wait we are verifying your voice.");
                Title = String.Format("Identifying File...");
                OperationLocation processPollingLocation;
                Console.WriteLine("Selected file is : {0}", _selectedFile);
                using (Stream audioStream = File.OpenRead(_selectedFile))
                {
                    //_selectedFile = "";
                    Console.WriteLine("Start");
                    Console.WriteLine("Audio File is : {0}", audioStream);
                    processPollingLocation = await _serviceClient.IdentifyAsync(audioStream, selectedIds, true);

                    Console.WriteLine("ProcesPolling Location : {0}", processPollingLocation);
                    Console.WriteLine("Done");
                }

                IdentificationOperation identificationResponse = null;
                int      numOfRetries       = 10;
                TimeSpan timeBetweenRetries = TimeSpan.FromSeconds(5.0);
                while (numOfRetries > 0)
                {
                    await Task.Delay(timeBetweenRetries);

                    identificationResponse = await _serviceClient.CheckIdentificationStatusAsync(processPollingLocation);

                    Console.WriteLine("Response is : {0}", identificationResponse);

                    if (identificationResponse.Status == Microsoft.ProjectOxford.SpeakerRecognition.Contract.Identification.Status.Succeeded)
                    {
                        break;
                    }
                    else if (identificationResponse.Status == Microsoft.ProjectOxford.SpeakerRecognition.Contract.Identification.Status.Failed)
                    {
                        Console.WriteLine("In");
                        speechSynthesizer.SpeakAsync("Failed. Please make sure your voice is registered.");
                        throw new IdentificationException(identificationResponse.Message);
                    }
                    numOfRetries--;
                }
                if (numOfRetries <= 0)
                {
                    throw new IdentificationException("Identification operation timeout.");
                }

                Title = String.Format("Identification Done.");

                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = "Select AccountNo, CustomerName From AccountDetails where AccountNo = (Select AccountNo From AuthenticationDetails where VoiceId = '" + identificationResponse.ProcessingResult.IdentifiedProfileId.ToString() + "')";
                dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        accountNo = dr.GetInt32(0);
                        voiceIdentifiedUserName = dr[1].ToString();
                        Console.WriteLine("Account No is : " + accountNo);
                        Console.WriteLine("Identified as :" + voiceIdentifiedUserName);
                        _identificationResultTxtBlk.Text = voiceIdentifiedUserName;
                    }
                }
                dr.Close();
                conn.Close();
                if (_identificationResultTxtBlk.Text == "")
                {
                    _identificationResultTxtBlk.Text = identificationResponse.ProcessingResult.IdentifiedProfileId.ToString();
                    speechSynthesizer.SpeakAsync("Sorry we have not found your data.");
                    return;
                }
                else
                {
                    if (faceIdentifiedUserName == voiceIdentifiedUserName)
                    {
                        Console.WriteLine("Selected file is : {0}", _selectedFile);

                        Stream stream = File.OpenRead(_selectedFile);
                        verifySpeaker(stream);
                        //speechSynthesizer.SpeakAsync("Hi.");
                        //speechSynthesizer.SpeakAsync(_identificationResultTxtBlk.Text.ToString());
                        //speechSynthesizer.SpeakAsync("Thanks to verify your face and voice.");
                        //speechSynthesizer.SpeakAsync("Now you can do your transactions");
                    }
                    else
                    {
                        speechSynthesizer.SpeakAsync("Sorry we have found different voice identity from your face identity.");
                        return;
                    }
                    _identificationConfidenceTxtBlk.Text    = identificationResponse.ProcessingResult.Confidence.ToString();
                    _identificationResultStckPnl.Visibility = Visibility.Visible;
                    GC.Collect();
                }
            }
            catch (IdentificationException ex)
            {
                Console.WriteLine("Speaker Identification Error : " + ex.Message);
                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
                GC.Collect();
            }
        }
        //private void loadFileBtn_Click(object sender, RoutedEventArgs e)
        //{
        //    identifyBtn.IsEnabled = true;
        //    OpenFileDialog openFileDialog = new OpenFileDialog();
        //    openFileDialog.Filter = "WAV Files(*.wav)|*.wav";
        //    bool? result = openFileDialog.ShowDialog();

        //    if (!(bool)result)
        //    {
        //        Title = String.Format("No File Selected.");
        //        return;
        //    }
        //    Title = String.Format("File Selected: " + openFileDialog.FileName);
        //    _selectedFile = openFileDialog.FileName;
        //}


        private async void identifyBtn_Click(object sender, RoutedEventArgs e)
        {
            _identificationResultStckPnl.Visibility = Visibility.Hidden;
            //First Stop Recording...
            recordBtn.IsEnabled   = true;
            identifyBtn.IsEnabled = false;
            if (_waveIn != null)
            {
                _waveIn.StopRecording();
            }

            TimeSpan timeBetweenSaveAndIdentify = TimeSpan.FromSeconds(5.0);
            await Task.Delay(timeBetweenSaveAndIdentify);

            //await UpdateAllSpeakersAsync();

            //Identify Voice
            //List<Guid> selectedItems = new List<Guid>(3);
            //selectedItems.Add(Guid.Parse("f7d5a9d2-9663-4504-b53c-ee0c2c975104")); //f7d5a9d2-9663-4504-b53c-ee0c2c975104
            //selectedItems.Add(Guid.Parse("acec28d0-cfd5-4bc4-8840-03bb523a43f7"));
            //selectedItems.Add(Guid.Parse("7ce81071-ef9d-46cf-9d87-02d465b1a972"));
            //selectedItems.Add(Guid.Parse("f7d5a9d2-9663-4504-b53c-ee0c2c975104"));
            //selectedItems.Add(Guid.Parse("0501e357-e56d-46b0-87ad-957ef8744d9c"));
            //selectedItems.Add(Guid.Parse("aeb46767-24b7-4d9d-a9ad-dd7dc965b0bb"));
            //selectedItems.Add(Guid.Parse("26c11b8d-6de2-4c5e-971c-8c4dc774d5e1"));
            //selectedItems.Add(Guid.Parse("f7d5a9d2-9663-4504-b53c-ee0c2c975104"));
            //selectedItems.Add(Guid.Parse("8f85b2c6-688a-4d44-a8c4-370be910b8bf"));

            //Guid[] selectedIds = new Guid[1];
            //int i = 0;
            //foreach (KeyValuePair<Guid, string> kv in enrollVoiceList)
            //{
            //    selectedIds[i] = kv.Key;
            //    i++;
            //}
            //selectedIds[0] = selectedItems[0];

            //for (int j = 0; j < 1; j++)
            //{
            //    selectedIds[i] = selectedItems[i];

            //}

            List <Guid> list = new List <Guid>();

            Profile[] allProfiles = await _serviceClient.GetProfilesAsync();

            int itemsCount = 0;

            foreach (Profile profile in allProfiles)
            {
                list.Add(profile.ProfileId);
                itemsCount++;
            }
            Guid[] selectedIds = new Guid[1];
            for (int i = 0; i < 1; i++)
            {
                selectedIds[i] = list[i];
            }

            try
            {
                if (_selectedFile == "")
                {
                    throw new Exception("No File Selected.");
                }

                Title = String.Format("Identifying File...");
                OperationLocation processPollingLocation;
                using (Stream audioStream = File.OpenRead(_selectedFile))
                {
                    _selectedFile = "";
                    Console.WriteLine("Audio File is : {0}", audioStream);
                    processPollingLocation = await _serviceClient.IdentifyAsync(audioStream, selectedIds, true);
                }

                IdentificationOperation identificationResponse = null;
                int      numOfRetries       = 10;
                TimeSpan timeBetweenRetries = TimeSpan.FromSeconds(5.0);
                while (numOfRetries > 0)
                {
                    await Task.Delay(timeBetweenRetries);

                    identificationResponse = await _serviceClient.CheckIdentificationStatusAsync(processPollingLocation);

                    Console.WriteLine("Response is : {0}", identificationResponse);
                    if (identificationResponse.Status == Status.Succeeded)
                    {
                        break;
                    }
                    else if (identificationResponse.Status == Status.Failed)
                    {
                        throw new IdentificationException(identificationResponse.Message);
                    }
                    numOfRetries--;
                }
                if (numOfRetries <= 0)
                {
                    throw new IdentificationException("Identification operation timeout.");
                }

                Title = String.Format("Identification Done.");

                if (identificationResponse.ProcessingResult.IdentifiedProfileId.ToString() == "aeb46767-24b7-4d9d-a9ad-dd7dc965b0bb")
                {
                    _identificationResultTxtBlk.Text = "Toshif"; //aeb46767 - 24b7 - 4d9d - a9ad - dd7dc965b0bb //f7d5a9d2-9663-4504-b53c-ee0c2c975104
                }

                else if (identificationResponse.ProcessingResult.IdentifiedProfileId.ToString() == "7ce81071-ef9d-46cf-9d87-02d465b1a972")
                {
                    _identificationResultTxtBlk.Text = "Aakash";
                }
                else if (identificationResponse.ProcessingResult.IdentifiedProfileId.ToString() == "acec28d0-cfd5-4bc4-8840-03bb523a43f7")
                {
                    _identificationResultTxtBlk.Text = "Mohammad Toshif Khan"; //0501e357 - e56d - 46b0 - 87ad - 957ef8744d9c
                }
                else if (identificationResponse.ProcessingResult.IdentifiedProfileId.ToString() == "f7d5a9d2-9663-4504-b53c-ee0c2c975104")
                {
                    _identificationResultTxtBlk.Text = "Nandini"; //f7d5a9d2 - 9663 - 4504 - b53c - ee0c2c975104
                }
                else
                {
                    _identificationResultTxtBlk.Text = identificationResponse.ProcessingResult.IdentifiedProfileId.ToString();
                }
                _identificationConfidenceTxtBlk.Text    = identificationResponse.ProcessingResult.Confidence.ToString();
                _identificationResultStckPnl.Visibility = Visibility.Visible;
            }
            catch (IdentificationException ex)
            {
                GC.Collect();
                Title = String.Format("Speaker Identification Error: " + ex.Message);
                Console.WriteLine("Speaker Identification Error : " + ex.Message);
            }
            catch (Exception ex)
            {
                GC.Collect();
                Title = String.Format("Error: " + ex.Message);
            }

            GC.Collect();
        }