/// <summary>
        ///     Identify a stream of audio
        /// </summary>
        /// <param name="stream">Audio buffer to be recognized</param>
        /// <param name="serviceClient">Client used in identifying the streamed audio wave</param>
        /// <param name="clientId">Client ID</param>
        /// <param name="requestId">Request ID</param>
        public async Task IdentifyStreamAsync(Stream stream, SpeakerIdentificationServiceClient serviceClient,
                                              Guid clientId, int requestId)
        {
            try
            {
                OperationLocation processPollingLocation = await serviceClient.IdentifyAsync(stream, _speakerIds, true).ConfigureAwait(false);

                var numberOfPollingRetries = 3;
                while (numberOfPollingRetries > 0)
                {
                    await Task.Delay(TimeSpan.FromSeconds(TimeSpanBetweenPollingRetries));

                    IdentificationOperation identificationResponse = await serviceClient.CheckIdentificationStatusAsync(processPollingLocation);

                    if (identificationResponse.Status == Status.Succeeded)
                    {
                        var result = new RecognitionResult(identificationResponse.ProcessingResult, clientId,
                                                           requestId);
                        _resultCallback(result);
                        break;
                    }

                    if (identificationResponse.Status == Status.Failed)
                    {
                        var failureResult = new RecognitionResult(false, identificationResponse.Message, requestId);

                        _resultCallback(failureResult);
                        return;
                    }

                    numberOfPollingRetries--;
                }


                if (numberOfPollingRetries <= 0)
                {
                    var failureResult = new RecognitionResult(false, "Request timeout.", requestId);
                    _resultCallback(failureResult);
                }
            }
            catch (Exception ex)
            {
                var result = new RecognitionResult(false, ex.Message, requestId);
                _resultCallback(result);
            }
        }
Exemplo n.º 2
0
        private static string GetSpeakerName(RecognitionResult currentResult)
        {
            var person = "Unknown";
            var s      = currentResult.Value.IdentifiedProfileId.ToString();

            if (s.Contains("1aef1c90-8936-49ed-aaf0-0b4843f5f95b"))
            {
                person = "Judith";
            }
            else if (s.Contains("5d68a5aa-4426-4c4b-b8f9-2de573492dcb"))
            {
                person = "Leo";
            }
            else if (s.Contains("7af47c2c-7165-4cbc-997a-b3f8fc5bbbbb"))
            {
                person = "Meeting Messenger Bot";
            }

            return(person);
        }
Exemplo n.º 3
0
        private void WriteResults(RecognitionResult recognitionResult)
        {
            _recognitionResults.Add(recognitionResult);
            if (!recognitionResult.Succeeded)
            {
                WriteLine("Request " + recognitionResult.RequestId + " error message: " +
                          recognitionResult.FailureMsg);
                return;
            }

            var identificationResult = recognitionResult.Value;

            WriteLine(identificationResult.IdentifiedProfileId == Guid.Empty
                ? "Unknown"
                : identificationResult.IdentifiedProfileId.ToString());
            WriteLine(identificationResult.Confidence.ToString());
            WriteLine(recognitionResult.RequestId.ToString());
            var result = identificationResult.IdentifiedProfileId == Guid.Empty
                ? "Unknown"
                : identificationResult.IdentifiedProfileId.ToString();

            WriteLine("Request " + recognitionResult.RequestId + ": Profile id: " + result);
        }