Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,31 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Resolve version
- name: Resolve version and channel
id: version
run: |
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"

# A -beta suffix (e.g. v1.2.0-beta.1) selects the beta channel: a GitHub
# prerelease and a separate wyoming-apple-stt-beta formula that coexists with,
# and conflicts with, the stable one.
if [[ "${TAG}" == *-beta* ]]; then
CHANNEL="beta"
FORMULA_NAME="wyoming-apple-stt-beta"
FORMULA_CLASS="WyomingAppleSttBeta"
else
CHANNEL="stable"
FORMULA_NAME="wyoming-apple-stt"
FORMULA_CLASS="WyomingAppleStt"
fi

echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "channel=${CHANNEL}" >> "$GITHUB_OUTPUT"
echo "formula_name=${FORMULA_NAME}" >> "$GITHUB_OUTPUT"
echo "formula_class=${FORMULA_CLASS}" >> "$GITHUB_OUTPUT"
echo "formula_file=Formula/${FORMULA_NAME}.rb" >> "$GITHUB_OUTPUT"

- name: Run Swift tests
run: make swift-test
Expand All @@ -40,42 +58,62 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PRERELEASE_FLAG=()
if [[ "${{ steps.version.outputs.channel }}" == "beta" ]]; then
PRERELEASE_FLAG=(--prerelease)
fi
gh release create "${{ steps.version.outputs.tag }}" \
"${{ steps.tarball.outputs.path }}" \
--title "${{ steps.version.outputs.tag }}" \
--generate-notes
--generate-notes \
"${PRERELEASE_FLAG[@]}"

- name: Render formula and push to tap
env:
TAP_PUSH_TOKEN: ${{ secrets.TAP_PUSH_TOKEN }}
TAG: ${{ steps.version.outputs.tag }}
VERSION: ${{ steps.version.outputs.version }}
SHA256: ${{ steps.tarball.outputs.sha256 }}
CHANNEL: ${{ steps.version.outputs.channel }}
FORMULA_NAME: ${{ steps.version.outputs.formula_name }}
FORMULA_CLASS: ${{ steps.version.outputs.formula_class }}
FORMULA_FILE: ${{ steps.version.outputs.formula_file }}
run: |
set -euo pipefail

URL="https://github.com/FI-153/wyoming-apple-stt/releases/download/v${VERSION}/wyoming-apple-stt-${VERSION}.tar.gz"
URL="https://github.com/FI-153/wyoming-apple-stt/releases/download/${TAG}/wyoming-apple-stt-${VERSION}.tar.gz"

URL="${URL}" python3 - <<'PY'
import os
from pathlib import Path

# Stable and beta are mutually exclusive: both install the same apple-stt/apple-tts
# binaries and launchd service. conflicts_with is only enforced from the declaring
# side, so each formula names the other.
because = "both install the same binaries and launchd service"
other = "wyoming-apple-stt" if os.environ["CHANNEL"] == "beta" else "wyoming-apple-stt-beta"
conflicts = f'conflicts_with "{other}", because: "{because}"'

tpl = Path("packaging/formula.rb.template").read_text()
resources = Path("packaging/python-resources.rb").read_text().rstrip()
rendered = (
tpl
.replace("{{CLASS}}", os.environ["FORMULA_CLASS"])
.replace("{{URL}}", os.environ["URL"])
.replace("{{VERSION}}", os.environ["VERSION"])
.replace("{{SHA256}}", os.environ["SHA256"])
.replace("{{CONFLICTS}}", conflicts)
.replace("{{PYTHON_RESOURCES}}", resources)
)
Path("wyoming-apple-stt.rb").write_text(rendered)
Path("rendered-formula.rb").write_text(rendered)
PY

git clone "https://x-access-token:${TAP_PUSH_TOKEN}@github.com/FI-153/homebrew-tap.git" tap
mkdir -p tap/Formula
mv wyoming-apple-stt.rb tap/Formula/wyoming-apple-stt.rb
mv rendered-formula.rb "tap/${FORMULA_FILE}"
cd tap
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/wyoming-apple-stt.rb
git commit -m "wyoming-apple-stt ${VERSION}"
git add "${FORMULA_FILE}"
git commit -m "${FORMULA_NAME} ${VERSION}"
git push origin HEAD:main
55 changes: 43 additions & 12 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Wyoming Apple STT

A Wyoming protocol STT server that bridges macOS on-device speech recognition (Apple's Speech
framework) to Home Assistant's Voice pipeline.
A Wyoming protocol STT + TTS server that bridges macOS on-device speech recognition (Apple's
Speech framework) and Siri text-to-speech to Home Assistant's Voice pipeline.

## Project Components

- **swift/** — Swift CLI tool that reads PCM audio from stdin and outputs transcribed text as JSON.
- **swift/Sources/AppleSTT/** — Swift CLI tool (`apple-stt`) that reads PCM audio from stdin and
outputs transcribed text as JSON.
Uses SpeechAnalyzer on macOS 26+ and SFSpeechRecognizer on older systems.
With `--worker` it runs as a persistent streaming worker instead: framed JSON commands on
stdin (`transcribe` → `audio`+PCM payload → `stop`), `ready`/`partial`/`final`/`error`
Expand All @@ -20,12 +21,22 @@ framework) to Home Assistant's Voice pipeline.
- `SupportedLanguages.swift` — pure function `languageCodes(from:)` for extracting deduplicated,
sorted short language codes from a list of locales. Used by `--list-languages` CLI flag.
- `swift/Tests/AppleSTTTests/` — Swift unit tests (Swift Testing framework).
- **swift/Sources/AppleTTS/** — Swift CLI tool (`apple-tts`) exposing the private Siri synthesis
engine (`SiriTTSService.framework`). Runs as a long-lived worker: JSON commands on stdin,
JSON-header + binary PCM frames on stdout. `--list-voices` prints the system-managed Siri
voices (the only ones that reliably load; see `context/planning/add-siri-tts-streaming.md`
for the engine's lifecycle constraints — engines are never deallocated, init failures are
process-fatal by design).
- `swift/Tests/AppleTTSTests/` — voice-specifier parsing and asset-discovery tests.
- **wyoming_apple_stt/** — Python Wyoming protocol server. Handles TCP connections from Home
Assistant. `stt.py` keeps a pool of pre-warmed `apple-stt --worker` processes; the handler
streams audio chunks into a worker session as they arrive, forwards partial transcripts as
`transcript-chunk` events, and emits the final transcript right after `audio-stop`. Any
streaming failure falls back to the buffered one-shot transcription path (audio is always
buffered in parallel).
Assistant. For STT, `stt.py` keeps a pool of pre-warmed `apple-stt --worker` processes
(mirroring the TTS pool design); the handler streams audio chunks into a worker session as
they arrive, forwards partial transcripts as `transcript-chunk` events, and emits the final
transcript right after `audio-stop`. Any streaming failure falls back to the buffered
one-shot transcription path (audio is always buffered in parallel). For TTS, `tts.py`
keeps a pool of pre-warmed `apple-tts` workers (acquire triggers a background replacement
spawn) and the handler serves both legacy `synthesize` and streaming
`synthesize-start/chunk/stop` with sentence-level incremental synthesis.
- **scripts/** — Install and uninstall scripts for the launchd service.
- **packaging/** — Release tooling: `build-release-tarball.sh` produces the
GitHub release artifact; `formula.rb.template` + `python-resources.rb` are
Expand Down Expand Up @@ -95,22 +106,42 @@ the user explicitly asks. Stage and commit decisions are always the user's to ma

## Releasing

Releases are tag-driven. To cut a new release:
Releases are tag-driven and split into two channels by the tag's shape. To cut a
**stable** release:

```bash
git tag v<major>.<minor>.<patch>
git push origin v<major>.<minor>.<patch>
```

To cut a **beta** release, add a `-beta.<n>` suffix:

```bash
git tag v<major>.<minor>.<patch>-beta.<n> # e.g. v1.2.0-beta.1
git push origin v<major>.<minor>.<patch>-beta.<n>
```

Both match the same `v*` trigger; the workflow branches on the `-beta` suffix.

The `.github/workflows/release.yml` workflow then:

1. Runs `make swift-test` and aborts on failure.
2. Builds the universal Swift binary via `packaging/build-release-tarball.sh` and
assembles `wyoming-apple-stt-<version>.tar.gz`.
3. Creates a GitHub release named after the tag and uploads the tarball as the
sole asset.
4. Renders `packaging/formula.rb.template` with the new version, URL, and sha256,
then pushes the resulting `Formula/wyoming-apple-stt.rb` to `FI-153/homebrew-tap`.
sole asset — marked as a **prerelease** for beta tags.
4. Renders `packaging/formula.rb.template` with the new version, URL, sha256, class
name, and a `conflicts_with` directive, then pushes the result to
`FI-153/homebrew-tap`. Stable tags write `Formula/wyoming-apple-stt.rb` (class
`WyomingAppleStt`); beta tags write a separate `Formula/wyoming-apple-stt-beta.rb`
(class `WyomingAppleSttBeta`), so the two channels coexist in the tap and never
overwrite each other.

The beta uses a `-beta` suffix rather than `@beta` because Homebrew derives a formula's
Ruby class name from its filename and only maps `@` to `AT` before a digit
(`python@3.12`), so `wyoming-apple-stt@beta` would be an invalid class. Users install the
beta with `brew install FI-153/tap/wyoming-apple-stt-beta`; the two formulae
`conflicts_with` each other, so only one channel is active at a time.

Requirements:

Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ VENV_DIR := .venv
VENV_PYTHON := $(VENV_DIR)/bin/python
VENV_PIP := $(VENV_DIR)/bin/pip
SWIFT_BIN := swift/.build/release/apple-stt
TTS_BIN := swift/.build/release/apple-tts
PORT ?= 10300
LANGUAGE ?= en

Expand All @@ -27,9 +28,9 @@ $(VENV_DIR)/bin/activate: requirements-dev.txt requirements.txt
$(VENV_PIP) install --quiet -r requirements-dev.txt
touch $(VENV_DIR)/bin/activate

build: $(SWIFT_BIN) ## Build the Swift CLI binary
build: $(SWIFT_BIN) ## Build the Swift CLI binaries

$(SWIFT_BIN): swift/Package.swift swift/Sources/AppleSTT/*.swift
$(SWIFT_BIN): swift/Package.swift swift/Sources/AppleSTT/*.swift swift/Sources/AppleTTS/*.swift
cd swift && swift build -c release
codesign -f -s - $(SWIFT_BIN)

Expand All @@ -43,20 +44,22 @@ quality: venv ## Run ruff linter and mypy type checker
$(VENV_DIR)/bin/ruff check wyoming_apple_stt/ tests/
$(VENV_DIR)/bin/mypy wyoming_apple_stt/

run-clean: venv ## Rebuild Swift binary and start server
rm -f $(SWIFT_BIN)
run-clean: venv ## Rebuild Swift binaries and start server
rm -f $(SWIFT_BIN) $(TTS_BIN)
cd swift && swift build -c release
codesign -f -s - $(SWIFT_BIN)
$(VENV_PYTHON) -m wyoming_apple_stt \
--uri tcp://0.0.0.0:$(PORT) \
--apple-stt-bin $(SWIFT_BIN) \
--apple-tts-bin $(TTS_BIN) \
--language $(LANGUAGE) \
--debug

run: venv build ## Run the server locally (Ctrl+C to stop)
$(VENV_PYTHON) -m wyoming_apple_stt \
--uri tcp://0.0.0.0:$(PORT) \
--apple-stt-bin $(SWIFT_BIN) \
--apple-tts-bin $(TTS_BIN) \
--language $(LANGUAGE) \
--debug

Expand Down
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Wyoming Apple STT

On-device speech-to-text for Home Assistant, powered by Apple's Speech framework.
On-device speech-to-text **and Siri text-to-speech** for Home Assistant, powered by
Apple's Speech framework and the Siri speech synthesizer.
Every word stays on your Mac: no cloud, no API key, no usage limits, full privacy.

<img src="https://github.com/user-attachments/assets/a66196c6-065c-44d0-a381-12261da7d0c8" />
Expand Down Expand Up @@ -35,6 +36,55 @@ so concurrent utterances never wait for model initialization. If the streaming p
for any reason, the server transparently falls back to buffered one-shot transcription of
the same utterance — no audio is lost.

## Text-to-speech (Siri voices) 🗣️

The server also exposes the Mac's Siri voices as a Wyoming TTS service with **streaming
synthesis**: audio starts flowing to Home Assistant as soon as the first samples are
generated, sentence by sentence, instead of waiting for the whole reply. To keep latency
near zero, a synthesis engine is pre-warmed in an idle worker process at all times — when a
request arrives it starts speaking immediately while a replacement engine spins up in the
background for concurrent requests.

Only voices that macOS manages itself are offered, because they always match the system's
Siri engine. macOS only keeps a *full* voice bundle on disk for a voice you've actually
selected — the language's other voice slots stay as tiny preview-only resource bundles
until you switch to them, so each voice you want available has to be selected at least
once:

1. Open **System Settings → Siri → Siri Voice** (or **Accessibility → Spoken Content →
System Voice**), pick the language, then select **each voice slot you want** (e.g.
*Voice 1*/German "Martin" and *Voice 2*/German "Helena" are separate downloads) and let
it finish downloading. You can select a different voice afterwards as your live Siri
voice — once downloaded, the bundle stays and stays usable by this server regardless of
which one is currently active.
2. Restart the server. The voices appear automatically in Home Assistant's voice picker
(run `swift/.build/release/apple-tts --list-voices` to check what the server currently
sees without restarting anything).

If no Siri voice is installed, the server logs a warning and runs STT-only. TTS can also be
turned off explicitly with `--no-tts` (via `EXTRA_ARGS`).

Useful `EXTRA_ARGS` flags: `--tts-voice <name>` (default voice), `--tts-rate 1.2`
(speaking speed), `--tts-idle-workers 2` (more pre-warmed engines), `--no-tts`.

### Concurrency model

Each in-flight synthesis runs in its own `apple-tts` worker process, so requests never
queue behind each other. Beyond the pre-warmed pool (`--tts-idle-workers`, default 1), a
worker is spawned on demand for every concurrent request with no upper limit — the pool
only bounds how many engines are kept *pre-warmed*, not how many can run at once. A worker
that finishes while the pool already has enough idle workers is torn down immediately;
there's no idle timeout — surplus workers aren't kept around "just in case," and the
`idle_target` workers that are kept live until the server stops.

In practice this scales with the Mac's CPU: tested on an 8-core Mac mini, 1–80 concurrent
requests all completed successfully (no errors, no dropped connections) at roughly 55 MB
resident memory per active worker. Latency stays near-instant (first audio in under
100 ms) up to about as many concurrent requests as physical cores; beyond that, requests
queue for CPU time and first-audio latency grows roughly linearly (e.g. ~3–11s at 80
concurrent requests on 8 cores). This comfortably covers realistic Home Assistant usage
(one or a handful of simultaneous voice satellites); it isn't tuned for large numbers of
simultaneous conversations on constrained hardware.

## Install (Homebrew) 🍺

Expand Down
2 changes: 2 additions & 0 deletions com.wyoming-apple-stt.plist.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string>tcp://0.0.0.0:__PORT__</string>
<string>--apple-stt-bin</string>
<string>__APPLE_STT_BIN__</string>
<string>--apple-tts-bin</string>
<string>__APPLE_TTS_BIN__</string>
<string>--language</string>
<string>__LANGUAGE__</string>
</array>
Expand Down
32 changes: 18 additions & 14 deletions packaging/build-release-tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@ DIST_DIR="${REPO_DIR}/dist"
STAGE_DIR="${DIST_DIR}/wyoming-apple-stt-${VERSION}"
TARBALL="${DIST_DIR}/wyoming-apple-stt-${VERSION}.tar.gz"

echo "==> Building universal Swift binary"
echo "==> Building universal Swift binaries"
cd "${REPO_DIR}/swift"
swift build -c release --arch arm64 --arch x86_64
BIN_PATH="$(swift build -c release --arch arm64 --arch x86_64 --show-bin-path)/apple-stt"

echo "==> Verifying binary is universal"
ARCHS="$(lipo -archs "${BIN_PATH}")"
if [[ "${ARCHS}" != *"arm64"* ]] || [[ "${ARCHS}" != *"x86_64"* ]]; then
echo "ERROR: expected universal binary, got: ${ARCHS}" >&2
exit 1
fi
echo " archs: ${ARCHS}"
BUILD_DIR="$(swift build -c release --arch arm64 --arch x86_64 --show-bin-path)"

echo "==> Verifying binaries are universal"
for binary in apple-stt apple-tts; do
ARCHS="$(lipo -archs "${BUILD_DIR}/${binary}")"
if [[ "${ARCHS}" != *"arm64"* ]] || [[ "${ARCHS}" != *"x86_64"* ]]; then
echo "ERROR: expected universal ${binary}, got: ${ARCHS}" >&2
exit 1
fi
echo " ${binary} archs: ${ARCHS}"
done

echo "==> Staging tarball contents at ${STAGE_DIR}"
rm -rf "${STAGE_DIR}" "${TARBALL}"
mkdir -p "${STAGE_DIR}"
cp "${BIN_PATH}" "${STAGE_DIR}/apple-stt"
# Re-sign so the embedded Info.plist (speech-recognition usage description) is
# bound into the signature; the linker's ad-hoc signature leaves it unbound and
# TCC then aborts the process on first SFSpeechRecognizer authorization request.
cp "${BUILD_DIR}/apple-stt" "${STAGE_DIR}/apple-stt"
cp "${BUILD_DIR}/apple-tts" "${STAGE_DIR}/apple-tts"
# Re-sign apple-stt so the embedded Info.plist (speech-recognition usage
# description) is bound into the signature; the linker's ad-hoc signature leaves
# it unbound and TCC then aborts the process on first SFSpeechRecognizer
# authorization request. apple-tts uses no speech-recognition entitlement.
codesign -f -s - "${STAGE_DIR}/apple-stt"
cp -R "${REPO_DIR}/wyoming_apple_stt" "${STAGE_DIR}/wyoming_apple_stt"
cp "${REPO_DIR}/pyproject.toml" "${STAGE_DIR}/pyproject.toml"
Expand Down
10 changes: 8 additions & 2 deletions packaging/formula.rb.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class WyomingAppleStt < Formula
class {{CLASS}} < Formula
include Language::Python::Virtualenv

desc "Wyoming protocol STT server backed by Apple's Speech framework"
Expand All @@ -8,13 +8,16 @@ class WyomingAppleStt < Formula
sha256 "{{SHA256}}"
license "MIT"

depends_on "python@3.13"
depends_on macos: :sequoia
depends_on "python@3.13"

{{CONFLICTS}}

{{PYTHON_RESOURCES}}

def install
bin.install "apple-stt"
bin.install "apple-tts"
virtualenv_install_with_resources

conf = etc/"wyoming-apple-stt.conf"
Expand Down Expand Up @@ -43,6 +46,7 @@ class WyomingAppleStt < Formula
--uri "tcp://0.0.0.0:${PORT}" \\
--language "${LANGUAGE}" \\
--apple-stt-bin "#{bin}/apple-stt" \\
--apple-tts-bin "#{bin}/apple-tts" \\
${EXTRA_ARGS}
EOS
chmod 0755, libexec/"wyoming-apple-stt-run"
Expand All @@ -58,6 +62,8 @@ class WyomingAppleStt < Formula
test do
output = shell_output("#{bin}/apple-stt --list-languages")
assert_match(/"en"/, output)
tts_output = shell_output("#{bin}/apple-tts --list-voices")
assert_match(/\A\[/, tts_output)
system libexec/"bin/python", "-c", "import wyoming_apple_stt"
end
end
Loading
Loading