potential split between CLI and core library

This commit is contained in:
Nick Payne
2025-08-19 08:51:14 +01:00
parent a311cc583f
commit b7455d26d1
20 changed files with 74 additions and 8 deletions
@@ -0,0 +1,9 @@
import Foundation
/// Protocol for handling audio output in different formats
public protocol AudioOutputHandler {
func handleAudioPacket(_ packet: AudioPacket)
func handleMetadata(_ metadata: AudioStreamMetadata)
func handleStreamStart()
func handleStreamStop()
}
@@ -0,0 +1,23 @@
import Foundation
public class BinaryAudioOutputHandler: AudioOutputHandler {
public init() {}
public func handleAudioPacket(_ packet: AudioPacket) {
// TODO: should we use a DispatchQueue instead of writing directly?
// Write raw binary audio data directly to stdout
FileHandle.standardOutput.write(packet.data)
}
public func handleMetadata(_ metadata: AudioStreamMetadata) {
Logger.writeMessage(.metadata, data: metadata)
}
public func handleStreamStart() {
Logger.writeMessage(.streamStart, data: Optional<String>.none)
}
public func handleStreamStop() {
Logger.writeMessage(.streamStop, data: Optional<String>.none)
}
}
@@ -0,0 +1,44 @@
import Foundation
// Unified message types for all AudioTee output
public enum MessageType: String, Codable {
// Stream lifecycle
case metadata
case streamStart = "stream_start"
case streamStop = "stream_stop"
// Logging
case info
case error
case debug
}
// Base message envelope that wraps all outputs
public struct Message<T: Codable>: Codable {
public let timestamp: Date
public let type: MessageType
public let data: T?
public enum CodingKeys: String, CodingKey {
case timestamp
case type = "message_type"
case data
}
public init(type: MessageType, data: T? = nil) {
self.timestamp = Date()
self.type = type
self.data = data
}
}
// Simple log data for logging messages
public struct LogData: Codable {
public let message: String
public let context: [String: String]?
public init(message: String, context: [String: String]? = nil) {
self.message = message
self.context = context
}
}