-
Notifications
You must be signed in to change notification settings - Fork 617
Refactor live bidi #6870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor live bidi #6870
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
fa6fcf4
Temp Stash
daymxn 9654496
Fix audiohelper bug
daymxn c906509
Rename class
daymxn 909a730
Remove mediadata
daymxn d3bf812
Remove id changes, but leave a TODO
daymxn 19147e3
Remove testing artifacts
daymxn 61f6f4c
Update APIController.kt
daymxn 6df1ef0
Formatting
daymxn b3e5bd9
Add docs to AudioHelper
daymxn 28171b4
Update AudioHelper.kt
daymxn 5df85dc
Document accumulateUntil
daymxn 1bed4eb
Add back stopReceiving
daymxn 89ec5a9
Add additional documentation
daymxn b3b9678
Cleanup javadocs
daymxn fbae7cb
Use blocking instead of background dispatcher
daymxn 3d390a1
Emit empty buffer if no data is read
daymxn 51d1fec
Add documentation for util methods
daymxn 7de0eb7
Decode setupComplete to json
daymxn b137cd9
Update javadocs
daymxn 3b408dc
Update java javadocs to match kotlin
daymxn cc8969a
Update CHANGELOG.md
daymxn 8c99ced
fmt
daymxn c9dda5c
Add missing copyright
daymxn a0cb879
Update api.txt
daymxn b79f27f
Add back MediaData
daymxn d534ef0
Update CHANGELOG.md
daymxn 73a0e3b
Merge branch 'main' into daymon-update-bidi
daymxn 97d46cb
Use ByteArrayOutputStream
daymxn 9fae0b8
Add catching for exceptions
daymxn 0df186c
Handle the return value on write to playback track
daymxn b90e10d
Add note about startAudioConversation and sendFunctionResponse
daymxn f40dcfa
Catch recorder.stop exception
daymxn 795dcfe
Add docs for exceptions thrown
daymxn e6475c7
Use a fold instead of a collect
daymxn b7b0f13
Merge branch 'main' into daymon-update-bidi
daymxn 2e2892a
Update AudioHelper.kt
daymxn 87f1ffa
Update android.kt
daymxn 1ff1618
Update LiveSession.kt
daymxn 644a50b
Update android.kt
daymxn 0a1a48a
Merge branch 'main' into daymon-update-bidi
daymxn 8f199ef
Revert "Update android.kt"
daymxn e38febd
Update android.kt
daymxn ab359fb
Update LiveSessionFutures.kt
daymxn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/util/android.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.vertexai.common.util | ||
|
||
import android.media.AudioRecord | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.yield | ||
|
||
/** | ||
* The minimum buffer size for this instance. | ||
* | ||
* The same as calling [AudioRecord.getMinBufferSize], except the params are pre-populated. | ||
*/ | ||
internal val AudioRecord.minBufferSize: Int | ||
get() = AudioRecord.getMinBufferSize(sampleRate, channelConfiguration, audioFormat) | ||
|
||
/** | ||
* Reads from this [AudioRecord] and returns the data in a flow. | ||
* | ||
* Will yield when this instance is not recording. | ||
*/ | ||
internal fun AudioRecord.readAsFlow() = flow { | ||
val buffer = ByteArray(minBufferSize) | ||
|
||
while (true) { | ||
if (recordingState != AudioRecord.RECORDSTATE_RECORDING) { | ||
yield() | ||
continue | ||
} | ||
|
||
val bytesRead = read(buffer, 0, buffer.size) | ||
if (bytesRead > 0) { | ||
emit(buffer.copyOf(bytesRead)) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.