File tree Expand file tree Collapse file tree 2 files changed +5
-25
lines changed
firebaseai/FirebaseAIExample Expand file tree Collapse file tree 2 files changed +5
-25
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,11 @@ struct LiveScreen: View {
5757 . padding ( )
5858 . navigationTitle ( viewModel. title)
5959 . navigationBarTitleDisplayMode ( . inline)
60- . background ( viewModel. backgroundColor ?? . clear)
60+ . background ( viewModel. backgroundColor ?? . clear) . onDisappear {
61+ Task {
62+ await viewModel. disconnect ( )
63+ }
64+ }
6165 }
6266}
6367
Original file line number Diff line number Diff line change @@ -83,30 +83,6 @@ actor AudioController {
8383 listenForRouteChange ( )
8484 }
8585
86- deinit {
87- stopped = true
88- listenTask? . cancel ( )
89- // audio engine needs to be stopped before disconnecting nodes
90- audioEngine? . pause ( )
91- audioEngine? . stop ( )
92- if let audioEngine {
93- do {
94- // the VP IO leaves behind artifacts, so we need to disable it to properly clean up
95- if audioEngine. inputNode. isVoiceProcessingEnabled {
96- try audioEngine. inputNode. setVoiceProcessingEnabled ( false )
97- }
98- } catch {
99- logger. error ( " Failed to disable voice processing: \( error. localizedDescription) " )
100- }
101- }
102- Task { @MainActor [ audioPlayer, microphone] in
103- microphone? . stop ( )
104- audioPlayer? . stop ( )
105- }
106- microphoneDataQueue. finish ( )
107- routeTask? . cancel ( )
108- }
109-
11086 /// Kicks off audio processing, and returns a stream of recorded microphone audio data.
11187 public func listenToMic( ) async throws -> AsyncStream < AVAudioPCMBuffer > {
11288 try await spawnAudioProcessingThread ( )
You can’t perform that action at this time.
0 commit comments