Cognitive-services-speech-sdk: Exception with an error code: 0x5 (SPXERR_INVALID_ARG) or 0x21 (SPXERR_INVALID_HANDLE) when trying to Enroll a VoiceProfile for Speaker Identification

Created on 23 Jul 2020  路  10Comments  路  Source: Azure-Samples/cognitive-services-speech-sdk

Hi I'm getting the following errors when trying to Enroll a voice profile for speaker identification and the error changes between versions 1.12.1. and 1.13.0

The profile has been checked and is an Identification profile , and exists.

The error occurs when i call
result = await client.EnrollProfileAsync(profile, audioConfig);

I am trying to create the profile, then enroll later...
When i create a voiceprofile to pass into the enrollment like this

var profile = new VoiceProfile(profileId)

..rather than creating one with the client seems to be triggering the error. , Does the Enrollment need the profile creating just before? I cannot see a client method for retrieving a created voiceprofile.

Expected behaviour
Enrollment occurs or a more meaningful error message is displayed

Environment
Using the windows version of SDK
OS: windows 10 Version 10.0.18363 Build 18363
Programming language: C# in a project targeting netstandard2.0
Tried enrolling using microphone and wav files and get the same errors.
App: Winforms

Version: Microsoft.CognitiveServices.Speech SDK 1.12.1

Error
Exception with an error code: 0x5 (SPXERR_INVALID_ARG)
Source
Microsoft.CognitiveServices.Speech.csharp

Stack trace
at Microsoft.CognitiveServices.Speech.Internal.SpxExceptionThrower.ThrowIfFail(IntPtr hr)
at Microsoft.CognitiveServices.Speech.Internal.SpxFactory.GetDataFromHandleUsingDelegate(GetResultDelegate functionPtr, InteropSafeHandle handle, Int32 maxCharCount)
at Microsoft.CognitiveServices.Speech.VoiceProfileEnrollmentResult..ctor(IntPtr resultHandlePtr)
at Microsoft.CognitiveServices.Speech.VoiceProfileClient.<>c__DisplayClass6_0.b__0(InteropSafeHandle h)
at Microsoft.CognitiveServices.Speech.VoiceProfileClient.<>c__DisplayClass10_01.b__0() at System.Threading.Tasks.Task1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Ossa.VoiceIdentification.Common.SpeechWrapper.d__19.MoveNext() in C:\Projects\VoiceIdentification\src\Ossa.VoiceIdentification.Common\SpeechWrapper.cs:line 269
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Ossa.VoiceIdentification.WindowsClient.Form1.d__19.MoveNext() in C:\Projects\VoiceIdentification\src\Ossa.VoiceIdentification.WindowsClient\Form1.cs:line 181
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

If I update to Version: Microsoft.CognitiveServices.Speech SDK 1.13.0 I get the following error

'Exception with an error code: 0x21 (SPXERR_INVALID_HANDLE)'

  at Microsoft.CognitiveServices.Speech.Internal.SpxExceptionThrower.ThrowIfFail(IntPtr hr)

at Microsoft.CognitiveServices.Speech.Internal.SpxFactory.GetDataFromHandleUsingDelegate(GetResultDelegate functionPtr, InteropSafeHandle handle, Int32 maxCharCount)
at Microsoft.CognitiveServices.Speech.VoiceProfileEnrollmentResult..ctor(IntPtr resultHandlePtr)
at Microsoft.CognitiveServices.Speech.VoiceProfileClient.<>c__DisplayClass6_0.b__0(InteropSafeHandle h)
at Microsoft.CognitiveServices.Speech.VoiceProfileClient.<>c__DisplayClass10_01.<RunAsync>b__0() at System.Threading.Tasks.Task1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Ossa.VoiceIdentification.Common.SpeechWrapper.d__18.MoveNext() in C:\Projects\VoiceIdentification\src\Ossa.VoiceIdentification.Common\SpeechWrapper.cs:line 243
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Ossa.VoiceIdentification.WindowsClient.Form1.d__15.MoveNext() in C:\Projects\VoiceIdentification\src\Ossa.VoiceIdentification.WindowsClient\Form1.cs:line 127

bug

Most helpful comment

in approximately 3-4 weeks.

All 10 comments

Sorry you hit this...

There's some information missing that enrollment currently needs, and that there isn't an API to provide when creating a VoiceProfile from an ID alone.

I've put a bug in our internal tracking system to address this.

@rhurey how do we verify the voice later? I am trying to create VoiceProfile("profile guid id") and then use the following code to verify the voice-

var profile = new VoiceProfile("profile guid id");
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);

The above fails with the error "Exception with an error code: 0x21 (SPXERR_INVALID_HANDLE)'", does this mean we cannot verify voice unless we create and enroll profile at the same time? When I use the VoiceProfile object created by VoiceProfileClient the above code just works. I thought all our client needed was just a profile id for posting a voice audio for verification against it.

Hello Suneetnangia,

Your above statement is correct. You would have to keep the voice profile you created from VoiceProfileClient::CreateProfileAsync in order to do verification or identification at the moment.

For the time being, to workaround the issue, you can use the REST API directly. For text-dependent verification, do a HTTP POST like below:
POST {Endpoint}/speaker/verification/v2.0/text-dependent/profiles/{profileId}/verify
where, Endpoint for the time being is https://westus.api.cognitive.microsoft.com/, and profileId is the GUID id you have.

You can try the REST API at here.

Sorry for the inconvenience. This is will be addressed in our next release.

Thanks for confirming that I wasn't going mad.
I tried the REST API and have another issue which is, when I post a wav file's base64 string data to the service it return-
{
"error": {
"code": "InvalidRequest",
"message": "Audio is too noisy."
}
}
when I use the same wav file via SDK for verification it returns me the score correctly? Are you doing any processing of wav file in the SDK when we use AudioConfig.FromWavFileInput?
Also, are you going to have SDK following the new standards i.e. using Azure.Core and open source it?
Cheers.

The service needs raw PCM data. I have not done any processing other than just sending the raw PCM data. Could it due to the "base64 string data"? I had luck with curl doing HTTP POST to the speaker id service before.

We have "open source" on our road map. I can see open source will be helpful in your case.

The service needs raw PCM data. I have not done any processing other than just sending the raw PCM data. Could it due to the "base64 string data"? I had luck with curl doing HTTP POST to the speaker id service before.

We have "open source" on our road map. I can see open source will be helpful in your case.

Thanks. sending binary data directly worked. Would be nice to have a better error message if data is sent as base64string to reflect the issue.

To update, work is now ongoing to add an API that enables creating a VoiceProfile from an ID alone. This is planned for the next Speech SDK release (1.14.0).

Closing this item, please open a new issue if you need further support.

Hi Azure Speaker Recognition team, when are you planning to release the next version (1.14.0) with these fixes?

in approximately 3-4 weeks.

The fixes is in the latest release of SDK. The latest version is 1.15.

Was this page helpful?
0 / 5 - 0 ratings