potential split between CLI and core library
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user