public async Task <IdentificationResponse> IdentifySpeaker(IdentifyProfile model)
        {
            var profiles = await GetProfiles();

            var identificationProfileIds = string.Join(",", profiles.Where(x => x.EnrollmentStatus != null && x.EnrollmentStatus.EnrollmentStatusEnrollmentStatus == "Enrolled").Select(x => x.Id));

            var url = $"{ Configuration["AudioAnalyticsAPI"] }identify?identificationProfileIds={ identificationProfileIds }";

            var key = Configuration["AudioAnalyticsKey"];

            using (var stream = model.Audio.OpenReadStream())
            {
                var response = await CognitiveServicesHttpClient.HttpPostAudio(stream, url, key);

                var responseBytes = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    var operationLocation = response.Headers.GetValues("Operation-Location").FirstOrDefault();

                    return(new IdentificationResponse {
                        OperationLocation = operationLocation
                    });
                }

                return(JSONHelper.FromJson <IdentificationResponse>(responseBytes));
            }
        }
예제 #2
0
        public async Task <JsonResult> IdentifySpeaker(IdentifyProfile model)
        {
            if (ModelState.IsValid)
            {
                var result = await AudioIdentificationService.IdentifySpeaker(model);

                return(new JsonResult(result));
            }

            return(new JsonResult(string.Empty));
        }
        public async Task <string> IdentifySpeaker(IdentifyProfile model)
        {
            var profiles = await GetEnrolledProfiles();

            var identificationProfileIds = string.Join(",", profiles.Select(x => x.Id));

            var url = $"{Configuration["AudioAnalyticsAPI"]}identify?identificationProfileIds={identificationProfileIds}";

            var key = Configuration["AudioAnalyticsKey"];

            using (var stream = model.Audio.OpenReadStream())
            {
                var response = await CognitiveServicesHttpClient.HttpPostAudio(stream, url, key);

                var responseBytes = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(response.Headers.GetValues("Operation-Location").FirstOrDefault());
                }

                throw new Exception($"Failed request : {responseBytes} ");
            }
        }