realhood / assemblyai-realtime
PHP package for AssemblyAI real-time streaming with Lemur support
dev-main
2024-12-15 15:30 UTC
Requires
- php: >=7.4
- ext-json: *
- guzzlehttp/guzzle: ^7.0
- ratchet/pawl: ^0.4.1
- react/event-loop: ^1.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2025-06-11 13:17:42 UTC
README
A comprehensive PHP package for real-time transcription and Lemur integration with AssemblyAI. This package provides a robust implementation for real-time audio transcription and AI-powered analysis using AssemblyAI's WebSocket API and Lemur capabilities.
Features
- ๐๏ธ Real-time audio transcription
- ๐ค Lemur AI integration for advanced analysis
- ๐ Support for multiple Lemur tasks (summarization, Q&A, action items)
- ๐ WebSocket-based streaming with automatic reconnection
- โก Efficient audio processing and chunking
- ๐ ๏ธ Comprehensive error handling
- ๐งช Full test coverage
Requirements
- PHP 7.4 or higher
- Composer
- AssemblyAI API key
Installation
composer require realhood/assemblyai-realtime
Quick Start
use AssemblyAIRealtime\Client\AssemblyAIClient; use AssemblyAIRealtime\Config\Configuration; // Initialize client with Lemur $config = new Configuration([ 'lemur' => [ 'enabled' => true, 'task' => 'summarize', 'prompt' => 'Provide a brief summary' ] ]); $client = new AssemblyAIClient('your-api-key', $config); // Handle transcription results $messageHandler = function($result) { switch ($result['type']) { case 'partial': echo "Partial: {$result['text']}\n"; break; case 'final': echo "Final: {$result['text']}\n"; break; case 'lemur': echo "Lemur: {$result['response']}\n"; break; } }; // Start transcription $client->startRealTimeTranscription($messageHandler); // Send audio data $client->sendAudioChunk($audioData); // Stop when done $client->stop();
Advanced Usage
Audio Processing
use AssemblyAIRealtime\Utils\AudioUtils; // Validate audio format if (AudioUtils::validateAudioFormat($audioPath)) { // Get audio duration $duration = AudioUtils::getAudioDuration($audioPath); // Convert and process audio $chunks = AudioUtils::convertAudioToFormat($audioPath); foreach ($chunks as $chunk) { $client->sendAudioChunk($chunk); usleep(20000); // 20ms delay } }
Lemur Integration
use AssemblyAIRealtime\Utils\LemurUtils; // Create Lemur configuration $lemurConfig = LemurUtils::createLemurConfig( 'summarize', 'Provide a detailed summary' ); // Available Lemur tasks $tasks = [ 'summarize', 'question_answer', 'action_items', 'key_points' ];
Error Handling
try { $client->startRealTimeTranscription($handler); } catch (AssemblyAIException $e) { echo "AssemblyAI Error: " . $e->getMessage(); } catch (TranscriptionException $e) { echo "Transcription Error: " . $e->getMessage(); } catch (LemurException $e) { echo "Lemur Error: " . $e->getMessage(); }
Testing
Run the test suite:
./vendor/bin/phpunit
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.
Credits
Created and maintained by Reza Aleyasin.