|
| 1 | +# GitHub Copilot Instructions |
| 2 | + |
| 3 | +## Project Context |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +## Code Style and Conventions |
| 8 | + |
| 9 | +- Use async/await patterns for all I/O operations |
| 10 | +- Follow Python type hints for function signatures |
| 11 | +- Maintain consistency with existing error handling patterns |
| 12 | +- Use logging for debugging and error messages |
| 13 | +- Keep functions focused and modular |
| 14 | + |
| 15 | +## Architecture Overview |
| 16 | + |
| 17 | +### Core Components |
| 18 | + |
| 19 | +- **`handler.py`**: Contains `OpenAIEventHandler` - the main Wyoming protocol event handler that processes ASR and TTS requests |
| 20 | +- **`compatibility.py`**: Provides `CustomAsyncOpenAI` class with backend detection and OpenAI API compatibility layer |
| 21 | +- **`__main__.py`**: Entry point with argument parsing and server initialization |
| 22 | +- **`utilities.py`**: Helper functions for audio processing and data handling |
| 23 | +- **`const.py`**: Version constants and configuration |
| 24 | + |
| 25 | +### Key Patterns |
| 26 | + |
| 27 | +1. **Async Event Handling**: Uses Wyoming's `AsyncEventHandler` to process incoming protocol events |
| 28 | +2. **Backend Abstraction**: `CustomAsyncOpenAI` wraps different backends (OpenAI, Speaches, LocalAI, etc.) with a unified interface |
| 29 | +3. **Stream Processing**: Handles both streaming and non-streaming transcription modes |
| 30 | +4. **Audio Buffer Management**: Collects audio chunks into complete files for processing |
| 31 | + |
| 32 | +### Wyoming Protocol Events |
| 33 | + |
| 34 | +The handler processes these Wyoming events: |
| 35 | +- `AudioStart/AudioChunk/AudioStop` → STT transcription |
| 36 | +- `Transcribe` → Initiate transcription request |
| 37 | +- `Synthesize` → TTS audio generation |
| 38 | + |
| 39 | +### Supported Backends |
| 40 | + |
| 41 | +The `OpenAIBackend` enum defines supported backends: |
| 42 | +- `OPENAI`: Official OpenAI API |
| 43 | +- `SPEACHES`: Local Speaches service |
| 44 | +- `LOCALAI`: LocalAI service |
| 45 | +- `KOKORO_FASTAPI`: Kokoro TTS service |
| 46 | + |
| 47 | +## Testing Guidelines |
| 48 | + |
| 49 | +When writing tests: |
| 50 | +- Use pytest fixtures for common setup |
| 51 | +- Mock external API calls |
| 52 | +- Test both success and error scenarios |
| 53 | +- Include integration tests for end-to-end flows |
| 54 | +- Aim for high code coverage |
| 55 | + |
| 56 | +Test files are organized by module: |
| 57 | +- `test_handler.py`: Event handler logic |
| 58 | +- `test_compatibility.py`: Backend compatibility |
| 59 | +- `test_utilities.py`: Helper functions |
| 60 | +- `test_integration.py`: End-to-end scenarios |
| 61 | + |
| 62 | +## Common Development Tasks |
| 63 | + |
| 64 | +### Running Tests |
| 65 | +```bash |
| 66 | +pytest # Run all tests |
| 67 | +pytest --cov=wyoming_openai # With coverage |
| 68 | +pytest tests/test_handler.py # Specific test file |
| 69 | +``` |
| 70 | + |
| 71 | +### Code Quality |
| 72 | +```bash |
| 73 | +ruff check . # Run linting |
| 74 | +ruff check . --fix # Auto-fix issues |
| 75 | +``` |
| 76 | + |
| 77 | +### Local Development |
| 78 | +```bash |
| 79 | +pip install -e ".[dev]" # Install dev dependencies |
| 80 | +python -m wyoming_openai --uri tcp://0.0.0.0:10300 --stt-models whisper-1 --tts-models tts-1 |
| 81 | +``` |
| 82 | + |
| 83 | +### Docker Development |
| 84 | +```bash |
| 85 | +docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build |
| 86 | +``` |
| 87 | + |
| 88 | +## Configuration |
| 89 | + |
| 90 | +The server accepts both command-line arguments and environment variables. When suggesting configuration changes, consider: |
| 91 | +- STT/TTS API keys and URLs |
| 92 | +- Model lists for STT and TTS |
| 93 | +- Voice configurations |
| 94 | +- Backend-specific settings (temperature, speed, etc.) |
| 95 | + |
| 96 | +## When Making Changes |
| 97 | + |
| 98 | +- Ensure backward compatibility with existing Wyoming clients |
| 99 | +- Update tests to reflect new functionality |
| 100 | +- Add appropriate logging for debugging |
| 101 | +- Document new configuration options |
| 102 | +- Consider impact on all supported backends |
| 103 | +- Validate audio format conversions maintain quality |
0 commit comments