private async Task <(Transcription response, HttpStatusCode code)> CheckCognitiveServicesTranscriptionStatusAsync()
        {
            (Transcription response, HttpStatusCode code) = await _cogsClient.CheckTranscriptionRequestAsync(new Uri(transcriptionRequest.BlobUri));

            await _serviceClient.PublishNotification(transcriptionRequest.TranscriptionId.ToString(), response.Status);

            return(response, code);
        }
Example #2
0
        public async Task <ActionResult> Transcribe(TradiureTranscriptionRequest request, CancellationToken cancellationToken)
        {
            try
            {
                _logger.LogInformation($"{request.TranscriptionId}. {request.BlobUri} was successfullly received by Dapr PubSub");
                (Transcription response, HttpStatusCode code) = await _cogsClient.SubmitTranscriptionRequestAsync(new Uri(request.BlobUri));

                await _serviceClient.PublishNotification(request.TranscriptionId.ToString(), response.Status);

                return(code switch
                {
                    HttpStatusCode.Created => await HandleSuccess(response.Self, request.TranscriptionId),
                    _ => await HandleFailure(response.Self, request.TranscriptionId),
                });
            }
        public async Task <ActionResult> Transcribe(TradiureTranscriptionRequest request, CancellationToken cancellationToken)
        {
            try
            {
                _logger.LogInformation($"{request.TranscriptionId}. {request.BlobUri} was successfullly received by Dapr PubSub");
                state = await _client.GetStateEntryAsync <TraduireTranscription>(Components.StateStoreName, request.TranscriptionId.ToString());

                state.Value ??= new TraduireTranscription();

                (TranscriptionResults result, HttpStatusCode code) = await _cogsClient.DownloadTranscriptionResultAsync(new Uri(request.BlobUri));

                switch (code)
                {
                case HttpStatusCode.OK:
                    _logger.LogInformation($"{request.TranscriptionId}. Transcription from '{request.BlobUri}' was saved to state store ");
                    var firstChannel = result.CombinedRecognizedPhrases.FirstOrDefault();

                    await _serviceClient.PublishNotification(request.TranscriptionId.ToString(), state.Value.Status.ToString());
                    await UpdateStateRepository(TraduireTranscriptionStatus.Completed, firstChannel.Display);

                    _logger.LogInformation($"{request.TranscriptionId}. All working completed on request");
                    return(Ok(request.TranscriptionId));

                default:
                    _logger.LogInformation($"{request.TranscriptionId}. Transcription Failed for an unexpected reason. Added to Failed Queue for review");
                    var failedEvent = await UpdateStateRepository(TraduireTranscriptionStatus.Failed, code, request.BlobUri);

                    await _client.PublishEventAsync(Components.PubSubName, Topics.TranscriptionFailedTopicName, failedEvent, cancellationToken);

                    break;
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Nuts. Something really bad happened processing {request.BlobUri} - {ex.Message}");
            }

            return(BadRequest());
        }