internal static Task ReadResponseStream(AsyncDuplexStreamingCall <StreamingRequest, StreamingResponse> grpcCall)
        {
            return(Task.Factory.StartNew(async() =>
            {
                ILogger log = Log.Logger;
                log.Information("Started new ResponseStream reading task");
                try
                {
                    //  grpcCall.ResponseStream.MoveNext().Wait();
                    await foreach (var response in grpcCall.ResponseStream.ReadAllAsync())
                    {
                        ChunkRecievedEventArgs evt = new ChunkRecievedEventArgs(response);
                        ChunkRecived?.Invoke(null, evt);

                        log.Information($"{response.EventCase} chunk of {response.CalculateSize()} bytes recieved in {response.ResponseWallTimeMs}");

                        if (response.EventCase == StreamingResponse.EventOneofCase.StatusCode && response.StatusCode.CodeType == CodeType.Closed)
                        {
                            log.Information($"Call compleated");
                            Client.cancelSource.Cancel();
                            return;
                        }
                    }
                }
                catch (RpcException ex) when(ex.StatusCode == Grpc.Core.StatusCode.DeadlineExceeded)
                {
                    // Check for details https://cloud.yandex.com/docs/speechkit/stt/streaming#session-restrictions
                    log.Information($"Session limit riched {ex.Message}  with status {ex.Status} code {ex.StatusCode}");
                }
                catch (RpcException ex)
                {
                    log.Error($"ResponseStream err {ex.Message}  with status {ex.Status} code {ex.StatusCode}");
                }
                catch (Exception ex) {
                    log.Error($"Error during read {ex.Message}");
                }
            }));
        }
Exemple #2
0
        private const int MAX_BYTES_SENT = 32 * 1024; // check https://cloud.yandex.com/docs/speechkit/stt/streaming#session-restrictions for limitation details


        private void _readTask_SpeechToTextResultsRecived(object sender, ChunkRecievedEventArgs e)
        {
            SpeechToTextResultsRecived?.Invoke(sender, e);
        }