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
24
24
import io.ktor.websocket.Frame
25
25
import io.ktor.websocket.close
26
26
import io.ktor.websocket.readBytes
27
+ import java.io.ByteArrayOutputStream
27
28
import java.util.concurrent.ConcurrentLinkedQueue
28
29
import kotlin.coroutines.CoroutineContext
29
30
import kotlinx.coroutines.CoroutineScope
@@ -141,16 +142,14 @@ internal constructor(
141
142
}
142
143
143
144
private suspend fun sendAudioDataToServer () {
144
- var offset = 0
145
- val audioBuffer = ByteArray ( MIN_BUFFER_SIZE * 2 )
145
+
146
+ val audioBufferStream = ByteArrayOutputStream ( )
146
147
while (isRecording) {
147
148
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()
154
153
}
155
154
}
156
155
}
You can’t perform that action at this time.
0 commit comments