//This calls the functionality to enroll the recorded audio samlpe private async void EnrollProfile() { DataGridViewRow dr = dgvProfiles.CurrentRow; if (dr != null) { string profileID = dr.Cells["SpeakerID"].Value.ToString(); projectOxfordSpeaker s = new projectOxfordSpeaker(); functionResult result = await s.enrollSpeaker(audioStream1, new Guid(profileID), Convert.ToDouble(lblSample1Length.Text)); if (result.Result == true) { //setValidStream(true); LoadProfiles(); } else { MessageBox.Show(result.Message, "Function Result: Enroll Profile", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Please select a profile to enroll to", "Enroll Sample", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//This calls the functionality to load all available profiles private async void LoadProfiles() { this.Cursor = Cursors.WaitCursor; setValidStream(false); projectOxfordSpeaker s = new projectOxfordSpeaker(); DataTable dt = await s.UpdateAllSpeakers(); dgvProfiles.DataSource = dt; if (dt.Rows.Count > 0) { setValidStream(false); btnAddProfile.Enabled = true; btnRemoveProfile.Enabled = true; btnRecord1.Enabled = true; } else { btnAddProfile.Enabled = false; btnRemoveProfile.Enabled = false; btnRecord1.Enabled = true; } this.Cursor = Cursors.Default; }
//This calls the functionality to remove the selected profile private async void RemoveProfile() { if (dgvProfiles.RowCount > 0) { DataGridViewRow dr = dgvProfiles.CurrentRow; if (dr != null) { string profileID = dr.Cells["SpeakerID"].Value.ToString(); DialogResult dresult = MessageBox.Show("Are you sure you want to remove profile ID: " + profileID + "?", "Remove Profile", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dresult == DialogResult.Yes) { projectOxfordSpeaker s = new projectOxfordSpeaker(); functionResult result = await s.removeSpeaker(new Guid(profileID)); if (result.Result == true) { LoadProfiles(); } else { MessageBox.Show(result.Message, "Function Result: Remove Profile", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Please select a profile to remove", "Remove Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("There are no profiles available. Please press the 'Load Profiles' to check for profiles on the server or 'Create Profile' to create a new profile", "Remove Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//This will perform the verification of the user sample against the profile ID //INPUT: profile ID //OUPUT: private async void performSpeakerEnrollment(string profileID) { //Disable the buttons so the user doesn't try to re-record btnRecord.Enabled = false; btnStopRecording.Enabled = false; btnCreate.Enabled = false; //Validate the audio stream against the profile ID projectOxfordSpeaker s = new projectOxfordSpeaker(); functionResult result = await s.enrollSpeaker(audioStream1, new Guid(profileID), Convert.ToDouble(lblRecordingLength.Text)); //If all is good, set the validation as true if (result.Result == true) { this.DialogResult = DialogResult.OK; } else { //If there are errors. display the message MessageBox.Show(result.Message, "Function Result: Enroll Speaker", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Cursor = Cursors.Default; btnCreate.Text = "Create"; btnCancel.Enabled = true; btnCreate.Enabled = true; } }
private async void frmViewAllProfiles_Load(object sender, EventArgs e) { //this loads all profiles on the MS server for viewing. Only realy needed for testing projectOxfordSpeaker s = new projectOxfordSpeaker(); DataTable dt = await s.UpdateAllSpeakers(); dataGridView1.DataSource = dt; }
private async void btnRemoveUser_Click(object sender, EventArgs e) { //Make sure a row is selected if (mcbUserAccounts.SelectedValue != null) { this.Cursor = Cursors.WaitCursor; //Get the actual data row DataRowView drv = (DataRowView)mcbUserAccounts.SelectedItem; //Assign the required values to variables string ProfileID = Convert.ToString(drv["PROFILEID"].ToString()); string Name = Convert.ToString(drv["NAME"].ToString()); int ID = Convert.ToInt32(drv["ID"]); //Ensure the user wasnt to delete the row if (MessageBox.Show("Are you sure you want to remove User ID: " + ID.ToString() + "?" + Environment.NewLine + "This will remove their profile and enrollment information and cannot be reversed.", "Remove User", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { functionResult r = new functionResult(); //If there is a valid profile ID, remove it from the server, else just set the result as true to continue if (ProfileID.Length > 0) { projectOxfordSpeaker s = new projectOxfordSpeaker(); r = await s.removeSpeaker(new Guid(ProfileID)); } else { r.Result = true; r.Message = "No Profile ID"; } if (r.Result == true) { //Next remove the user from our database Database db = new Database(); r = db.removeUser(ID.ToString()); //If there is no issues, reload the listing if (r.Result == true) { LoadListing(); } else { MessageBox.Show(r.Message, "Error removing from database"); } } else { MessageBox.Show(r.Message, "Error removing Microsoft profile"); } } this.Cursor = Cursors.Default; } }
//This will perform the verification of the user sample against the profile ID //INPUT: //OUPUT: private async void performSpeakerValidation() { //Disable the buttons so the user doesn't try to re-record btnRecord.Enabled = false; btnStopRecording.Enabled = false; btnContinue.Enabled = false; string profileID = public_profileID; //Validate the audio stream against the profile ID projectOxfordSpeaker s = new projectOxfordSpeaker(); speakerVerificationResult result = await s.verifySpeaker(audioStream1, new Guid(profileID), Convert.ToDouble(lblRecordingLength.Text)); //If all is good, set the validation as true if (result.Result == true) { if (profileID == result.IdentifiedProfileId) { validSpeaker = true; lblValidation.Text = "User validated"; lblValidation.ForeColor = Color.Green; } else { lblValidation.Text = "Invalid User"; validSpeaker = false; lblValidation.ForeColor = Color.Salmon; } } else { //If there are errors. display the message validLogin = false; MessageBox.Show(result.Message, "Function Result: Verify Speaker", MessageBoxButtons.OK, MessageBoxIcon.Error); } btnRecord.Enabled = true; //Stop the progress bar progressBar1.Style = ProgressBarStyle.Continuous; if (validSpeaker && validSpeech) { validLogin = true; btnContinue.BackColor = Color.Green; //If autolog in checked, do login if (chkAutoLogin.Checked == true) { this.DialogResult = DialogResult.OK; } } btnContinue.Enabled = validLogin; }
//This calls the functionality to add a profile private async void AddProfile() { projectOxfordSpeaker s = new projectOxfordSpeaker(); functionResult result = await s.addSpeaker(); if (result.Result == true) { LoadProfiles(); } else { MessageBox.Show(result.Message, "Function Result: Add Profile", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async void btnCreate_Click(object sender, EventArgs e) { if (txtUserName.Text.Length == 0) { MessageBox.Show("Please enter a valid user name", "Add User"); return; } this.Cursor = Cursors.WaitCursor; btnCreate.Text = "Please Wait"; btnCancel.Enabled = false; btnCreate.Enabled = false; Database db = new Database(); functionResult r = db.addNewUser(txtUserName.Text); if (r.Result == true) { string newUserID = r.Message; projectOxfordSpeaker s = new projectOxfordSpeaker(); r = await s.addSpeaker(); if (r.Result == true) { db.updateUser(newUserID, txtUserName.Text, r.Message); performSpeakerEnrollment(r.Message); } else { MessageBox.Show(r.Message, "Error when creating new profile"); btnCreate.Text = "Create"; btnCancel.Enabled = true; btnCreate.Enabled = true; } } else { MessageBox.Show(r.Message, "Error when adding new user"); btnCreate.Text = "Create"; btnCancel.Enabled = true; btnCreate.Enabled = true; } this.Cursor = Cursors.Default; }