chore: add Apache License 2.0 and ignore build directory

This commit is contained in:
2026-07-16 17:24:50 +03:00
parent 45e4bce2a0
commit 7affa0dbc8
23 changed files with 1814 additions and 157 deletions
+61
View File
@@ -0,0 +1,61 @@
// Package app coordinates capture, transcription, and caption presentation.
package app
import (
"context"
"errors"
"fmt"
"io"
"tea.chunkbyte.com/kato/captioneer/src/captions"
"tea.chunkbyte.com/kato/captioneer/src/capture"
"tea.chunkbyte.com/kato/captioneer/src/config"
"tea.chunkbyte.com/kato/captioneer/src/models"
"tea.chunkbyte.com/kato/captioneer/src/output"
)
func Run(ctx context.Context, settings config.Settings, sink output.Sink, diagnostics io.Writer) error {
if err := capture.ValidatePrograms(); err != nil {
return err
}
resources, err := models.New(settings)
if err != nil {
return err
}
defer resources.Close()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
monitorSource, err := capture.DefaultMonitorSource(ctx)
if err != nil {
return fmt.Errorf("find default output monitor: %w", err)
}
fmt.Fprintf(diagnostics, "Capturing from: %s\n", monitorSource)
fmt.Fprintln(diagnostics, "Press Ctrl+C to stop.")
packets, waitCapture, err := capture.Packets(ctx, monitorSource)
if err != nil {
return fmt.Errorf("start system-audio capture: %w", err)
}
processor := captions.New(settings, resources, sink.Publish)
var processErr error
for packet := range packets {
if err := processor.Accept(packet); err != nil {
processErr = fmt.Errorf("publish caption: %w", err)
cancel()
break
}
}
if processErr == nil {
processErr = processor.Flush()
}
captureErr := waitCapture()
if captureErr != nil && ctx.Err() == nil {
captureErr = fmt.Errorf("audio capture stopped unexpectedly: %w", captureErr)
} else {
captureErr = nil
}
return errors.Join(processErr, captureErr)
}