refactor: reorganize monolithic main package into focused packages

Move the executable entry point to `src/cmd/captioneer` and split audio, capture, config, caption, and model logic into separate packages under `src/`. Update README with new build/run commands and a package-overview section.
This commit is contained in:
2026-07-16 12:12:01 +03:00
parent ce2161b7e6
commit 45e4bce2a0
15 changed files with 454 additions and 386 deletions
+15 -15
View File
@@ -35,19 +35,19 @@ The download installs the Parakeet TDT v2 int8 model and Silero VAD into `models
Use VAD mode for normal live captions. It shows a temporary `…` caption while speech is active, then prints a timestamped final caption after 0.5 seconds of silence:
```bash
go run ./src --mode=vad
go run ./src/cmd/captioneer --mode=vad
```
Use fixed mode to decode exact time slices, even through silence:
```bash
go run ./src --mode=fixed --chunk-duration=1s
go run ./src/cmd/captioneer --mode=fixed --chunk-duration=1s
```
Build a reusable executable instead of using `go run`:
```bash
go build -o captioneer ./src
go build -o captioneer ./src/cmd/captioneer
./captioneer --mode=vad
```
@@ -70,27 +70,27 @@ Examples:
```bash
# Faster fixed chunks
go run ./src --mode=fixed --chunk-duration=500ms
go run ./src/cmd/captioneer --mode=fixed --chunk-duration=500ms
# Fewer VAD preview redraws and four CPU threads
go run ./src --mode=vad --chunk-duration=2s --threads=4
go run ./src/cmd/captioneer --mode=vad --chunk-duration=2s --threads=4
# Store or reuse models outside this repository
go run ./src --mode=vad --models-dir=/path/to/models
go run ./src/cmd/captioneer --mode=vad --models-dir=/path/to/models
```
There are no environment variables to configure. All supported configuration is supplied with command-line options.
## Source layout
All Go code lives in `src/`. It remains one executable package, split into focused files:
All Go code lives in `src/` as focused packages:
- `main.go` coordinates startup and shutdown.
- `config.go` defines and validates command-line options.
- `capture.go` reads the default system-audio monitor.
- `audio.go` contains PCM conversion and audio calculations.
- `models.go` validates and initializes Parakeet and Silero.
- `captions.go` handles fixed chunks, VAD segments, and terminal output.
- `cmd/captioneer` is the executable entrypoint.
- `config` defines command-line options.
- `audio` contains PCM conversion and audio calculations.
- `capture` reads the default system-audio monitor.
- `models` owns Parakeet and Silero model resources.
- `captions` handles fixed chunks, VAD segments, and terminal output.
## Output and troubleshooting
@@ -103,7 +103,7 @@ Final captions go to standard output in this form:
Startup messages and overload warnings go to standard error, so you can save final captions separately:
```bash
go run ./src --mode=vad > captions.txt
go run ./src/cmd/captioneer --mode=vad > captions.txt
```
- **Missing model files:** run `./scripts/download-models.sh` again.
@@ -115,5 +115,5 @@ go run ./src --mode=vad > captions.txt
```bash
go test ./...
go build -o captioneer ./src
go build -o captioneer ./src/cmd/captioneer
```