Coder Social home page Coder Social logo

Comments (1)

I1Artemov avatar I1Artemov commented on September 28, 2024

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

from projectoxford-clientsdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.