//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 will take the recorded speech and compare it against the expected string //INPUT: expectedString //OUPUT: True if the strings match, false if not private Boolean doSpeechTextValidation(string expectedString) { speechRecognition_system_speech ps = new speechRecognition_system_speech(); functionResult f = ps.convertToSpeechWithString(audioStream1, expectedString); if (f.Result == true) { //If no recognised result, then no valid phrase if found. this is NOT an error if (f.recognitionResult == null) { txtRecognisedText.Text = "No Valid Phrase Found, Please try again ensuring to speak slowly and clearly"; txtRecognisedText.BackColor = Color.Salmon; return(false); } else { txtRecognisedText.Text = f.recognitionResult.Text + " (Result Confidence = " + f.recognitionResult.Confidence + ")"; txtRecognisedText.BackColor = Color.LightGreen; return(true); } } else { MessageBox.Show(f.Message, "doSpeechTextValidation - Error"); return(false); } }
//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 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; } }
private void btnRecord1_Click(object sender, EventArgs e) { //Enable/Disable the buttons as required audioCapture a = new audioCapture(); functionResult f = a.onRecord(ref audioStream1); if (f.Result == true) { timerClock.Start(); setValidStream(false); btnStopRecord1.Enabled = true; } }
//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 void btnSpeakCommand_Click(object sender, EventArgs e) { //create the audio capture functionality and start recording audioCapture a = new audioCapture(); functionResult r = a.onRecord(ref audioStream1); if (r.Result == true) { //If there are no errors. Set the lable text and button enable/disable. //also start the timer txtTextRecognises.Text = "Please say your command:"; timerClock.Start(); btnStartCommand.Enabled = false; btnStopCommand.Enabled = true; } }
private void btnRecord_Click(object sender, EventArgs e) { //create the audio capture functionality and start recording audioCapture a = new audioCapture(); functionResult r = a.onRecord(ref audioStream1); if (r.Result == true) { //If there are no errors. Set the lable text and button enable/disable. //also start the timer timerClock.Start(); btnRecord.Enabled = false; btnCreate.Enabled = false; btnStopRecording.Enabled = true; } }
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; }
//This will do the speech validation functionality //INPUT: //OUPUT: true for valid command found private Boolean doSpeechTextValidation() { speechRecognition_system_speech ps = new speechRecognition_system_speech(); Choices c = new Choices(); //Now build a list of choices foreach (DataGridViewRow dr in dgvUserAccounts.Rows) { string keyword = dr.Cells["SiteKey"].Value.ToString(); //Generate a list of available commands c.Add("Open " + keyword); } functionResult f = ps.convertToSpeechwithChoices(audioStream1, c); if (f.Result == true) { if (f.recognitionResult == null) { txtTextRecognises.Text = "No Valid Phrase Found, Please try again ensuring to speak slowly and clearly"; return(false); } else { txtTextRecognises.Text = f.recognitionResult.Text + " (Result Confidence = " + f.recognitionResult.Confidence + ")"; return(true); } } else { MessageBox.Show(f.Message, "doSpeechTextValidation - Error"); return(false); } }
private void btnRemoveLogin_Click(object sender, EventArgs e) { //Get the selected row int selectedrowindex = dgvUserAccounts.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dgvUserAccounts.Rows[selectedrowindex]; //Get the information about the selected row int AccountID = Convert.ToInt32(selectedRow.Cells["AccountID"].Value.ToString()); string SiteKey = selectedRow.Cells["SiteKey"].Value.ToString(); //Make sure a row is selected if (AccountID > 0) { this.Cursor = Cursors.WaitCursor; //Ensure the user wants to delete the row if (MessageBox.Show("Are you sure you want to remove Account: " + SiteKey + " (" + AccountID + ") ?" + Environment.NewLine + "This will remove account and the assigned information will be lost.", "Remove Account", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { functionResult r = new functionResult(); //Next remove the user from our database Database db = new Database(); r = db.RemoveAccountLogin(AccountID); //If there is no issues, reload the listing if (r.Result == true) { LoadLogins(); } else { MessageBox.Show(r.Message, "Error removing from database"); } } this.Cursor = Cursors.Default; } }