File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed
firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import io.ktor.client.plugins.websocket.ClientWebSocketSession
2424import io.ktor.websocket.Frame
2525import io.ktor.websocket.close
2626import io.ktor.websocket.readBytes
27+ import java.io.ByteArrayOutputStream
2728import java.util.concurrent.ConcurrentLinkedQueue
2829import kotlin.coroutines.CoroutineContext
2930import kotlinx.coroutines.CoroutineScope
@@ -141,16 +142,14 @@ internal constructor(
141142 }
142143
143144 private suspend fun sendAudioDataToServer () {
144- var offset = 0
145- val audioBuffer = ByteArray ( MIN_BUFFER_SIZE * 2 )
145+
146+ val audioBufferStream = ByteArrayOutputStream ( )
146147 while (isRecording) {
147148 val receivedAudio = audioQueue.poll() ? : continue
148- receivedAudio.copyInto(audioBuffer, offset)
149- offset + = receivedAudio.size
150- if (offset >= MIN_BUFFER_SIZE ) {
151- sendMediaStream(listOf (MediaData (audioBuffer, " audio/pcm" )))
152- audioBuffer.fill(0 )
153- offset = 0
149+ audioBufferStream.write(receivedAudio)
150+ if (audioBufferStream.size() >= MIN_BUFFER_SIZE ) {
151+ sendMediaStream(listOf (MediaData (audioBufferStream.toByteArray(), " audio/pcm" )))
152+ audioBufferStream.reset()
154153 }
155154 }
156155 }
You can’t perform that action at this time.
0 commit comments