private static async Task <int> RunEnrollAndReturnExitCode(EnrollOptions opts) { SpeechApi.Initialize( new SpeechApi.Builder() .SetDeveloperKey(opts.DeveloperKey) .SetApplicationKey(opts.ApplicationKey) .SetApplicationSource("Dynamic.Speech.Samples") .SetLogger(Logger) .Build() ); if (string.IsNullOrEmpty(opts.Path) || !Directory.Exists(opts.Path)) { Logger.LogError("No Enrollment Directory Found for ClientId: {0}", opts.ClientId); return(1); } string[] enrollmentFiles = Directory.GetFiles(opts.Path, "*.wav"); if (enrollmentFiles == null || enrollmentFiles.Length == 0) { Logger.LogError("No Enrollment Files Found for ClientId Folder: {0}", opts.ClientId); return(1); } await PerformEnroll(opts, enrollmentFiles); return(0); }
private static async Task PerformEnroll(EnrollOptions opts, string[] enrollmentFiles) { var enroller = new SpeechEnroller(); enroller.ClientId = opts.ClientId; if (!string.IsNullOrEmpty(opts.Gender)) { switch (opts.Gender.ToLower()) { case "m": case "male": { enroller.SubPopulation = SpeechEnroller.Gender.Male; } break; case "f": case "female": { enroller.SubPopulation = SpeechEnroller.Gender.Female; } break; case "u": case "unknown": default: { enroller.SubPopulation = SpeechEnroller.Gender.Unknown; } break; } } else { enroller.SubPopulation = SpeechEnroller.Gender.Unknown; } if (!string.IsNullOrEmpty(opts.InteractionId)) { enroller.InteractionId = opts.InteractionId; } if (!string.IsNullOrEmpty(opts.InteractionTag)) { enroller.InteractionTag = opts.InteractionTag; } try { if (await enroller.StartAsync()) { foreach (var file in enrollmentFiles) { await enroller.PostAsync(file); Logger.LogInfo("Speech-Extracted: {0}", enroller.SpeechExtracted); } var result = await enroller.TrainAsync(); Logger.LogInfo("Has-Enough-Speech: {0}", enroller.HasEnoughSpeech); Logger.LogInfo("Is-Trained: {0}", enroller.IsTrained); Logger.LogInfo("Result: {0}", result); Logger.LogInfo("Speech-Trained: {0}", enroller.SpeechTrained); if (result == SpeechEnroller.Result.Success) { Logger.LogInfo("ClientId: {0}, Successfully Enrolled", opts.ClientId); } else { Logger.LogError("Error Found for ClientId: {0} - {1}", opts.ClientId, result); } } } catch (Exception ex) { Logger.LogError(ex); if (enroller.IsSessionOpen) { await enroller.CancelAsync("Exception Occurred"); } } }