spark-backend-pattern
/spark-backend-pattern
Dodaje lub zmienia wymienny backend w Spark, takie jak rozpoznawanie mowy, TTS czy VAD, z rejestrem i testami.
- Autor
- contextuai ↗
- Repozytorium
- hey-spark ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 31.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 31.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Dodaje lub zmienia wymienny backend w Spark, takie jak rozpoznawanie mowy, TTS czy VAD, z rejestrem i testami.
Oryginalny opis (EN)
How to add or modify a swappable backend in Spark (wake word, VAD, STT, TTS, brain, audio I/O) — ABC in interfaces.py, registry entry, lazy imports, config schema, doctor check, and tests. Use whenever creating or changing any file under spark/wakeword, spark/vad, spark/stt, spark/tts, spark/brain/claude_agent.py, or spark/registry.py.
Jak działa
- 1. Interface (spark/interfaces.py)
- 2. Module
- 3. Registry (spark/registry.py)
- 4. Config (spark/config.py + config.yaml)
- 5. Doctor (spark/doctor.py)
- 6. Tests
Podgląd SKILL.md
---
name: spark-backend-pattern
description: How to add or modify a swappable backend in Spark (wake word, VAD, STT, TTS, brain, audio I/O) — ABC in interfaces.py, registry entry, lazy imports, config schema, doctor check, and tests. Use whenever creating or changing any file under spark/wakeword, spark/vad, spark/stt, spark/tts, spark/brain/claude_agent.py, or spark/registry.py.
---
# Adding a Spark backend
Backends must be swappable **by editing `config.yaml` alone** (Phase 1 acceptance). Follow all six steps.
## 1. Interface (`spark/interfaces.py`)
The ABCs already exist (or create them exactly like this):
```python
class WakeWordDetector(ABC):
frame_length: int # samples @16k this detector consumes
@abstractmethod
def process(self, frame: np.ndarray) -> bool: ...
def reset(self) -> None: ...
def close(self) -> None: ...
class VAD(ABC):
frame_length: int = 512
@abstractmethod
def is_speech(self, frame: np.ndarray) -> bool: ...
def reset(self) -> None: ...
class STT(ABC):
async def warmup(self) -> None: ...
@abstractmethod
async def transcribe(self, pcm: np.ndarray) -> str: ...
class TTS(ABC):
async def warmup(self) -> None: ...
@abstractmethod
async def speak(self, text_chunks: AsyncIterator[str]) -> None: ...
@abstractmethod
async def stop(self) -> None: ...
class Brain(ABC):
@abstractmethod
def respond(self, text: str) -> AsyncIterator[str]: ...
async def reset(self) -> None: ...
async def close(self) -> None: ...
class BackendUnavailable(RuntimeError):
def __init__(self, backend: str, reason: str, fix: str): ...
```
Don't change a signature without updating every backend, fake, and test in the same commit.
## 2. Module
`spark/<kind>/<name>.py`: one class. Import heavy libraries **inside `__init__`**, and convert an ImportError or a missing file/key into `BackendUnavailable(backend, reason, fix)`, where `fix` is a copy-pasteable command.
## 3. Registry (`spark/registry.py`)
```python
REGISTRY = {
"stt": {"faster_whisper": "spark.stt.faster_whisper:FasterWhisperSTT",
"deepgram": "spark.stt.deepgram:DeepgramSTT"},
...
}
def build(kind: str, cfg: Settings, **deps) -> Any # importlib by dotted path
```
Registration uses a string path, so nothing is imported until selected. The app calls `build(...)` only.
## 4. Config (`spark/config.py` + `config.yaml`)
Add a pydantic sub-model `<Name>Config` under `stt.options.<name>` (etc.), with defaults that match the spec. Selection key: `stt.backend: faster_whisper`. Env overrides use the prefix `SPARK_` with the `__` delimiter. Document every new key with a comment in `config.yaml`.
## 5. Doctor (`spark/doctor.py`)
Add a check: try constructing the backend (or just verify the file, key, and import) and print ✔ or ✖ with `fix`. The doctor never crashes; it collects every result.
## 6. Tests
- Registry test: every registry entry resolves to a class that subclasses the right ABC (import only if the dependency is installed, otherwise assert the dotted path is well-formed).
- A backend-specific test that skips with a reason if the model or dependency is missing.
- A swap test: build the app from two configs that differ only in `stt.backend`/`tts.backend` (using fake backends registered for the test) and assert the right classes were built. That proves "swap without code changes".
Wersje
W bazie nie ma innych skilli o nazwie spark-backend-pattern.
Migawka bazy z 13.11.2026 · wersja paczki a7434994dbe7 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100arn-spark-report
Diagnozuje problem z workflow Arness Spark i zakłada zgłoszenie w repozytorium wtyczki na GitHubie. - 90spark-audio-fixtures
Generuje sztuczne pliki audio do testów asystenta głosowego: słowa wybudzające, polecenia, ciszę i szum, bez nagrywania człowieka. - 100spark-quality-gate
Określa, co znaczy zielone dla Spark: lint, formatowanie, higiena importów i testy, a także jak diagnozować błędy przed commitem. - 86spark
Pomaga w obliczeniach Spark: zapytaniach Spark SQL, Structured Streaming, RDD i przetwarzaniu dużych danych. - 96parallel-task-spark
Prawdopodobnie uruchamia równoległe wykonanie zadań w wariancie spark po jawnym poleceniu /parallel-task-spark. - 100spark-job-creator
Prawdopodobnie tworzy zadania Spark do potoków danych, pomagając budować joby przetwarzania w ramach kategorii Data Pipelines.