diff --git a/src/Custom/RealtimeConversation/RealtimeConversationSession.cs b/src/Custom/RealtimeConversation/RealtimeConversationSession.cs index 960f817e..6ce50e2a 100644 --- a/src/Custom/RealtimeConversation/RealtimeConversationSession.cs +++ b/src/Custom/RealtimeConversation/RealtimeConversationSession.cs @@ -138,10 +138,20 @@ public virtual async Task SendInputAudioAsync(BinaryData audio, CancellationToke } _isSendingAudio = true; } - // TODO: consider automatically limiting/breaking size of chunk (as with streaming) - InternalRealtimeClientEventInputAudioBufferAppend internalCommand = new(audio); - BinaryData requestData = ModelReaderWriter.Write(internalCommand); - await SendCommandAsync(requestData, cancellationToken.ToRequestOptions()).ConfigureAwait(false); + try + { + // TODO: consider automatically limiting/breaking size of chunk (as with streaming) + InternalRealtimeClientEventInputAudioBufferAppend internalCommand = new(audio); + BinaryData requestData = ModelReaderWriter.Write(internalCommand); + await SendCommandAsync(requestData, cancellationToken.ToRequestOptions()).ConfigureAwait(false); + } + finally + { + lock (_sendingAudioLock) + { + _isSendingAudio = false; + } + } } /// @@ -162,10 +172,20 @@ public virtual void SendInputAudio(BinaryData audio, CancellationToken cancellat } _isSendingAudio = true; } - // TODO: consider automatically limiting/breaking size of chunk (as with streaming) - InternalRealtimeClientEventInputAudioBufferAppend internalCommand = new(audio); - BinaryData requestData = ModelReaderWriter.Write(internalCommand); - SendCommand(requestData, cancellationToken.ToRequestOptions()); + try + { + // TODO: consider automatically limiting/breaking size of chunk (as with streaming) + InternalRealtimeClientEventInputAudioBufferAppend internalCommand = new(audio); + BinaryData requestData = ModelReaderWriter.Write(internalCommand); + SendCommand(requestData, cancellationToken.ToRequestOptions()); + } + finally + { + lock (_sendingAudioLock) + { + _isSendingAudio = false; + } + } } public virtual async Task ClearInputAudioAsync(CancellationToken cancellationToken = default)