internal static Task ReadResponseStream(AsyncDuplexStreamingCall <StreamingRecognitionRequest, StreamingRecognitionResponse> grpcCall) { return(Task.Factory.StartNew(async() => { ILogger log = Log.Logger; log.Information("Started new ResponseStream reading task"); try { await foreach (var response in grpcCall.ResponseStream.ReadAllAsync()) { log.Information($"s2t chunk of {response.CalculateSize()} bytes recieved "); foreach (SpeechRecognitionChunk chunk in response.Chunks) { ChunkRecievedEventArgs evt = new ChunkRecievedEventArgs(chunk); ChunkRecived?.Invoke(null, evt); } } } catch (RpcException ex) when(ex.StatusCode == 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}"); } })); }
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}"); } })); }