/// <summary>Snippet for StreamCall</summary> public async Task StreamCall() { // Snippet: StreamCall(CallSettings, BidirectionalStreamingSettings) // Create client StreamsClient streamsClient = StreamsClient.Create(); // Initialize streaming call, retrieving the stream object StreamsClient.StreamCallStream response = streamsClient.StreamCall(); // Sending requests and retrieving responses can be arbitrarily interleaved // Exact sequence will depend on client/server behavior // Create task to do something with responses from server Task responseHandlerTask = Task.Run(async() => { // Note that C# 8 code can use await foreach AsyncResponseStream <StreamCallResponse> responseStream = response.GetResponseStream(); while (await responseStream.MoveNextAsync()) { StreamCallResponse responseItem = responseStream.Current; // Do something with streamed response } // The response stream has completed }); // Send requests to the server bool done = false; while (!done) { // Initialize a request StreamCallRequest request = new StreamCallRequest { Setup = new StreamSetup(), InputAudio = new InputAudio(), UpdateRequestParameters = new UpdateRequestParameters(), }; // Stream a request to the server await response.WriteAsync(request); // Set "done" to true when sending requests is complete } // Complete writing requests to the stream await response.WriteCompleteAsync(); // Await the response handler // This will complete once all server responses have been processed await responseHandlerTask; // End snippet }