private async void GetEnrollmentOperationStatus(OperationLocation location) { try { while (true) { EnrollmentOperation result = await _speakerIdentificationClient.CheckEnrollmentStatusAsync(location); if (result.Status != Status.Running) { RaiseOnIdentificationStatusUpdated(new SpeakerIdentificationStatusUpdateEventArgs(result.Status.ToString(), $"Enrollment finished. Enrollment status: {result.ProcessingResult.EnrollmentStatus.ToString()}")); break; } RaiseOnIdentificationStatusUpdated(new SpeakerIdentificationStatusUpdateEventArgs(result.Status.ToString(), "Enrolling...")); await Task.Delay(1000); } } catch (IdentificationException ex) { RaiseOnIdentificationError(new SpeakerIdentificationErrorEventArgs($"Failed to get operation status: {ex.Message}")); } catch (Exception ex) { RaiseOnIdentificationError(new SpeakerIdentificationErrorEventArgs($"Failed to get operation status: {ex.Message}")); } }
/// <summary> /// Gets the enrollment operation status or result asynchronously /// </summary> /// <param name="location">The location returned upon enrollment</param> /// <exception cref="EnrollmentException">Thrown in case of internal server error or an invalid url</exception> /// <exception cref="TimeoutException">Thrown in case the connection timed out</exception> /// <returns>The enrollment object encapsulating the result</returns> public async Task <EnrollmentOperation> CheckEnrollmentStatusAsync(OperationLocation location) { try { EnrollmentOperation operation = await CheckStatusAsync <EnrollmentOperation, EnrollmentException>(location.Url).ConfigureAwait(false); return(operation); } catch (TaskCanceledException exception) { throw new TimeoutException("Connection timed out: " + exception.Message); } }
async Task finishEnrollment() { if (btnRecordEnroll.IsEnabled == false) { return; // if user clicks and then comes timer event } btnRecordEnroll.Content = "Start record enrollment"; btnRecordEnroll.IsEnabled = false; await CaptureMedia.StopRecordAsync(); Stream str = AudioStream.AsStream(); str.Seek(0, SeekOrigin.Begin); _speakerId = Guid.Parse((lbProfiles.SelectedItem as ListBoxItem).Content.ToString()); OperationLocation processPollingLocation; try { processPollingLocation = await _serviceClient.EnrollAsync(str, _speakerId); } catch (EnrollmentException vx) { txtInfo.Text = vx.Message; CleanAfter(); return; } catch (Exception vx) { txtInfo.Text = vx.Message; CleanAfter(); return; } EnrollmentOperation enrollmentResult = null; 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) { txtInfo.Text = enrollmentResult.Message; CleanAfter(); return; } numOfRetries--; } if (numOfRetries <= 0) { txtInfo.Text = "Identification operation timeout"; } else { txtInfo.Text = "Enrollment done. " + enrollmentResult.Status + Environment.NewLine + " Remaining Speech Time " + enrollmentResult.ProcessingResult.RemainingEnrollmentSpeechTime; } CleanAfter(); }