Skip to content

Commit 703177f

Browse files
committed
update
1 parent a9ba7a9 commit 703177f

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

firebase-ai/api.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,8 @@ package com.google.firebase.ai.type {
893893
method public suspend Object? send(String text, kotlin.coroutines.Continuation<? super kotlin.Unit>);
894894
method public suspend Object? sendFunctionResponse(java.util.List<com.google.firebase.ai.type.FunctionResponsePart> functionList, kotlin.coroutines.Continuation<? super kotlin.Unit>);
895895
method public suspend Object? sendMediaStream(java.util.List<com.google.firebase.ai.type.MediaData> mediaChunks, kotlin.coroutines.Continuation<? super kotlin.Unit>);
896-
method @RequiresPermission(android.Manifest.permission.RECORD_AUDIO) public suspend Object? startAudioConversation(kotlin.jvm.functions.Function1<? super com.google.firebase.ai.type.FunctionCallPart,com.google.firebase.ai.type.FunctionResponsePart>? functionCallHandler = null, Boolean? enableInterruptions = null, kotlin.coroutines.Continuation<? super kotlin.Unit>);
896+
method @RequiresPermission(android.Manifest.permission.RECORD_AUDIO) public suspend Object? startAudioConversation(kotlin.jvm.functions.Function1<? super com.google.firebase.ai.type.FunctionCallPart,com.google.firebase.ai.type.FunctionResponsePart>? functionCallHandler = null, boolean enableInterruptions = false, kotlin.coroutines.Continuation<? super kotlin.Unit>);
897+
method @RequiresPermission(android.Manifest.permission.RECORD_AUDIO) public suspend Object? startAudioConversation(kotlin.jvm.functions.Function1<? super com.google.firebase.ai.type.FunctionCallPart,com.google.firebase.ai.type.FunctionResponsePart>? functionCallHandler = null, kotlin.coroutines.Continuation<? super kotlin.Unit>);
897898
method public void stopAudioConversation();
898899
method public void stopReceiving();
899900
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/util/android.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.firebase.ai.common.util
1818

1919
import android.media.AudioRecord
20+
import kotlin.time.Duration.Companion.milliseconds
2021
import kotlinx.coroutines.delay
2122
import kotlinx.coroutines.flow.flow
2223
import kotlinx.coroutines.yield
@@ -39,7 +40,7 @@ internal fun AudioRecord.readAsFlow() = flow {
3940

4041
while (true) {
4142
if (recordingState != AudioRecord.RECORDSTATE_RECORDING) {
42-
delay(10)
43+
delay(10.milliseconds)
4344
yield()
4445
continue
4546
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/java/LiveSessionFutures.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ public abstract class LiveSessionFutures internal constructor() {
6363
* Starts an audio conversation with the model, which can only be stopped using
6464
* [stopAudioConversation] or [close].
6565
*
66-
* @param enableInterruptions Boolean to enable user to interrupt the model. Setting this variable
67-
* would allow the user to talk while the model is responding.
66+
* @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
67+
* ongoing reply.
6868
*
69-
* **WARNING**: User interruption might not work reliably across all devices.
69+
* **WARNING**: The user interruption feature relies on device-specific support, and may not be
70+
* consistently available.
7071
*/
7172
@RequiresPermission(RECORD_AUDIO)
7273
public abstract fun startAudioConversation(enableInterruptions: Boolean): ListenableFuture<Unit>
@@ -78,10 +79,11 @@ public abstract class LiveSessionFutures internal constructor() {
7879
* @param functionCallHandler A callback function that is invoked whenever the model receives a
7980
* function call.
8081
*
81-
* @param enableInterruptions Boolean to enable user to interrupt the model. Setting this variable
82-
* would allow the user to talk while the model is responding.
82+
* @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
83+
* ongoing reply.
8384
*
84-
* **WARNING**: User interruption might not work reliably across all devices.
85+
* **WARNING**: The user interruption feature relies on device-specific support, and may not be
86+
* consistently available.
8587
*/
8688
@RequiresPermission(RECORD_AUDIO)
8789
public abstract fun startAudioConversation(

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/LiveSession.kt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,32 @@ internal constructor(
9292
* @param functionCallHandler A callback function that is invoked whenever the model receives a
9393
* function call. The [FunctionResponsePart] that the callback function returns will be
9494
* automatically sent to the model.
95+
*/
96+
@RequiresPermission(RECORD_AUDIO)
97+
public suspend fun startAudioConversation(
98+
functionCallHandler: ((FunctionCallPart) -> FunctionResponsePart)? = null
99+
) {
100+
startAudioConversation(functionCallHandler, false)
101+
}
102+
103+
/**
104+
* Starts an audio conversation with the model, which can only be stopped using
105+
* [stopAudioConversation] or [close].
95106
*
96-
* @param enableInterruptions Boolean to enable user to interrupt the model. Setting this variable
97-
* would allow the user to talk while the model is responding.
107+
* @param functionCallHandler A callback function that is invoked whenever the model receives a
108+
* function call. The [FunctionResponsePart] that the callback function returns will be
109+
* automatically sent to the model.
110+
*
111+
* @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
112+
* ongoing reply.
98113
*
99-
* **WARNING**: User interruption might not work reliably across all devices.
114+
* **WARNING**: The user interruption feature relies on device-specific support, and may not be
115+
* consistently available.
100116
*/
101117
@RequiresPermission(RECORD_AUDIO)
102118
public suspend fun startAudioConversation(
103119
functionCallHandler: ((FunctionCallPart) -> FunctionResponsePart)? = null,
104-
enableInterruptions: Boolean? = null,
120+
enableInterruptions: Boolean = false,
105121
) {
106122

107123
val context = firebaseApp.applicationContext
@@ -381,14 +397,14 @@ internal constructor(
381397
*
382398
* Launched asynchronously on [scope].
383399
*/
384-
private fun listenForModelPlayback(enableInterruptions: Boolean? = null) {
400+
private fun listenForModelPlayback(enableInterruptions: Boolean = false) {
385401
scope.launch {
386402
while (isActive) {
387403
val playbackData = playBackQueue.poll()
388404
if (playbackData == null) {
389405
// The model playback queue is complete, so we can continue recording
390406
// TODO(b/408223520): Conditionally resume when param is added
391-
if (enableInterruptions != true) {
407+
if (!enableInterruptions) {
392408
audioHelper?.resumeRecording()
393409
}
394410
yield()

0 commit comments

Comments
 (0)