Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

ArgumentException boundary #99

Open
tsoumalis opened this issue Jul 6, 2017 · 1 comment
Open

ArgumentException boundary #99

tsoumalis opened this issue Jul 6, 2017 · 1 comment

Comments

@tsoumalis
Copy link

tsoumalis commented Jul 6, 2017

I am using the SpeakerRecognition API with the Nuget package Microsoft.ProjectOxford.SpeakerRecognition.

When I call the EnrollAsync method, passing a Stream with data from a wav file and a GUID of a user, I get an ArgumentException boundary. I use Xamarin.Android (Target Framework 7.0). This is from the Application Output:
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: boundary

With no more further details.

The code I use is:
await client.EnrollAsync(stream, profile);

Where stream is a MemoryStream with the file data and profile the GUID of my profile. The wav file that I generate is valid and according to the guidelines of the documentation.

@tsoumalis tsoumalis reopened this Jul 6, 2017
@I1Artemov
Copy link

I've figured out how to solve this. You shold add this method to your code:

public async Task<Enrollment> EnrollAsyncRedone( Stream audioStream, Guid id ) {
            try {
                // Initialization and preparation stuff
                string _BASE_URI = "https://api.projectoxford.ai/spid/v1.0/verificationProfiles";
                string _JSON_HEADER = "application/json";
                string _OCP_SUBSCRIPTION_KEY_HEADER = "Ocp-Apim-Subscription-Key";
                HttpClient _DefaultHttpClient = new HttpClient();
                _DefaultHttpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( _JSON_HEADER ) );
                // Don't forget to change "yourAPIkeyString" to your actual API key!
                _DefaultHttpClient.DefaultRequestHeaders.Add( _OCP_SUBSCRIPTION_KEY_HEADER, yourAPIkeyString );

                // This line caused the exception:
                //var content = new MultipartFormDataContent( "Upload----" + DateTime.Now.ToString( "u" ) );
                // Now it is changed to this (no arguments in braces => correct boundaries generation)
                var content = new MultipartFormDataContent(  );
                content.Add( new StreamContent( audioStream ), "enrollmentData", id.ToString( "D" ) + "_" + DateTime.Now.ToString( "u" ) );

                var requestUrl = _BASE_URI + "/" + id.ToString( "D" ) + "/enroll";
                var result = await _DefaultHttpClient.PostAsync( requestUrl, content ).ConfigureAwait( false );
                string resultStr = await result.Content.ReadAsStringAsync().ConfigureAwait( false );

                if (result.StatusCode == HttpStatusCode.OK) {
                    //parse response
                    Enrollment response = JsonConvert.DeserializeObject<Enrollment>( resultStr );
                    return response;
                } else {
                    throw new EnrollmentException( resultStr );
                }
            } catch (TaskCanceledException exception) {
                throw new TimeoutException( "Connection timed out: " + exception.Message );
            }
        }

And then you should call EnrollAsyncRedone(stream, profile); instead of client.EnrollAsync(stream, profile); - so the error will disappear. I've got EnrollAsync's source code from here: https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/SpeakerRecognition/Windows/ClientLibrary/SpeakerVerificationServiceClient.cs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants