Package recording provides conversation audio recording to local WAV files and async upload to S3 via a worker pool.
Purpose
ConversationRecorder: Records mixed PCM 16-bit mono samples for a single session; WriteSamples appends audio; Close finalizes the WAV file and returns LocalFileInfo.
Uploader: Accepts RecordingJob (local path, bucket, key); worker pool uploads to S3 and removes the local file on success. Used when a session ends: recorder is closed, then a job is enqueued.
Session end: caller closes the recorder (get LocalFileInfo), builds RecordingJob with path, bucket, key (e.g. via BuildS3Key), then Uploader.Enqueue(job).
Workers pull jobs from the channel and upload; on success the local file is removed. Metrics: RecordingJobsEnqueuedTotal, RecordingJobsSuccessTotal, RecordingJobsFailedTotal, RecordingQueueDepth.
Concurrency
ConversationRecorder: Intended for single-goroutine use (e.g. one recorder per session).
Uploader: Enqueue is safe for concurrent use; Shutdown closes the job channel and waits for workers (or ctx done). Worker goroutines run until the job channel is closed.
type ConversationRecorder interface {
// WriteSamples appends raw PCM 16-bit mono samples at the given sample rate. WriteSamples(samples []int16, sampleRate int) error// Close finalizes the recording and returns info about the created file. Close() (LocalFileInfo, error)
}
ConversationRecorder records mixed audio for a single call/session.
Implementations are expected to be safe for use from a single goroutine.
type Uploader struct {
// contains filtered or unexported fields
}
Uploader uploads recordings to S3 using a fixed-size worker pool.
THREAD SAFETY: Enqueue may be called from any goroutine; workers are the only consumers of jobs; Shutdown must not be called concurrently with Enqueue.
NewUploader creates a new uploader with the given worker count, queue size, and max retries (0 = default 3).
SCALING: one worker per ~N concurrent sessions uploading at once; tune for S3 bandwidth.