private async void _addBtn_Click(object sender, RoutedEventArgs e) { MainWindow window = (MainWindow)Application.Current.MainWindow; try { window.Log("Creating Speaker Profile..."); CreateProfileResponse creationResponse = await _serviceClient.CreateProfileAsync(_localeCmb.Text); window.Log("Speaker Profile Created."); window.Log("Retrieving The Created Profile..."); Profile profile = await _serviceClient.GetProfileAsync(creationResponse.ProfileId); window.Log("Speaker Profile Retrieved."); SpeakersListPage.SpeakersList.AddSpeaker(profile); } catch (CreateProfileException ex) { window.Log("Profile Creation Error: " + ex.Message); } catch (GetProfileException ex) { window.Log("Error Retrieving The Profile: " + ex.Message); } catch (Exception ex) { window.Log("Error: " + ex.Message); } }
/// <summary> /// Creates a new user profile for a User and returns the GUID for that profile. /// In the full system, this method should include a check to find out /// if the user is already registered in persistent storage (i.e. database). /// </summary> /// <param name="client"></param> /// <param name="locale"></param> /// <returns></returns> public static async Task <Guid> CreateUserProfile(SpeakerIdentificationServiceClient client, User user, string locale = "en-us") { var taskComplete = new TaskCompletionSource <Guid>(); var profileTask = client.CreateProfileAsync(locale); await profileTask; taskComplete.SetResult(profileTask.Result.ProfileId); return(profileTask.Result.ProfileId); }
private async void btnCreateProfile_Click(object sender, RoutedEventArgs e) { try { CreateProfileResponse response = await _serviceClient.CreateProfileAsync("en-us"); txtInfo.Text = "Profile Created: " + response.ProfileId; } catch { } await GetProfiles(); }
private void EnrollSpeaker(Stream stream) { // Reset pointer stream.Seek(0, SeekOrigin.Begin); SpeakerIdentificationServiceClient speakerIDClient = new SpeakerIdentificationServiceClient("c6b005dcf13e45b6a91485d38763277b"); //Creating Speaker Profile... CreateProfileResponse creationResponse = speakerIDClient.CreateProfileAsync("en-US").Result; //Speaker Profile Created. //Retrieving The Created Profile... Profile profile = speakerIDClient.GetProfileAsync(creationResponse.ProfileId).Result; //Speaker Profile Retrieved." //Enrolling Speaker OperationLocation processPollingLocation = speakerIDClient.EnrollAsync(stream, profile.ProfileId, false).Result; EnrollmentOperation enrollmentResult; int numOfRetries = 10; TimeSpan timeBetweenRetries = TimeSpan.FromSeconds(5.0); while (numOfRetries > 0) { Task.Delay(timeBetweenRetries); enrollmentResult = speakerIDClient.CheckEnrollmentStatusAsync(processPollingLocation).Result; if (enrollmentResult.Status == Status.Succeeded) { break; } else if (enrollmentResult.Status == Status.Failed) { throw new EnrollmentException(enrollmentResult.Message); } numOfRetries--; } if (numOfRetries <= 0) { throw new EnrollmentException("Enrollment operation timeout."); } //Enrollment Done. // Store profile in memory cache ObjectCache memCache = MemoryCache.Default; var profiles = memCache.Get("SpeakerProfiles") != null?memCache.Get("SpeakerProfiles") as List <Profile> : new List <Profile>(); memCache.Remove("SpeakerProfiles"); memCache.Add("SpeakerProfiles", profiles, DateTimeOffset.UtcNow.AddHours(2)); }
public async void voicetoprofile(byte[] data, string filename) { try { SpeakerIdentificationServiceClient _serviceClient = new SpeakerIdentificationServiceClient("xxxxxxxxxxxxxxxxxxxxxxx"); CreateProfileResponse creationResponse = await _serviceClient.CreateProfileAsync(name.Text.ToString()); Profile profile = await _serviceClient.GetProfileAsync(creationResponse.ProfileId); //SpeakersListPage.SpeakersList.AddSpeaker(profile); OperationLocation processPollingLocation; using (Stream audioStream = new MemoryStream(data)) { //_selectedFile = ""; processPollingLocation = await _serviceClient.EnrollAsync(audioStream, profile.ProfileId); } EnrollmentOperation enrollmentResult; int numOfRetries = 10; TimeSpan timeBetweenRetries = TimeSpan.FromSeconds(5.0); while (numOfRetries > 0) { await Task.Delay(timeBetweenRetries); enrollmentResult = await _serviceClient.CheckEnrollmentStatusAsync(processPollingLocation); if (enrollmentResult.Status == Status.Succeeded) { break; } else if (enrollmentResult.Status == Status.Failed) { throw new EnrollmentException(enrollmentResult.Message); } numOfRetries--; } if (numOfRetries <= 0) { throw new EnrollmentException("Enrollment operation timeout."); } } catch (Exception ex) { throw ex; } }
//This Creates a new speaker in the database //INPUT: //OUTPUT: functionResult public async Task <functionResult> addSpeaker() { functionResult result = new functionResult(); //If the _serviceClient is null, create it with the subsciption key stored if (_serviceClient == null) { _serviceClient = new SpeakerIdentificationServiceClient(_subscriptionKey); } try { //Create the new profile and assign it to the Profile Tag CreateProfileResponse creationResponse = await _serviceClient.CreateProfileAsync("en-us"); Profile profile = await _serviceClient.GetProfileAsync(creationResponse.ProfileId); result.Result = true; result.Message = profile.ProfileId.ToString(); } catch (CreateProfileException ex) { result.Result = false; result.Message = "Error Creating The Profile: " + ex.Message.ToString(); } catch (GetProfileException ex) { result.Result = false; result.Message = "Error Retrieving The Profile: " + ex.Message.ToString(); } catch (Exception ex) { result.Result = false; result.Message = "Error: " + ex.Message.ToString(); } return(result); }
//To make the user's profile. private async void registerBtn_Click(object sender, RoutedEventArgs e) { try { registerBtn.IsEnabled = false; var faceServiceClient = new FaceServiceClient(faceAPISubscriptionKey); registerForm = new RegisterForm(); registerForm.ShowDialog(); if (registerForm.textBox.Text == "") { speechSynthesizer.SpeakAsync("Please enter your name."); var result = MessageBox.Show("Please Enter your Name."); if (result == MessageBoxResult.OK) { registerForm = new RegisterForm(); registerForm.ShowDialog(); } registerBtn.IsEnabled = true; return; } else { userName = registerForm.textBox.Text; userDirPath = dirPath + userName + "\\"; bool exist = Directory.Exists(dirPath + userName); if (!exist) { Directory.CreateDirectory(dirPath + userName); accountBal = 10000; //Insert some amount in database along with username. conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "Insert into AccountDetails (AccountBalance,CustomerName) values ('" + accountBal + "' , '" + userName + "')"; cmd.ExecuteNonQuery(); conn.Close(); Console.WriteLine("Record Successfully Inserted"); //Fetch the accountno from AccountDetails by using username. conn.Open(); SqlCommand cmdd = conn.CreateCommand(); cmdd.CommandType = System.Data.CommandType.Text; cmdd.CommandText = "Select AccountNo From AccountDetails where CustomerName = '" + userName + "'"; dr = cmdd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { accountNo = int.Parse(dr[0].ToString()); } } dr.Close(); //Insert this accountno into AuthenticationDetails table. SqlCommand cmd1 = conn.CreateCommand(); cmd1.CommandType = System.Data.CommandType.Text; cmd1.CommandText = "Insert into AuthenticationDetails (AccountNo) values ('" + accountNo + "')"; cmd1.ExecuteNonQuery(); conn.Close(); Console.WriteLine("Record Successfully Inserted"); await Task.Delay(2000); speechSynthesizer.SpeakAsync("Ok, Now you need to capture your three photos."); Title = string.Format("Ready...Now click your three photos."); } else { registerBtn.IsEnabled = true; SqlCommand cmd4 = conn.CreateCommand(); cmd4.CommandType = System.Data.CommandType.Text; cmd4.CommandText = "Select * From AuthenticationDetails where FaceId = '" + faceid + "'"; dr = cmd.ExecuteReader(); if (dr.Read()) { speechSynthesizer.SpeakAsync("You already registered your data."); Title = string.Format(""); return; } else { Console.WriteLine("Sorry try with another name"); speechSynthesizer.SpeakAsync("Try with another Name."); registerBtn.IsEnabled = true; return; } } } //creating speaker profile with en-us locality. SpeakerIdentificationServiceClient _serviceClient = new SpeakerIdentificationServiceClient(speakerAPISubscriptionKey); creationResponse = await _serviceClient.CreateProfileAsync("en-US"); var tag = System.IO.Path.GetFileName(dirPath + userName); Console.WriteLine("FileName : {0}", tag); p.PersonName = tag; // Call create person REST API, the new create person id will be returned Console.WriteLine("Request: Creating person \"{0}\"", p.PersonName); p.PersonId = (await faceServiceClient.CreatePersonAsync(GroupName, p.PersonName)).PersonId.ToString(); Console.WriteLine("Person Id is : {0}", p.PersonId); faceid = p.PersonId.ToString(); Console.WriteLine("Response: Success. Person \"{0}\" (PersonID:{1}) created", p.PersonName, p.PersonId.ToString()); await Task.Delay(3000); captureBtn.IsEnabled = true; GC.Collect(); } catch (Exception ex) { registerBtn.IsEnabled = true; MessageBox.Show(ex.Message); } }
/// <summary> /// Adds speaker profile management dialog /// </summary> private void AddProfileDialog() { Add(Inputs.ManageProfile, new ChoicePrompt(Culture.English)); Add(Dialogs.ManageProfileDialogName, new WaterfallStep[] { async(dc, args, next) => { // Prompt for action. var mainOptions = new List <string> { ProfileMenu.ViewProfile, ProfileMenu.CreateProfile, ProfileMenu.DeleteProfile, ProfileMenu.EnrollProfile, ProfileMenu.BackToMainMenu }; await dc.Prompt(Inputs.ManageProfile, "What do you want to do?", new ChoicePromptOptions { Choices = ChoiceFactory.ToChoices(mainOptions), RetryPromptActivity = MessageFactory.SuggestedActions(mainOptions, "Please select an option.") as Activity }); }, async(dc, args, next) => { var action = (FoundChoice)args["Value"]; switch (action.Value) { case ProfileMenu.ViewProfile: await dc.Replace(Dialogs.ViewProfileDialogName); break; case ProfileMenu.CreateProfile: await dc.Replace(Dialogs.CreateProfileDialogName); break; case ProfileMenu.DeleteProfile: await dc.Replace(Dialogs.DeleteProfileDialogName); break; case ProfileMenu.EnrollProfile: await dc.Replace(Dialogs.EnrollProfileDialogName); break; case ProfileMenu.BackToMainMenu: await dc.Replace(Dialogs.MainDialogName); break; } } }); Add(Dialogs.ViewProfileDialogName, new WaterfallStep[] { async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (string.IsNullOrWhiteSpace(state.Name)) { await dc.Prompt(Inputs.NamePrompt, "What is your name?"); } else { await next(args); } }, async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (string.IsNullOrWhiteSpace(state.Name)) { string name = (string)args["Value"]; state.Name = name; } if (state.ProfileId.HasValue) { var profile = await _client.GetProfileAsync(state.ProfileId.Value); state.EnrollmentStatus = profile.EnrollmentStatus; switch (profile.EnrollmentStatus) { case EnrollmentStatus.Enrolling: await dc.Context.SendActivity( $"Welcome back {state.Name}. You are enrolling, {profile.RemainingEnrollmentSpeechSeconds}s remaining"); break; case EnrollmentStatus.Training: await dc.Context.SendActivity($"Welcome back {state.Name}. Your profile is being trained."); break; case EnrollmentStatus.Enrolled: await dc.Context.SendActivity($"Welcome back {state.Name}. Your profile is enrolled."); break; } } else { await dc.Context.SendActivity($"I haven't seen you before, {state.Name}"); } //we're done await dc.Replace(Dialogs.ManageProfileDialogName); } }); Add(Dialogs.CreateProfileDialogName, new WaterfallStep[] { async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (string.IsNullOrWhiteSpace(state.Name)) { await dc.Prompt(Inputs.NamePrompt, "What is your name?"); } else { await next(args); } }, async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (string.IsNullOrWhiteSpace(state.Name)) { string name = (string)args["Value"]; state.Name = name; } if (state.ProfileId.HasValue) { //exists await dc.Context.SendActivity( $"I know you {state.Name}. Your existing profile id is: {state.ProfileId.Value}"); } else { //new await dc.Context.SendActivity("Creating a new profile..."); var result = await _client.CreateProfileAsync("en-US"); state.ProfileId = result.ProfileId; state.EnrollmentStatus = EnrollmentStatus.Enrolling; await dc.Context.SendActivity($"Welcome {state.Name}. Your new profile id is: {result.ProfileId}"); //we're done await dc.Replace(Dialogs.ManageProfileDialogName); } } }); Add(Dialogs.DeleteProfileDialogName, new WaterfallStep[] { async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (string.IsNullOrWhiteSpace(state.Name)) { await dc.Prompt(Inputs.NamePrompt, "What is your name?"); } else { await next(args); } }, async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (string.IsNullOrWhiteSpace(state.Name)) { string name = (string)args["Value"]; state.Name = name; } if (state.ProfileId.HasValue) { //exists await dc.Context.SendActivity($"Deleting your profile"); await _client.DeleteProfileAsync(state.ProfileId.Value); state.ProfileId = null; await dc.Context.SendActivity($"Deleted your profile"); } else { //new await dc.Context.SendActivity("I'm sorry, you don't have a profile to delete."); } //we're done await dc.Replace(Dialogs.ManageProfileDialogName); } }); Add(Dialogs.EnrollProfileDialogName, new WaterfallStep[] { async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (string.IsNullOrWhiteSpace(state.Name)) { await dc.Prompt(Inputs.NamePrompt, "What is your name?"); } else { await next(args); } }, async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (string.IsNullOrWhiteSpace(state.Name)) { string name = (string)args["Value"]; state.Name = name; } if (state.ProfileId.HasValue) { //exists await dc.Context.SendActivity($"Enrolling your profile"); await dc.Prompt(Inputs.EnrollProfilePrompt, "Please upload a .wav file", new PromptOptions()); } else { //new await dc.Context.SendActivity("I'm sorry, you don't have a profile to enroll."); //we're done await dc.Replace(Dialogs.ManageProfileDialogName); } }, async(dc, args, next) => { var state = dc.Context.GetConversationState <ProfileState>(); if (!state.ProfileId.HasValue) { //new await dc.Context.SendActivity("I'm sorry, you don't have a profile to enroll."); //we're done await dc.Replace(Dialogs.ManageProfileDialogName); return; } //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.ManageProfileDialogName); 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.ManageProfileDialogName); return; } string attachmentContentUrl = attachment.ContentUrl; //send attachment in chunks to be analyzed await dc.Context.SendActivity("Enrolling a profile with your voice..."); await EnrollWavFile(attachmentContentUrl, state.ProfileId.Value, dc); await dc.Context.SendActivity("Enrolling of attachment is complete."); //we're done await dc.Replace(Dialogs.ManageProfileDialogName); } }); Add(Inputs.EnrollProfilePrompt, new AttachmentPrompt()); }