File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
firebaseai/FirebaseAIExample/Shared/Audio Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 1313// limitations under the License.
1414
1515import AVFoundation
16+ import OSLog
1617
1718/// Controls audio playback and recording.
1819actor AudioController {
20+ private var logger = Logger ( subsystem: Bundle . main. bundleIdentifier!, category: " generative-ai " )
21+
1922 /// Data processed from the microphone.
2023 private let microphoneData : AsyncStream < AVAudioPCMBuffer >
2124 private let microphoneDataQueue : AsyncStream < AVAudioPCMBuffer > . Continuation
@@ -93,7 +96,7 @@ actor AudioController {
9396 try audioEngine. inputNode. setVoiceProcessingEnabled ( false )
9497 }
9598 } catch {
96- print ( " Failed to disable voice processing: \( error. localizedDescription) " )
99+ logger . error ( " Failed to disable voice processing: \( error. localizedDescription) " )
97100 }
98101 }
99102 Task { @MainActor [ audioPlayer, microphone] in
@@ -142,7 +145,7 @@ actor AudioController {
142145 try audioEngine. inputNode. setVoiceProcessingEnabled ( false )
143146 }
144147 } catch {
145- print ( " Failed to disable voice processing: \( error. localizedDescription) " )
148+ logger . error ( " Failed to disable voice processing: \( error. localizedDescription) " )
146149 }
147150 }
148151 await microphone? . stop ( )
@@ -246,7 +249,7 @@ actor AudioController {
246249 do {
247250 try await spawnAudioProcessingThread ( )
248251 } catch {
249- print ( " Failed to spawn audio processing thread: \( String ( describing: error) ) " )
252+ await logger . error ( " Failed to spawn audio processing thread: \( String ( describing: error) ) " )
250253 }
251254 }
252255 default : ( )
Original file line number Diff line number Diff line change 1414
1515import AVFoundation
1616import Foundation
17+ import OSLog
1718
1819/// Plays back audio through the primary output device.
1920class AudioPlayer {
21+ private var logger = Logger ( subsystem: Bundle . main. bundleIdentifier!, category: " generative-ai " )
22+
2023 private let engine : AVAudioEngine
2124 private let inputFormat : AVAudioFormat
2225 private let outputFormat : AVAudioFormat
@@ -54,7 +57,7 @@ class AudioPlayer {
5457 /// being played through the output device.
5558 public func play( _ audio: Data ) throws {
5659 guard engine. isRunning else {
57- print ( " Audio engine needs to be running to play audio. " )
60+ logger . warning ( " Audio engine needs to be running to play audio. " )
5861 return
5962 }
6063
You can’t perform that action at this time.
0 commit comments