コード例 #1
0
ファイル: Program.cs プロジェクト: vaclavek/CloudDevelopment
        // 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}");
            }
        }
コード例 #2
0
        private async Task RecognizeFromSourceAsync(SourceType sourceType, StorageFile file = null)
        {
            try
            {
                ProcessState = ProcessState.Processing;
                ToggleUI(isProcessing: true);

                // get all identification profiles based on current speakerRecognitionService
                SpeakerProfilesResponse userProfileResponse = await this.userProvidedSpeakerRecognitionService.GetProfilesAsync(VoiceProfileType.TextIndependentIdentification);

                List <SpeakerRecognitionViewModel> userIdentificationProfiles = userProfileResponse != null?Models.Where(m => userProfileResponse.Profiles.Select(p => p.ProfileId).Contains(m.IdentificationProfileId)).ToList() : new List <SpeakerRecognitionViewModel>();

                // recognize
                SpeakerRecognitionResult userResult = null;
                using (AudioConfig audioInput = sourceType == SourceType.FromFile ? AudioConfig.FromWavFileInput(file.Path) : AudioConfig.FromDefaultMicrophoneInput())
                {
                    userResult = await RecognizeAsync(userProvidedSpeechConfig, audioInput, userIdentificationProfiles);
                }

                // display result
                if (userResult == null || userResult.Reason == ResultReason.Canceled)
                {
                    ProcessState = ProcessState.Error;
                    var cancellation = SpeakerRecognitionCancellationDetails.FromResult(userResult);
                    await ShowMessage("Speaker Identification Error", $"CANCELED: ErrorCode={cancellation.ErrorCode} ErrorDetails={cancellation.ErrorDetails}");
                }
                else
                {
                    ProcessState = ProcessState.Completed;
                    double score = userResult?.Score ?? 0;
                    this.detectedVoice.Text = userResult != null?userIdentificationProfiles.FirstOrDefault(m => string.Equals(m.IdentificationProfileId, userResult.ProfileId, StringComparison.OrdinalIgnoreCase))?.Name : string.Empty;

                    this.detectedVoiceProbability.Text = $"({Math.Round(score * 100)}%)";
                }
            }
            catch (Exception ex)
            {
                ProcessState = ProcessState.Error;
                await Util.GenericApiCallExceptionHandler(ex, "Speaker recognition error");
            }
            finally
            {
                ToggleUI(isProcessing: false);
            }
        }