-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[FirebaseAI] Add Live Audio screen #1776
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
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
72acfe4
Add live audio screen
daymxn caaa8cd
Add microphone usage description
daymxn ca5df45
Add live screen to xcode project
daymxn 39d50cb
Fix bug in transcript view model
daymxn 693e498
Formatting
daymxn 9b818ff
Fix typo
daymxn 8d53bad
Add docs for extension property
daymxn 74a7349
Remove app check import
daymxn 4bdeea4
Make int16Data not nullable
daymxn 7a2e3ea
Make audio controller an actor
daymxn e51984f
Rename ModelPhoto to ModelAvatar
daymxn d6a2986
Adjust TranscriptView text style
daymxn a61a459
Move Color extension to new file
daymxn e654c84
Add error handling instead of fatalError
daymxn b20448c
Update minimum version
daymxn d4d1edd
Add function calling tip
daymxn 2fc8b45
Fix error view
daymxn 52a24f5
Disable playback on simulator
daymxn b8238e4
Adjust connect button to be compat with glass
daymxn e19a16d
Increase line char length
daymxn a32fbda
Simplify the transcript view
daymxn 52e4f54
Update project.pbxproj
daymxn e3dde93
Merge branch 'main' into dlr/add-live-audio
daymxn 4e03f14
Merge branch 'main' into dlr/add-live-audio
daymxn 81bf0d1
Migrate to the new structure
daymxn 6fd9af9
Remove the old code
daymxn cbb1182
Update FirebaseAIExampleApp.swift
daymxn 82b032e
formatting
daymxn d830f65
Add audio playback toggle when running on the simulator (#1826)
andrewheard 4a491ce
Fix concurrency warnings
daymxn 0ddc62d
Use logger instead of print
daymxn 54ea164
Fix deinit logic not triggering
daymxn be1f51b
Use default font and size
daymxn ef9510b
Add border to connected
daymxn e3a58b7
Use non fill variants of icons
daymxn c75c740
Use system colors
daymxn 0d6e84e
Split view modifiers across two lines
daymxn 0427e11
Use style instead of inline configuration
daymxn 4b2e01c
formatting
daymxn 0d07e72
Fix typo
daymxn 9856ef5
Add full width back to connect button
daymxn 6fe2bca
Put view modifiers on their own lines
daymxn 159de5c
Fix explicit color usage
daymxn f7e07c8
Use TipKit instead of custom TipView
daymxn 99a4a7a
Add preview for InlineTip
daymxn e3a4bf9
Make audio playback toggle present during session
daymxn f655d18
formatting
daymxn 255181f
Fix compile error
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
21 changes: 21 additions & 0 deletions
21
firebaseai/FirebaseAIExample/Assets.xcassets/gemini-logo.imageset/Contents.json
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,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "gemini-logo.png", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } | ||
Binary file added
BIN
+235 KB
firebaseai/FirebaseAIExample/Assets.xcassets/gemini-logo.imageset/gemini-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
74 changes: 74 additions & 0 deletions
74
firebaseai/FirebaseAIExample/Features/Live/Screens/LiveScreen.swift
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,74 @@ | ||
| // 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. | ||
|
|
||
| #if canImport(FirebaseAILogic) | ||
| import FirebaseAILogic | ||
| #else | ||
| import FirebaseAI | ||
| #endif | ||
| import SwiftUI | ||
| import TipKit | ||
|
|
||
| struct LiveScreen: View { | ||
| let backendType: BackendOption | ||
| @StateObject var viewModel: LiveViewModel | ||
|
|
||
| init(backendType: BackendOption, sample: Sample? = nil) { | ||
| self.backendType = backendType | ||
| _viewModel = | ||
| StateObject(wrappedValue: LiveViewModel(backendType: backendType, | ||
| sample: sample)) | ||
| } | ||
|
|
||
| var body: some View { | ||
| VStack(spacing: 20) { | ||
| ModelAvatar(isConnected: viewModel.state == .connected) | ||
| TranscriptView(typewriter: viewModel.transcriptTypewriter) | ||
|
|
||
| Spacer() | ||
| if let error = viewModel.error { | ||
| ErrorDetailsView(error: error) | ||
| } | ||
| if let tip = viewModel.tip, !viewModel.hasTranscripts { | ||
| TipView(tip) | ||
| } | ||
| ConnectButton( | ||
| state: viewModel.state, | ||
| onConnect: viewModel.connect, | ||
| onDisconnect: viewModel.disconnect | ||
| ) | ||
|
|
||
| #if targetEnvironment(simulator) | ||
| AudioOutputToggle(isEnabled: $viewModel.isAudioOutputEnabled, onChange: { | ||
| Task { | ||
| await viewModel.onAudioPlaybackChanged() | ||
| } | ||
| }) | ||
| #endif | ||
| } | ||
| .padding() | ||
| .navigationTitle(viewModel.title) | ||
| .navigationBarTitleDisplayMode(.inline) | ||
| .background(viewModel.backgroundColor ?? .clear) | ||
| .onDisappear { | ||
| Task { | ||
| await viewModel.disconnect() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| LiveScreen(backendType: .googleAI) | ||
| } |
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.