macOS menu-bar utility: select text anywhere → right-click → Services → "Read with SelectedTextTTS" → high-quality TTS reads it aloud, with per-sentence caching.
This repo is built without Xcode (only Command Line Tools are installed). A small
build.sh compiles with swiftc and assembles the .app bundle by hand. It is still a
plain AppKit project and can be imported into Xcode later if desired.
M1 = menu-bar agent + macOS Services registration + selected-text logging. No audio yet.
The TTSBackend protocol (the pluggable engine abstraction) is defined; only a no-op
StubBackend is wired in. Audio playback arrives in M2.
./build.sh # build → install to ~/Applications → register Services → launch
./build.sh dev # build → run in THIS terminal (stdout/os_log visible, no install)
./build.sh build # build into ./build only
./build.sh test # compile + run the unit tests (TextSplitter, CrawlLayout, ReviewVerdict)
./build.sh smoke # 실제 LLM 엔드포인트로 해설→검수→대본→검수 스모크 (gemini_key 필요, 유료 호출)
./build.sh logs # tail the app's unified logs
./build.sh clean # remove ./buildLaunch Services only reliably scans
~/Applicationsand/Applications, so./build.shinstalls there. Running the.appfrom./buildmay not make the Service appear.
The global hotkeys (⌃⌥⌘R read, ⌃⌥⌘E explain) need Accessibility permission. With ad-hoc signing the grant is bound to the binary's cdhash, so every rebuild silently invalidates it — the toggle still shows on in System Settings, but pressing the hotkey just re-opens the permission prompt. Sign with a stable self-signed identity to fix this once and for all.
One-time cert creation (scripted — creates Codebasic TTS Local in the login keychain):
TMP="$(mktemp -d)"
cat > "$TMP/ext.cnf" <<'EOF'
[ req ]
distinguished_name = dn
x509_extensions = ext
prompt = no
[ dn ]
CN = Codebasic TTS Local
[ ext ]
basicConstraints = critical,CA:false
keyUsage = critical,digitalSignature
extendedKeyUsage = critical,codeSigning
EOF
openssl req -x509 -newkey rsa:2048 -sha256 -days 3650 -nodes \
-keyout "$TMP/key.pem" -out "$TMP/cert.pem" -config "$TMP/ext.cnf"
# NOTE: a non-empty -passout is required, else Apple's `security import` fails MAC verification
openssl pkcs12 -export -inkey "$TMP/key.pem" -in "$TMP/cert.pem" \
-out "$TMP/id.p12" -passout pass:codebasic -name "Codebasic TTS Local"
security import "$TMP/id.p12" -k ~/Library/Keychains/login.keychain-db \
-P codebasic -A -T /usr/bin/codesign
rm -rf "$TMP"(Alternatively, Keychain Access → Certificate Assistant → Create a Certificate…,
Name Codebasic TTS Local, Self-Signed Root, Code Signing.)
The cert is untrusted (CSSMERR_TP_NOT_TRUSTED) — that's fine: codesign still signs with
it and the designated requirement becomes a stable certificate leaf = H"…", which is all TCC
needs. build.sh detects it with security find-identity -p codesigning (no -v, since -v
hides untrusted identities). Then grant once:
./build.sh # signs with the cert (see its log line)
tccutil reset Accessibility com.seongjoo.SelectedTextTTS # clear the old ad-hoc grant once
# press ⌃⌥⌘R → grant in System Settings → Privacy & Security → AccessibilityAfter this, rebuilds keep the permission. Override the identity name with
CODESIGN_IDENTITY="…" ./build.sh if you named it differently.
./build.sh— installs, registers, and launches the app (🔊 appears in the menu bar).- In TextEdit, type and select a line of text.
- Right-click → Services → "Read with SelectedTextTTS" (or the app menu → Services).
- Confirm it fired:
- menu-bar 🔊 briefly flips to 🔈,
- its menu's "Last selection: …" updates,
./build.sh logsshowsService fired: received N chars.
For fast iteration during development, prefer ./build.sh dev: it runs the binary in the
foreground so logs print straight to your terminal. (The Services menu item still resolves
to the copy registered in ~/Applications, so keep one ./build.sh install around.)
Order of things to try:
./build.shagain (re-runslsregister -f+pbs -update/-flush).- Make sure you tested from an app that exposes Services well (TextEdit is reliable).
- Manually re-register:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \ -f ~/Applications/SelectedTextTTS.app /System/Library/CoreServices/pbs -update - Last resort: log out and back in.
pbssometimes only rescans on session start; a missing menu item after the steps above is a registration quirk, not a code bug.
SelectedTextTTS/
├── build.sh # swiftc build + bundle assembly + LS registration
├── Resources/Info.plist # LSUIElement + NSServices definition
└── Sources/
├── App/main.swift # programmatic NSApplication entry point
├── App/AppDelegate.swift # menu-bar item, Services registration, selection handler
├── Service/ServiceProvider.swift # NSServices handler (readSelectedText:userData:error:)
├── Core/Logging.swift # os_log wrappers (why: LSUIElement print() is invisible)
└── TTS/TTSBackend.swift # TTSBackend protocol + VoiceConfig + StubBackend
| Milestone | Scope |
|---|---|
| M1 ✅ | Menu-bar agent, Services registration, selected-text logging |
| M2 | ElevenLabs /stream → AVQueuePlayer, one-shot playback (no cache) |
| M3 | NLTokenizer sentence segmentation + per-segment disk cache |
| M4 | Partial / suffix-extended selection reuse |
| M5 | Local Qwen3MLXBackend (Python mlx-audio sidecar), backend toggle |
| M6 | Keychain API key, error/offline handling, voice-selection UI |
The handoff's final line asks to "run the local model first in M1." That is deferred on
purpose: mlx / mlx_audio are not importable in this machine's Python (3.14.5 — too new
for current MLX wheels), so the local engine needs its own venv (Python 3.11/3.12) set up as
a parallel track before M5. M1 ships the skeleton + the backend abstraction so either engine
can drop in behind TTSBackend. Voice-clone assets already exist in the repo root
(ref_sj.wav, voice_clone_prompt_sj.pt, ref_text.txt).