1717package com.google.firebase.ai.java
1818
1919import android.Manifest.permission.RECORD_AUDIO
20- import android.media.AudioRecord
21- import android.media.AudioTrack
2220import androidx.annotation.RequiresPermission
2321import androidx.concurrent.futures.SuspendToFutureAdapter
2422import com.google.common.util.concurrent.ListenableFuture
2523import com.google.firebase.ai.type.Content
24+ import com.google.firebase.ai.type.ConversationConfig
2625import com.google.firebase.ai.type.FunctionCallPart
2726import com.google.firebase.ai.type.FunctionResponsePart
2827import com.google.firebase.ai.type.InlineData
@@ -51,215 +50,62 @@ public abstract class LiveSessionFutures internal constructor() {
5150 @RequiresPermission(RECORD_AUDIO )
5251 public abstract fun startAudioConversation (): ListenableFuture <Unit >
5352
54- /* *
55- * Starts an audio conversation with the model, which can only be stopped using
56- * [stopAudioConversation] or [close].
57- *
58- * @param functionCallHandler A callback function that is invoked whenever the model receives a
59- * function call.
60- */
61- @RequiresPermission(RECORD_AUDIO )
62- public abstract fun startAudioConversation (
63- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )?
64- ): ListenableFuture <Unit >
65-
6653 /* *
6754 * Starts an audio conversation with the model, which can only be stopped using
6855 * [stopAudioConversation].
69- * @param transcriptHandler A callback function that is invoked whenever the model receives a
70- * transcript. The first [Transcription] object is the input transcription, and the second is the
71- * output transcription
72- */
73- @RequiresPermission(RECORD_AUDIO )
74- public abstract fun startAudioConversation (
75- transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
76- ): ListenableFuture <Unit >
77-
78- /* *
79- * Starts an audio conversation with the model, which can only be stopped using
80- * [stopAudioConversation] or [close].
8156 *
82- * @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
83- * ongoing reply.
84- *
85- * **WARNING**: The user interruption feature relies on device-specific support, and may not be
86- * consistently available.
87- */
88- @RequiresPermission(RECORD_AUDIO )
89- public abstract fun startAudioConversation (enableInterruptions : Boolean ): ListenableFuture <Unit >
90-
91- /* *
92- * Starts an audio conversation with the model, which can only be stopped using
93- * [stopAudioConversation] or [close].
94- *
95- * @param transcriptHandler A callback function that is invoked whenever the model receives a
96- * transcript. The first [Transcription] object is the input transcription, and the second is the
97- * output transcription
98- *
99- * @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
100- * ongoing reply.
101- *
102- * **WARNING**: The user interruption feature relies on device-specific support, and may not be
103- * consistently available.
57+ * @param conversationConfig A [ConversationConfig] provided by the user to control the various
58+ * aspects of the conversation.
10459 */
10560 @RequiresPermission(RECORD_AUDIO )
10661 public abstract fun startAudioConversation (
107- transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
108- enableInterruptions : Boolean
62+ conversationConfig : ConversationConfig
10963 ): ListenableFuture <Unit >
11064
11165 /* *
11266 * Starts an audio conversation with the model, which can only be stopped using
11367 * [stopAudioConversation] or [close].
11468 *
11569 * @param functionCallHandler A callback function that is invoked whenever the model receives a
116- * function call. The [FunctionResponsePart] that the callback function returns will be
117- * automatically sent to the model.
118- *
119- * @param audioHandler A callback function that is invoked immediately following the successful
120- * initialization of the associated [AudioRecord] and [AudioTrack] objects. This offers a final
121- * opportunity to apply custom configurations or modifications to these objects, which will remain
122- * valid and effective for the duration of the current audio session.
123- */
124- @RequiresPermission(RECORD_AUDIO )
125- public abstract fun startAudioConversation (
126- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
127- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )?
128- ): ListenableFuture <Unit >
129-
130- /* *
131- * Starts an audio conversation with the model, which can only be stopped using
132- * [stopAudioConversation] or [close].
133- *
134- * @param transcriptHandler A callback function that is invoked whenever the model receives a
135- * transcript. The first [Transcription] object is the input transcription, and the second is the
136- * output transcription.
137- *
138- * @param audioHandler A callback function that is invoked immediately following the successful
139- * initialization of the associated [AudioRecord] and [AudioTrack] objects. This offers a final
140- * opportunity to apply custom configurations or modifications to these objects, which will remain
141- * valid and effective for the duration of the current audio session.
142- */
143- @RequiresPermission(RECORD_AUDIO )
144- public abstract fun startAudioConversation (
145- transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
146- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )?
147- ): ListenableFuture <Unit >
148-
149- /* *
150- * Starts an audio conversation with the model, which can only be stopped using
151- * [stopAudioConversation] or [close].
152- *
153- * @param audioHandler A callback function that is invoked immediately following the successful
154- * initialization of the associated [AudioRecord] and [AudioTrack] objects. This offers a final
155- * opportunity to apply custom configurations or modifications to these objects, which will remain
156- * valid and effective for the duration of the current audio session.
157- *
158- * @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
159- * ongoing reply.
160- *
161- * **WARNING**: The user interruption feature relies on device-specific support, and may not be
162- * consistently available.
163- */
164- @RequiresPermission(RECORD_AUDIO )
165- public abstract fun startAudioConversation (
166- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ,
167- enableInterruptions : Boolean
168- ): ListenableFuture <Unit >
169-
170- /* *
171- * Starts an audio conversation with the model, which can only be stopped using
172- * [stopAudioConversation] or [close].
173- *
174- * @param functionCallHandler A callback function that is invoked whenever the model receives a
175- * function call. The [FunctionResponsePart] that the callback function returns will be
176- * automatically sent to the model.
177- *
178- * @param transcriptHandler A callback function that is invoked whenever the model receives a
179- * transcript. The first [Transcription] object is the input transcription, and the second is the
180- * output transcription.
181- *
182- * @param audioHandler A callback function that is invoked immediately following the successful
183- * initialization of the associated [AudioRecord] and [AudioTrack] objects. This offers a final
184- * opportunity to apply custom configurations or modifications to these objects, which will remain
185- * valid and effective for the duration of the current audio session.
70+ * function call.
18671 */
18772 @RequiresPermission(RECORD_AUDIO )
18873 public abstract fun startAudioConversation (
189- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
190- transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
191- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )?
74+ functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )?
19275 ): ListenableFuture <Unit >
19376
19477 /* *
19578 * Starts an audio conversation with the model, which can only be stopped using
196- * [stopAudioConversation] or [close].
197- *
198- * @param functionCallHandler A callback function that is invoked whenever the model receives a
199- * function call. The [FunctionResponsePart] that the callback function returns will be
200- * automatically sent to the model.
201- *
79+ * [stopAudioConversation].
20280 * @param transcriptHandler A callback function that is invoked whenever the model receives a
20381 * transcript. The first [Transcription] object is the input transcription, and the second is the
204- * output transcription.
205- *
206- * @param audioHandler A callback function that is invoked immediately following the successful
207- * initialization of the associated [AudioRecord] and [AudioTrack] objects. This offers a final
208- * opportunity to apply custom configurations or modifications to these objects, which will remain
209- * valid and effective for the duration of the current audio session.
210- *
211- * @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
212- * ongoing reply.
213- *
214- * **WARNING**: The user interruption feature relies on device-specific support, and may not be
215- * consistently available.
82+ * output transcription
21683 */
21784 @RequiresPermission(RECORD_AUDIO )
21885 public abstract fun startAudioConversation (
219- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
22086 transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
221- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ,
222- enableInterruptions : Boolean
22387 ): ListenableFuture <Unit >
22488
22589 /* *
22690 * Starts an audio conversation with the model, which can only be stopped using
22791 * [stopAudioConversation] or [close].
22892 *
229- * @param functionCallHandler A callback function that is invoked whenever the model receives a
230- * function call. The [FunctionResponsePart] that the callback function returns will be
231- * automatically sent to the model.
232- *
233- * @param audioHandler A callback function that is invoked immediately following the successful
234- * initialization of the associated [AudioRecord] and [AudioTrack] objects. This offers a final
235- * opportunity to apply custom configurations or modifications to these objects, which will remain
236- * valid and effective for the duration of the current audio session.
237- *
23893 * @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
23994 * ongoing reply.
24095 *
24196 * **WARNING**: The user interruption feature relies on device-specific support, and may not be
24297 * consistently available.
24398 */
24499 @RequiresPermission(RECORD_AUDIO )
245- public abstract fun startAudioConversation (
246- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
247- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ,
248- enableInterruptions : Boolean
249- ): ListenableFuture <Unit >
100+ public abstract fun startAudioConversation (enableInterruptions : Boolean ): ListenableFuture <Unit >
250101
251102 /* *
252103 * Starts an audio conversation with the model, which can only be stopped using
253104 * [stopAudioConversation] or [close].
254105 *
255106 * @param transcriptHandler A callback function that is invoked whenever the model receives a
256107 * transcript. The first [Transcription] object is the input transcription, and the second is the
257- * output transcription.
258- *
259- * @param audioHandler A callback function that is invoked immediately following the successful
260- * initialization of the associated [AudioRecord] and [AudioTrack] objects. This offers a final
261- * opportunity to apply custom configurations or modifications to these objects, which will remain
262- * valid and effective for the duration of the current audio session.
108+ * output transcription
263109 *
264110 * @param enableInterruptions If enabled, allows the user to speak over or interrupt the model's
265111 * ongoing reply.
@@ -270,24 +116,9 @@ public abstract class LiveSessionFutures internal constructor() {
270116 @RequiresPermission(RECORD_AUDIO )
271117 public abstract fun startAudioConversation (
272118 transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
273- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ,
274119 enableInterruptions : Boolean
275120 ): ListenableFuture <Unit >
276121
277- /* *
278- * Starts an audio conversation with the model, which can only be stopped using
279- * [stopAudioConversation] or [close].
280- *
281- * @param audioHandler A callback function that is invoked immediately following the successful
282- * initialization of the associated [AudioRecord] and [AudioTrack] objects. This offers a final
283- * opportunity to apply custom configurations or modifications to these objects, which will remain
284- * valid and effective for the duration of the current audio session.
285- */
286- @RequiresPermission(RECORD_AUDIO )
287- public abstract fun startAudioConversation (
288- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )?
289- ): ListenableFuture <Unit >
290-
291122 /* *
292123 * Starts an audio conversation with the model, which can only be stopped using
293124 * [stopAudioConversation] or [close].
@@ -480,6 +311,10 @@ public abstract class LiveSessionFutures internal constructor() {
480311 session.startAudioConversation(transcriptHandler = transcriptHandler)
481312 }
482313
314+ @RequiresPermission(RECORD_AUDIO )
315+ override fun startAudioConversation (conversationConfig : ConversationConfig ) =
316+ SuspendToFutureAdapter .launchFuture { session.startAudioConversation(conversationConfig) }
317+
483318 @RequiresPermission(RECORD_AUDIO )
484319 override fun startAudioConversation () =
485320 SuspendToFutureAdapter .launchFuture { session.startAudioConversation() }
@@ -502,108 +337,6 @@ public abstract class LiveSessionFutures internal constructor() {
502337 )
503338 }
504339
505- @RequiresPermission(RECORD_AUDIO )
506- override fun startAudioConversation (
507- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
508- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )?
509- ) =
510- SuspendToFutureAdapter .launchFuture {
511- session.startAudioConversation(
512- functionCallHandler = functionCallHandler,
513- audioHandler = audioHandler
514- )
515- }
516-
517- @RequiresPermission(RECORD_AUDIO )
518- override fun startAudioConversation (
519- transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
520- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )?
521- ) =
522- SuspendToFutureAdapter .launchFuture {
523- session.startAudioConversation(
524- transcriptHandler = transcriptHandler,
525- audioHandler = audioHandler
526- )
527- }
528-
529- @RequiresPermission(RECORD_AUDIO )
530- override fun startAudioConversation (
531- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ,
532- enableInterruptions : Boolean
533- ) =
534- SuspendToFutureAdapter .launchFuture {
535- session.startAudioConversation(
536- audioHandler = audioHandler,
537- enableInterruptions = enableInterruptions
538- )
539- }
540-
541- @RequiresPermission(RECORD_AUDIO )
542- override fun startAudioConversation (
543- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
544- transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
545- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )?
546- ) =
547- SuspendToFutureAdapter .launchFuture {
548- session.startAudioConversation(
549- functionCallHandler = functionCallHandler,
550- transcriptHandler = transcriptHandler,
551- audioHandler = audioHandler,
552- )
553- }
554-
555- @RequiresPermission(RECORD_AUDIO )
556- override fun startAudioConversation (
557- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
558- transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
559- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ,
560- enableInterruptions : Boolean
561- ) =
562- SuspendToFutureAdapter .launchFuture {
563- session.startAudioConversation(
564- functionCallHandler = functionCallHandler,
565- transcriptHandler = transcriptHandler,
566- audioHandler = audioHandler,
567- enableInterruptions = enableInterruptions
568- )
569- }
570-
571- @RequiresPermission(RECORD_AUDIO )
572- override fun startAudioConversation (
573- functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
574- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ,
575- enableInterruptions : Boolean
576- ) =
577- SuspendToFutureAdapter .launchFuture {
578- session.startAudioConversation(
579- functionCallHandler = functionCallHandler,
580- audioHandler = audioHandler,
581- enableInterruptions = enableInterruptions,
582- )
583- }
584-
585- @RequiresPermission(RECORD_AUDIO )
586- override fun startAudioConversation (
587- transcriptHandler : ((Transcription ? , Transcription ? ) -> Unit )? ,
588- audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ,
589- enableInterruptions : Boolean
590- ) =
591- SuspendToFutureAdapter .launchFuture {
592- session.startAudioConversation(
593- transcriptHandler = transcriptHandler,
594- audioHandler = audioHandler,
595- enableInterruptions = enableInterruptions,
596- )
597- }
598-
599- @RequiresPermission(RECORD_AUDIO )
600- override fun startAudioConversation (audioHandler : ((AudioRecord , AudioTrack ) -> Unit )? ) =
601- SuspendToFutureAdapter .launchFuture {
602- session.startAudioConversation(
603- audioHandler = audioHandler,
604- )
605- }
606-
607340 @RequiresPermission(RECORD_AUDIO )
608341 override fun startAudioConversation (
609342 functionCallHandler : ((FunctionCallPart ) -> FunctionResponsePart )? ,
0 commit comments