{"id":47718014,"url":"https://github.com/crazy-goat/piper-php","last_synced_at":"2026-04-05T22:00:38.374Z","repository":{"id":348118631,"uuid":"1196577822","full_name":"crazy-goat/piper-php","owner":"crazy-goat","description":"PHP text-to-speech library using Piper TTS via FFI — streaming audio, warm-up support, 40+ languages, zero dependencies","archived":false,"fork":false,"pushed_at":"2026-03-31T07:46:43.000Z","size":1099,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-03T05:07:57.810Z","etag":null,"topics":["audio","ffi","machine-learning","neural-tts","no-dependencies","onnx-runtime","php","php-library","piper","piper-tts","speech-synthesis","streaming-audio","text-to-speech","tts"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crazy-goat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-30T20:45:02.000Z","updated_at":"2026-04-01T09:25:52.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/crazy-goat/piper-php","commit_stats":null,"previous_names":["crazy-goat/piper-php"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/crazy-goat/piper-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazy-goat%2Fpiper-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazy-goat%2Fpiper-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazy-goat%2Fpiper-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazy-goat%2Fpiper-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crazy-goat","download_url":"https://codeload.github.com/crazy-goat/piper-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazy-goat%2Fpiper-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31374051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","ffi","machine-learning","neural-tts","no-dependencies","onnx-runtime","php","php-library","piper","piper-tts","speech-synthesis","streaming-audio","text-to-speech","tts"],"created_at":"2026-04-02T19:07:47.169Z","updated_at":"2026-04-03T20:01:15.954Z","avatar_url":"https://github.com/crazy-goat.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Piper PHP\n\nText-to-speech in PHP using [Piper](https://github.com/OHF-Voice/piper1-gpl) via FFI.\n\n[![PHP Version](https://img.shields.io/badge/php-%3E%3D8.2-8892BF.svg)](https://php.net/)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nFast, local text-to-speech synthesis without external services. Piper runs entirely on your machine using ONNX Runtime.\n\n## Features\n\n- 🚀 **Fast** - Local synthesis, no network latency\n- 🔊 **High quality** - Uses Piper neural TTS models\n- 📦 **Easy installation** - Composer package with FFI\n- 🎯 **Simple API** - Load model once, synthesize many times\n- ⚡ **Warm-up support** - Avoid first-chunk delay in production\n- 🔄 **Streaming** - Generate audio chunk by chunk for real-time playback\n\n## Requirements\n\n- PHP \u003e= 8.2 with FFI extension enabled\n- Piper library (libpiper.so) and ONNX Runtime\n- Voice models (.onnx files)\n\n## Installation\n\n```bash\ncomposer require crazy-goat/piper-php\n\n# Download pre-built libraries\nvendor/bin/piper-tts install-deps\n```\n\nThis will download and extract to `vendor/crazy-goat/piper-php/libs/`:\n- `libpiper.so` - Piper library\n- `libonnxruntime.so` - ONNX Runtime  \n- `espeak-ng-data/` - Phoneme data\n\n### Manual Download\n\nIf you prefer to download manually or need a specific version:\n\n```bash\n# Download individual libraries\nwget https://github.com/crazy-goat/piper-php/releases/latest/download/libpiper-linux-x86_64.tar.gz\nwget https://github.com/crazy-goat/piper-php/releases/latest/download/libonnxruntime-linux-x86_64.tar.gz\nwget https://github.com/crazy-goat/piper-php/releases/latest/download/espeak-ng-data.tar.gz\n\n# Extract\ntar -xzf libpiper-linux-x86_64.tar.gz\ntar -xzf libonnxruntime-linux-x86_64.tar.gz\ntar -xzf espeak-ng-data.tar.gz\n```\n\n### Building from Source\n\nIf you prefer to build from source or need a different architecture:\n\n```bash\n# Clone with submodules\ngit clone --recursive https://github.com/crazy-goat/piper-php.git\ncd piper-php\n\n# Or initialize submodules if already cloned\ngit submodule update --init --recursive\n\n# Build libpiper and copy to libs/ (like composer does)\nmake build-libs\n\n# Or build everything including espeakbridge\nmake build-piper1\n```\n\nThe build will create:\n- `libs/libpiper.so` - Piper library (copied to project root)\n- `libs/libonnxruntime.so` - ONNX Runtime (with all versioned files)\n- `libs/espeak-ng-data/` - Phoneme data\n\n### Running Examples Locally\n\nIf you're developing locally (not via composer), build libraries and run examples:\n\n```bash\n# Build libraries and copy to libs/ directory\nmake examples\n\n# Download a voice model\n./bin/piper-tts download en_US-lessac-medium ./models\n\n# Run example\nphp examples/speak.php \"Hello world\"\n```\n\nThis is equivalent to running `vendor/bin/piper-tts install-deps` for composer users.\n\n### Downloading Voice Models\n\nUse the included CLI tool to download voices from HuggingFace:\n\n```bash\n# List available voices\n./bin/piper-tts list\n\n# Filter by language\n./bin/piper-tts list --language=pl\n\n# Download a voice\n./bin/piper-tts download en_US-lessac-medium ./models\n\n# List installed voices\n./bin/piper-tts installed ./models\n```\n\nOr download manually from [HuggingFace](https://huggingface.co/rhasspy/piper-voices/tree/main).\n\n## Quick Start\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nuse CrazyGoat\\PiperTTS\\PiperTTS;\n\n// Libraries are auto-detected from vendor/crazy-goat/piper-php/libs/\n// (run: vendor/bin/piper-tts install-deps to download)\n$piper = new PiperTTS(modelsPath: __DIR__ . '/models');\n\n// Load voice with automatic warm-up (recommended for production)\n$model = $piper-\u003eloadModel('en_US-lessac-medium', warmUp: true);\n\n// Synthesize text to WAV\n$wav = $model-\u003espeak('Hello! This is Piper text to speech in PHP.');\nfile_put_contents('output.wav', $wav);\n```\n\n### Custom Library Paths (Optional)\n\nIf you need to use custom library locations:\n\n```php\n$piper = new PiperTTS(\n    modelsPath:     __DIR__ . '/models',\n    libpiperPath:   '/custom/path/libpiper.so',      // optional\n    onnxrtPath:     '/custom/path/libonnxruntime.so', // optional  \n    espeakDataPath: '/custom/path/espeak-ng-data',    // optional\n);\n```\n\n## API Reference\n\n### PiperTTS\n\nMain factory class for loading models.\n\n```php\n$piper = new PiperTTS(\n    modelsPath:     '/path/to/models',           // Directory with .onnx files\n    libpiperPath:   '/path/to/libpiper.so',      // Optional: auto-detected if null\n    onnxrtPath:     '/path/to/libonnxruntime.so', // Optional: auto-detected if null\n    espeakDataPath: '/path/to/espeak-ng-data',    // Optional: auto-detected if null\n);\n```\n\n#### Methods\n\n- `loadModel(string $voice, bool $warmUp = false): LoadedModel` - Load a voice model\n- `voices(): VoiceInfo[]` - List available voices in models directory\n\n### LoadedModel\n\nRepresents a loaded voice model. Reuse this instance for multiple synthesis calls.\n\n#### Methods\n\n- `speak(string $text, float $speed = 1.0, int $speakerId = 0): string` - Synthesize to WAV\n- `speakStreaming(string $text, float $speed = 1.0, int $speakerId = 0): \\Generator` - Stream chunks\n- `warmUp(): int` - Warm up the model, returns time in milliseconds\n- `free(): void` - Explicitly free resources (called automatically in destructor)\n\n### Speed Control\n\nAdjust speech speed with the `speed` parameter:\n\n```php\n// 2x faster\n$fast = $model-\u003espeak('Hello world', speed: 2.0);\n\n// 0.5x slower (half speed)\n$slow = $model-\u003espeak('Hello world', speed: 0.5);\n```\n\n### Streaming\n\nFor real-time applications, use streaming to get audio chunks as they're generated:\n\n```php\nforeach ($model-\u003espeakStreaming('First sentence. Second sentence.') as $chunk) {\n    // $chunk-\u003epcmData - Raw 16-bit PCM audio\n    // $chunk-\u003esampleRate - Sample rate (e.g., 22050)\n    // $chunk-\u003eisLast - True if this is the final chunk\n    \n    // Send to audio player, WebSocket, etc.\n    $player-\u003eplay($chunk-\u003epcmData);\n}\n```\n\n## Production Tips\n\n### Warm-up\n\nThe first inference in ONNX Runtime is slow (~900ms) due to initialization. Use warm-up to avoid this delay:\n\n```php\n// Option 1: Auto warm-up on load (recommended)\n$model = $piper-\u003eloadModel('voice', warmUp: true);\n\n// Option 2: Manual warm-up with timing\n$model = $piper-\u003eloadModel('voice');\n$ms = $model-\u003ewarmUp();\necho \"Warmed up in {$ms}ms\";\n```\n\n### Reuse Models\n\nLoad the model once and reuse for multiple synthesis calls:\n\n```php\n// Good: Load once, use many times\n$model = $piper-\u003eloadModel('en_US-lessac-medium', warmUp: true);\n\nforeach ($texts as $text) {\n    $wav = $model-\u003espeak($text);\n    // ...\n}\n\n// Bad: Loading model on every request (slow!)\nforeach ($texts as $text) {\n    $model = $piper-\u003eloadModel('en_US-lessac-medium');  // Don't do this\n    $wav = $model-\u003espeak($text);\n}\n```\n\n### Long-Running Processes\n\nFor daemons or workers, load models at startup:\n\n```php\n// At application startup\n$piper = new PiperTTS('/path/to/models');\n$voiceCache = [];\n\nfunction getVoice($piper, $voiceKey) {\n    global $voiceCache;\n    if (!isset($voiceCache[$voiceKey])) {\n        $voiceCache[$voiceKey] = $piper-\u003eloadModel($voiceKey, warmUp: true);\n    }\n    return $voiceCache[$voiceKey];\n}\n\n// In request handler\n$model = getVoice($piper, 'en_US-lessac-medium');\n$wav = $model-\u003espeak($userText);\n```\n\n## Examples\n\nSee the `examples/` directory:\n\n- `speak.php` - Basic text-to-speech with timing\n- `stream.php` - Streaming synthesis with per-chunk timing\n- `warmup.php` - Manual warm-up demonstration\n- `autowarmup.php` - Automatic warm-up on model load\n\nRun examples:\n\n```bash\nphp examples/speak.php \"Hello world\"\nphp examples/stream.php \"First sentence. Second sentence.\"\nphp examples/autowarmup.php \"Test text\"\n```\n\n## Performance\n\nTypical performance on modern CPU:\n\n| Operation | Time |\n|-----------|------|\n| Model loading | ~900ms |\n| Warm-up | ~70ms |\n| Synthesis (after warm-up) | ~70-150ms per sentence |\n| First chunk (without warm-up) | ~900ms |\n| First chunk (with warm-up) | ~70ms |\n\n## Troubleshooting\n\n### FFI extension not found\n\nEnable FFI in your `php.ini`:\n\n```ini\nextension=ffi\n```\n\n### Library not found errors\n\nSpecify full paths to libraries in the PiperTTS constructor:\n\n```php\n$piper = new PiperTTS(\n    modelsPath:     '/full/path/to/models',\n    libpiperPath:   '/full/path/to/libpiper.so',\n    onnxrtPath:     '/full/path/to/libonnxruntime.so',\n    espeakDataPath: '/full/path/to/espeak-ng-data',\n);\n```\n\n### ONNX Runtime errors\n\nMake sure all library dependencies are available:\n\n```bash\n# Check library dependencies\nldd /path/to/libonnxruntime.so\nldd /path/to/libpiper.so\n```\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file.\n\n## Credits\n\n- [Piper](https://github.com/rhasspy/piper) - Fast, local neural text-to-speech\n- [ONNX Runtime](https://onnxruntime.ai/) - Cross-platform ML inference\n- [espeak-ng](https://github.com/espeak-ng/espeak-ng) - Text-to-phoneme conversion\n\n## Contributing\n\nContributions welcome! Please submit issues and pull requests on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrazy-goat%2Fpiper-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrazy-goat%2Fpiper-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrazy-goat%2Fpiper-php/lists"}