|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Wyoming OpenAI is a proxy middleware that bridges the Wyoming protocol with OpenAI-compatible endpoints for ASR (Automatic Speech Recognition) and TTS (Text-to-Speech) services. It enables Wyoming clients like Home Assistant to use various OpenAI-compatible STT/TTS services. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Testing |
| 12 | +```bash |
| 13 | +# Install development dependencies |
| 14 | +pip install -e ".[dev]" |
| 15 | + |
| 16 | +# Run all tests |
| 17 | +pytest |
| 18 | + |
| 19 | +# Run tests with coverage |
| 20 | +pytest --cov=wyoming_openai |
| 21 | + |
| 22 | +# Run specific test file |
| 23 | +pytest tests/test_handler.py |
| 24 | +``` |
| 25 | + |
| 26 | +### Code Quality |
| 27 | +```bash |
| 28 | +# Run linting with Ruff |
| 29 | +ruff check . |
| 30 | + |
| 31 | +# Auto-fix linting issues |
| 32 | +ruff check . --fix |
| 33 | +``` |
| 34 | + |
| 35 | +### Local Development Setup |
| 36 | +```bash |
| 37 | +# Install in editable mode |
| 38 | +pip install -e . |
| 39 | + |
| 40 | +# Run the server locally |
| 41 | +python -m wyoming_openai --uri tcp://0.0.0.0:10300 --stt-models whisper-1 --tts-models tts-1 |
| 42 | +``` |
| 43 | + |
| 44 | +### Docker Development |
| 45 | +```bash |
| 46 | +# Build and run development container |
| 47 | +docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build |
| 48 | + |
| 49 | +# With local services (e.g., Speaches) |
| 50 | +docker compose -f docker-compose.speaches.yml -f docker-compose.dev.yml up -d --build |
| 51 | +``` |
| 52 | + |
| 53 | +## Architecture |
| 54 | + |
| 55 | +### Core Components |
| 56 | + |
| 57 | +- **`handler.py`**: Contains `OpenAIEventHandler` - the main Wyoming protocol event handler that processes ASR and TTS requests |
| 58 | +- **`compatibility.py`**: Provides `CustomAsyncOpenAI` class with backend detection and OpenAI API compatibility layer |
| 59 | +- **`__main__.py`**: Entry point with argument parsing and server initialization |
| 60 | +- **`utilities.py`**: Helper functions for audio processing and data handling |
| 61 | +- **`const.py`**: Version constants and configuration |
| 62 | + |
| 63 | +### Key Architecture Patterns |
| 64 | + |
| 65 | +1. **Async Event Handling**: Uses Wyoming's `AsyncEventHandler` to process incoming protocol events |
| 66 | +2. **Backend Abstraction**: `CustomAsyncOpenAI` wraps different backends (OpenAI, Speaches, LocalAI, etc.) with a unified interface |
| 67 | +3. **Stream Processing**: Handles both streaming and non-streaming transcription modes |
| 68 | +4. **Audio Buffer Management**: Collects audio chunks into complete files for processing |
| 69 | + |
| 70 | +### Wyoming Protocol Flow |
| 71 | + |
| 72 | +The handler processes these Wyoming events: |
| 73 | +- `AudioStart/AudioChunk/AudioStop` → STT transcription |
| 74 | +- `Transcribe` → Initiate transcription request |
| 75 | +- `Synthesize` → TTS audio generation |
| 76 | + |
| 77 | +### Backend Support |
| 78 | + |
| 79 | +The `OpenAIBackend` enum defines supported backends: |
| 80 | +- `OPENAI`: Official OpenAI API |
| 81 | +- `SPEACHES`: Local Speaches service |
| 82 | +- `LOCALAI`: LocalAI service |
| 83 | +- `KOKORO_FASTAPI`: Kokoro TTS service |
| 84 | + |
| 85 | +## Configuration |
| 86 | + |
| 87 | +The server accepts both command-line arguments and environment variables. Key configuration includes: |
| 88 | +- STT/TTS API keys and URLs |
| 89 | +- Model lists for STT and TTS |
| 90 | +- Voice configurations |
| 91 | +- Backend-specific settings (temperature, speed, etc.) |
| 92 | + |
| 93 | +## Testing Strategy |
| 94 | + |
| 95 | +Tests are organized by module: |
| 96 | +- `test_handler.py`: Event handler logic |
| 97 | +- `test_compatibility.py`: Backend compatibility |
| 98 | +- `test_utilities.py`: Helper functions |
| 99 | +- `test_integration.py`: End-to-end scenarios |
0 commit comments