@@ -55,9 +55,9 @@ public virtual async Task SendInputAudioAsync(Stream audio, CancellationToken ca
5555 }
5656 _isSendingAudioStream = true ;
5757 }
58+ byte [ ] buffer = ArrayPool < byte > . Shared . Rent ( 1024 * 16 ) ;
5859 try
5960 {
60- byte [ ] buffer = ArrayPool < byte > . Shared . Rent ( 1024 * 16 ) ;
6161 while ( true )
6262 {
6363 int bytesRead = await audio . ReadAsync ( buffer , 0 , buffer . Length , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -75,6 +75,7 @@ public virtual async Task SendInputAudioAsync(Stream audio, CancellationToken ca
7575 }
7676 finally
7777 {
78+ ArrayPool < byte > . Shared . Return ( buffer ) ;
7879 using ( await _audioSendSemaphore . AutoReleaseWaitAsync ( cancellationToken ) . ConfigureAwait ( false ) )
7980 {
8081 _isSendingAudioStream = false ;
@@ -93,9 +94,9 @@ public virtual void SendInputAudio(Stream audio, CancellationToken cancellationT
9394 }
9495 _isSendingAudioStream = true ;
9596 }
97+ byte [ ] buffer = ArrayPool < byte > . Shared . Rent ( 1024 * 16 ) ;
9698 try
9799 {
98- byte [ ] buffer = ArrayPool < byte > . Shared . Rent ( 1024 * 16 ) ;
99100 while ( true )
100101 {
101102 int bytesRead = audio . Read ( buffer , 0 , buffer . Length ) ;
@@ -113,6 +114,7 @@ public virtual void SendInputAudio(Stream audio, CancellationToken cancellationT
113114 }
114115 finally
115116 {
117+ ArrayPool < byte > . Shared . Return ( buffer ) ;
116118 using ( _audioSendSemaphore . AutoReleaseWait ( cancellationToken ) )
117119 {
118120 _isSendingAudioStream = false ;
@@ -349,4 +351,4 @@ public void Dispose()
349351 {
350352 WebSocket ? . Dispose ( ) ;
351353 }
352- }
354+ }
0 commit comments