private void WriteAudio(byte[] audioData)
 {
     try
     {
         AsyncDuplexStreamingCall <StreamingRecognitionRequest, StreamingRecognitionResponse> call = this.ActiveCall();
         StreamingRecognitionRequest rR = new StreamingRecognitionRequest();
         rR.AudioContent = Google.Protobuf.ByteString.CopyFrom(audioData);
         call.RequestStream.WriteAsync(rR).Wait();
     }
     catch (RpcException ex)     //when (ex.StatusCode == StatusCode.DeadlineExceeded)
     {
         Log.Error($"during data sent error: {ex.Message}  with status {ex.Status} code {ex.StatusCode}");
         throw ex;
     }
 }
        private const int MAX_BYTES_SENT = 10 * 1024 * 1024; // check https://cloud.yandex.com/docs/speechkit/stt/streaming#session-restrictions for limitation details

        private AsyncDuplexStreamingCall <StreamingRecognitionRequest, StreamingRecognitionResponse> ActiveCall()
        {
            if (this._call != null)
            {
                try
                {
                    Status status = this._call.GetStatus();
                    log.Information($"Call status: ${status.StatusCode} ${status.Detail}");

                    this._call.Dispose();
                    this._call = null;
                    if (this._readTask != null)
                    {
                        log.Information($"Call status: ${status.StatusCode} ${status.Detail}. Disposing.");
                        this._readTask.Dispose(); // Close read task
                    }
                    this._readTask = null;

                    // call is finished
                }
                catch (Exception ex)
                {
                    log.Information($"Call is in process - reuse. ${ex.Message}");
                    return(this._call);
                }
            }
            try
            {
                Log.Information($"Initialize gRPC call is finished");
                this._call = speechKitRpctClient.StreamingRecognize(
                    headers: this.MakeMetadata(),
                    deadline: DateTime.UtcNow.AddMinutes(5)); // check https://cloud.yandex.com/docs/speechkit/stt/streaming#session-restrictions for limitation details

                this.bytesSent = 0;                           // reset bytes counter
                StreamingRecognitionRequest rR = new StreamingRecognitionRequest();
                rR.Config = this.rConf;

                this._call.RequestStream.WriteAsync(rR).Wait();

                // Start reading task for call
                if (this._readTask == null)
                {
                    this._readTask = SpeechToTextResponseReader.ReadResponseStream(this._call);
                }

                return(this._call);
            }
            catch (RpcException ex) //when (ex.StatusCode == StatusCode.DeadlineExceeded)
            {
                Log.Warning($"gRPC request on create exception {ex.Message}  with status {ex.Status} code {ex.StatusCode}");
                // Maximum duration exeeded reestablish connection
                if (ex.StatusCode == StatusCode.DeadlineExceeded) //|| StatusCode=\"InvalidArgument\", Detail=\"audio should be less than 10MB\")"
                {
                    return(ActiveCall());
                }
                else
                {
                    throw ex;
                }
            }
            catch (Exception ex) //when (ex.StatusCode == StatusCode.DeadlineExceeded)
            {
                Log.Error($"during data sent exception {ex.Message} ");
                throw ex;
            }
        }