File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/util Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 17
17
package com.google.firebase.vertexai.common.util
18
18
19
19
import android.media.AudioRecord
20
+ import kotlinx.coroutines.delay
20
21
import kotlinx.coroutines.flow.flow
21
- import kotlinx.coroutines.yield
22
22
23
23
/* *
24
24
* The minimum buffer size for this instance.
@@ -31,14 +31,17 @@ internal val AudioRecord.minBufferSize: Int
31
31
/* *
32
32
* Reads from this [AudioRecord] and returns the data in a flow.
33
33
*
34
- * Will emit a zeroed out buffer when this instance is not recording.
34
+ * Will emit a zeroed out buffer every 100ms when this instance is not recording.
35
35
*/
36
36
internal fun AudioRecord.readAsFlow () = flow {
37
37
val buffer = ByteArray (minBufferSize)
38
+ val emptyBuffer = ByteArray (minBufferSize)
38
39
39
40
while (true ) {
40
41
if (recordingState != AudioRecord .RECORDSTATE_RECORDING ) {
41
- yield ()
42
+ emit(emptyBuffer)
43
+ // The model will close the connection if you spam it too fast
44
+ delay(100 )
42
45
continue
43
46
}
44
47
You can’t perform that action at this time.
0 commit comments