Exemplo 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;
                }
            }
        }
Exemplo n.º 2
0
        public static async Task SpeakerVerify(SpeechConfig config, VoiceProfile profile, Dictionary <string, string> profileMapping)
        {
            var speakerRecognizer = new SpeakerRecognizer(config, AudioConfig.FromDefaultMicrophoneInput());
            var model             = SpeakerVerificationModel.FromProfile(profile);

            Console.WriteLine("Speak the passphrase to verify: \"My voice is my passport, please verify me.\"");
            var result = await speakerRecognizer.RecognizeOnceAsync(model);

            Console.WriteLine($"Verified voice profile for speaker {profileMapping[result.ProfileId]}, score is {result.Score}");
        }
Exemplo n.º 3
0
        // helper function for speaker verification.
        public static async Task VerifySpeakerAsync(SpeechConfig config, VoiceProfile profile)
        {
            var speakerRecognizer = new SpeakerRecognizer(config, AudioConfig.FromWavFileInput(@"myVoiceIsMyPassportVerifyMe04.wav"));
            var model             = SpeakerVerificationModel.FromProfile(profile);
            var result            = await speakerRecognizer.RecognizeOnceAsync(model);

            if (result.Reason == ResultReason.RecognizedSpeaker)
            {
                Console.WriteLine($"Verified voice profile {result.ProfileId}, score is {result.Score}");
            }
            else if (result.Reason == ResultReason.Canceled)
            {
                var cancellation = SpeakerRecognitionCancellationDetails.FromResult(result);
                Console.WriteLine($"CANCELED {profile.Id}: ErrorCode={cancellation.ErrorCode}");
                Console.WriteLine($"CANCELED {profile.Id}: ErrorDetails={cancellation.ErrorDetails}");
            }
        }
Exemplo n.º 4
0
        public static async Task SpeakerVerify(SpeechConfig config, VoiceProfile profile, Dictionary <string, string> profileMapping, string file)
        {
            var model = SpeakerVerificationModel.FromProfile(profile);

            Console.WriteLine($"Veryifying {file} ...");
            try
            {
                var speakerRecognizer = new SpeakerRecognizer(config, AudioConfig.FromWavFileInput(file));
                var result            = await speakerRecognizer.RecognizeOnceAsync(model);

                Console.WriteLine($"Verified voice profile for speaker {profileMapping[result.ProfileId]}, score is {result.Score}");
                if (result.Score >= 0.5)
                {
                    File.Copy(file, Path.Combine(settings[SettingIndex.ResDir], Path.GetFileName(file)), true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught: " + ex.Message);
            }
        }
        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);
            }
        }