Skip to content

Commit 54ea164

Browse files
committed
Fix deinit logic not triggering
1 parent 0ddc62d commit 54ea164

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

firebaseai/FirebaseAIExample/Features/Live/Screens/LiveScreen.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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

firebaseai/FirebaseAIExample/Shared/Audio/AudioController.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)