예제 #1
0
        private async Task VerificationEnroll(SpeechConfig config, Dictionary <string, string> profileMapping)
        {
            using (var client = new VoiceProfileClient(config))
                using (var profile = await client.CreateProfileAsync(VoiceProfileType.TextDependentVerification, "en-us"))
                {
                    using (var audioInput = AudioConfig.FromDefaultMicrophoneInput())
                    {
                        Console.WriteLine($"Enrolling profile id {profile.Id}.");
                        // give the profile a human-readable display name
                        profileMapping.Add(profile.Id, "Your Name");

                        VoiceProfileEnrollmentResult result = null;
                        while (result is null || result.RemainingEnrollmentsCount > 0)
                        {
                            Console.WriteLine("Speak the passphrase, \"My voice is my passport, verify me.\"");
                            result = await client.EnrollProfileAsync(profile, audioInput);

                            Console.WriteLine($"Remaining enrollments needed: {result.RemainingEnrollmentsCount}");
                            Console.WriteLine("");
                        }

                        if (result.Reason == ResultReason.EnrolledVoiceProfile)
                        {
                            await SpeakerVerify(config, profile, profileMapping);
                        }
                        else if (result.Reason == ResultReason.Canceled)
                        {
                            var cancellation = VoiceProfileEnrollmentCancellationDetails.FromResult(result);
                            Console.WriteLine($"CANCELED {profile.Id}: ErrorCode={cancellation.ErrorCode} ErrorDetails={cancellation.ErrorDetails}");
                        }
                    }
                }
        }
예제 #2
0
        public static async Task VerificationEnroll(SpeechConfig config, Dictionary <string, string> profileMapping)
        {
            using (var client = new VoiceProfileClient(config))
                using (var profile = await client.CreateProfileAsync(VoiceProfileType.TextIndependentVerification, "en-us"))
                {
                    using (var audioInput = AudioConfig.FromWavFileInput(settings[SettingIndex.ExampleAudio]))
                    {
                        Console.WriteLine($"Enrolling profile id {profile.Id}.");
                        // give the profile a human-readable display name
                        profileMapping.Add(profile.Id, "Test speaker");

                        VoiceProfileEnrollmentResult result = null;
                        result = await client.EnrollProfileAsync(profile, audioInput);

                        if (result != null)
                        {
                            if (result.Reason == ResultReason.EnrolledVoiceProfile)
                            {
                                string[] files = Directory.GetFiles(settings[SettingIndex.SourceDir], "*.wav", SearchOption.TopDirectoryOnly);

                                foreach (string file in files)
                                {
                                    await SpeakerVerify(config, profile, profileMapping, file);
                                }
                            }
                            else if (result.Reason == ResultReason.Canceled)
                            {
                                var cancellation = VoiceProfileEnrollmentCancellationDetails.FromResult(result);
                                Console.WriteLine($"CANCELED {profile.Id}: ErrorCode={cancellation.ErrorCode} ErrorDetails={cancellation.ErrorDetails}");
                            }
                            await client.DeleteProfileAsync(profile);
                        }
                        else
                        {
                            Console.WriteLine("Profile enrollment error");
                        }
                    }
                }
        }
        private async Task <string> EnrollProfileAsync(SpeechConfig config, AudioConfig audioInput, VoiceProfileType voiceProfileType)
        {
            ClearTextMessages();

            using (var client = new VoiceProfileClient(config))
            {
                VoiceProfile profile = await client.CreateProfileAsync(voiceProfileType, "en-us");

                AddTextMessageToDisplay($"Enrolling identification profile id {profile.Id}.");

                VoiceProfileEnrollmentResult result = null;
                int remainingSeconds = 0;
                while (result is null || result.RemainingEnrollmentsSpeechLength > TimeSpan.Zero)
                {
                    result = await client.EnrollProfileAsync(profile, audioInput);

                    remainingSeconds = result.RemainingEnrollmentsSpeechLength.HasValue ? (int)result.RemainingEnrollmentsSpeechLength.Value.TotalSeconds : 0;
                    AddTextMessageToDisplay($"Remaining identification enrollment audio time needed: {remainingSeconds} sec");
                }

                if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = VoiceProfileEnrollmentCancellationDetails.FromResult(result);
                    AddTextMessageToDisplay($"CANCELED {profile.Id}: ErrorCode={cancellation.ErrorCode} ErrorDetails={cancellation.ErrorDetails}");

                    await this.speakerRecognitionService.DeleteProfileAsync(profile.Id, voiceProfileType);
                }

                if (result.Reason == ResultReason.EnrolledVoiceProfile)
                {
                    return(profile.Id);
                }

                return(null);
            }
        }