Ejemplo n.º 1
0
        // perform enrollment
        public static async Task EnrollSpeakerAsync(VoiceProfileClient client, VoiceProfile profile, string audioFileName)
        {
            // Create audio input for enrollment from audio files. Replace with your own audio files.
            using (var audioInput = AudioConfig.FromWavFileInput(audioFileName))
            {
                var reason = ResultReason.EnrollingVoiceProfile;
                while (reason == ResultReason.EnrollingVoiceProfile)
                {
                    var result = await client.EnrollProfileAsync(profile, audioInput);

                    if (result.Reason == ResultReason.EnrollingVoiceProfile)
                    {
                        Console.WriteLine($"Enrolling profile id {profile.Id}.");
                    }
                    else if (result.Reason == ResultReason.EnrolledVoiceProfile)
                    {
                        Console.WriteLine($"Enrolled profile id {profile.Id}.");
                    }
                    else if (result.Reason == ResultReason.Canceled)
                    {
                        var cancellation = VoiceProfileEnrollmentCancellationDetails.FromResult(result);
                        Console.WriteLine($"CANCELED {profile.Id}: ErrorCode={cancellation.ErrorCode}");
                        Console.WriteLine($"CANCELED {profile.Id}: ErrorDetails={cancellation.ErrorDetails}");
                    }
                    Console.WriteLine($"Summation of pure speech across all enrollments in seconds is {result.EnrollmentsSpeechLength.TotalSeconds}.");
                    Console.WriteLine($"The remaining enrollments speech length in seconds is {result.RemainingEnrollmentsSpeechLength?.TotalSeconds}.");
                    reason = result.Reason;
                }
            }
        }
Ejemplo n.º 2
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}");
                        }
                    }
                }
        }
Ejemplo n.º 3
0
        // perform speaker verification.
        public static async Task SpeakerVerificationAsync()
        {
            // Replace with your own subscription key and service region (e.g., "westus").
            string subscriptionKey = "YourSubscriptionKey";
            string region          = "YourServiceRegion";

            // Creates an instance of a speech config with specified subscription key and service region.
            var config = SpeechConfig.FromSubscription(subscriptionKey, region);

            // Creates a VoiceProfileClient to enroll your voice profile.
            using (var client = new VoiceProfileClient(config))
                // Creates a text dependent voice profile in one of the supported locales using the client.
                using (var profile = await client.CreateProfileAsync(VoiceProfileType.TextDependentVerification, "en-us"))
                {
                    try
                    {
                        Console.WriteLine($"Created a profile {profile.Id} for text dependent verification.");
                        string[] trainingFiles = new string[]
                        {
                            @"MyVoiceIsMyPassportVerifyMe01.wav",
                            @"MyVoiceIsMyPassportVerifyMe02.wav",
                            @"MyVoiceIsMyPassportVerifyMe03.wav"
                        };

                        // feed each training file to the enrollment service.
                        foreach (var trainingFile in trainingFiles)
                        {
                            // Create audio input for enrollment from audio file. Replace with your own audio files.
                            using (var audioInput = AudioConfig.FromWavFileInput(trainingFile))
                            {
                                var result = await client.EnrollProfileAsync(profile, audioInput);

                                if (result.Reason == ResultReason.EnrollingVoiceProfile)
                                {
                                    Console.WriteLine($"Enrolling profile id {profile.Id}.");
                                }
                                else if (result.Reason == ResultReason.EnrolledVoiceProfile)
                                {
                                    Console.WriteLine($"Enrolled profile id {profile.Id}.");
                                    await VerifySpeakerAsync(config, profile);
                                }
                                else if (result.Reason == ResultReason.Canceled)
                                {
                                    var cancellation = VoiceProfileEnrollmentCancellationDetails.FromResult(result);
                                    Console.WriteLine($"CANCELED {profile.Id}: ErrorCode={cancellation.ErrorCode}");
                                    Console.WriteLine($"CANCELED {profile.Id}: ErrorDetails={cancellation.ErrorDetails}");
                                }

                                Console.WriteLine($"Number of enrollment audios accepted for {profile.Id} is {result.EnrollmentsCount}.");
                                Console.WriteLine($"Number of enrollment audios needed to complete { profile.Id} is {result.RemainingEnrollmentsCount}.");
                            }
                        }
                    }
                    finally
                    {
                        await client.DeleteProfileAsync(profile);
                    }
                }
        }
Ejemplo n.º 4
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);
            }
        }