认知服务说话人识别问题

问题描述

我是 ms Azure 的新手,但我完成了以下任务,即使用 Azure 认知服务说话人识别来确认说话人与已知或注册的声音相匹配。微软网站上有一篇关于如何使用语音服务的示例的文章,但是当我运行该示例时,它会在 SpeakerVerify 函数上停止,并且无法处理相似度得分结果(结果 = await SpeakerRecognizer.RecognizeOnceAsync (model)) .一切都与 Azure 同步。请帮我弄清楚是什么问题。提前致谢。

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;

namespace YMM7
{
    public class Program
    {

        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.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.RemainingEnrollmentsspeechLength > TimeSpan.Zero)
                    {
                        Console.WriteLine("Continue speaking to add to the profile enrollment sample.");
                        result = await client.EnrollProfileAsync(profile,audioInput);
                        Console.WriteLine($"Remaining enrollment audio time needed: {result.RemainingEnrollmentsspeechLength}");
                        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}");
                    }
                }
            }
        }
        public static async Task SpeakerVerify(SpeechConfig config,VoiceProfile profile,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,verify me.\"");
           
            var result = await speakerRecognizer.RecognizeOnceAsync(model);
            
            Console.WriteLine($"Verified voice profile for speaker {profileMapping[result.ProfileId]},score is {result.score}");
        }
        static async Task Main(string[] args)
        {
            // replace with your own subscription key 
            string subscriptionKey = "1234567890";
            string region = "westus";
            var config = SpeechConfig.FromSubscription(subscriptionKey,region); 


            var profileMapping = new Dictionary<string,string>();
            await VerificationEnroll(config,profileMapping);

            Console.ReadLine();
        }

    }

}

Error screenshot

解决方法

抱歉,我没有重现您的错误。

我测试了官方文档中的代码,效果很好。 enter image description here 而且我还修改了您的代码,该代码停留在这一部分: enter image description here

我发现唯一不同的是我们使用 result.RemainingEnrollmentsCount,而您使用 result.RemainingEnrollmentsSpeechLength

尝试使用官方文档中的代码:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;

namespace SpeakerRecog
{
    public class Program
    {

        public static 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())
                //using (var audioInput = AudioConfig.FromWavFileInput("myVoiceIsMyPassportVerifyMe01.wav"))
                {
                    Console.WriteLine($"Enrolling profile id {profile.Id}.");
                    // give the profile a human-readable display name
                    profileMapping.Add(profile.Id,"Doris");

                    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}");
                    }
                }
            }
        }

        public static async Task SpeakerVerify(SpeechConfig config,VoiceProfile profile,string> profileMapping)
        {
            var speakerRecognizer = new SpeakerRecognizer(config,AudioConfig.FromDefaultMicrophoneInput());
            //var speakerRecognizer = new SpeakerRecognizer(config,AudioConfig.FromWavFileInput("d:/MyRepository/file/myVoiceIsMyPassportVerifyMe02.wav"));
            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}");
        }

        static async Task Main(string[] args)
        {
            // replace with your own subscription key 
            string subscriptionKey = "subscriptionKey";
            string region = "westus";
            var config = SpeechConfig.FromSubscription(subscriptionKey,region);

            // persist profileMapping if you want to store a record of who the profile is
            var profileMapping = new Dictionary<string,string>();
            await VerificationEnroll(config,profileMapping);

            Console.ReadLine();
        }
    }
}