caraxes / speech-texter
A Laravel package for speech-to-text processing.
README
SpeechTexter is a Laravel package that simplifies speech-to-text processing by integrating with external services. This package provides an easy way to store, manage, and retrieve transcribed audio files while allowing full flexibility in configuring dependencies such as user and file models.
🚀 Features
- Seamless speech-to-text integration
- Configurable API endpoints
- Dynamic model binding for User and File
- Supports Laravel migrations and service providers
- Queued job processing for speech recognition requests
- Storage support for temporary and persistent audio files
- Validation for user inputs and API requests
📞 External Service
This package integrates with the ussistant speech recognition service for Persian language support. If you intend to use this package for Persian speech-to-text conversion, please refer to the API documentation and services provided by ussistant.
📦 Installation
You can install this package via Composer:
composer require caraxes/speech-texter
After installation, publish the package configuration:
php artisan vendor:publish --tag=speech-texter-config
Example config/speech-texter.php
:
return [ 'api_key' => env('SPEECH_TEXTER_X_API_KEY'), 'voice_api' => env('SPEECH_TEXTER_VOICE_API'), 'prefix' => 'speech-texter', 'user_model' => env('SPEECH_TEXTER_USER_MODEL', 'App\Models\User'), 'file_model' => env('SPEECH_TEXTER_FILE_MODEL', 'App\Models\File'), ];
🔧 Usage
1️⃣ Storing a Speech-to-Text Request
To store a new request, simply create a new SpeechTexter
model instance:
use SpeechTexter\Models\SpeechTexter; $record = SpeechTexter::create([ 'user_id' => auth()->id(), 'file_id' => $fileId, 'file_url' => $fileUrl, 'file' => $fileData, 'result' => json_encode($transcriptionResult), 'response_status_code' => 200, ]);
2️⃣ Retrieving Speech-to-Text Results
To get the transcribed result of a specific file:
$record = SpeechTexter::find($id); echo $record->result;
3️⃣ Handling Speech-to-Text Requests in the Repository
use SpeechTexter\Repositories\SpeechTexterRepository; $speechTexterRepo = new SpeechTexterRepository(); $response = $speechTexterRepo->speechToText($userId, $fileId, [ 'file' => $uploadedFile, ]);
4️⃣ Accessing Related Models
$user = $record->user; $file = $record->file;
5️⃣ Validating Inputs
use SpeechTexter\Validators\SpeechTexterValidator; $validator = new SpeechTexterValidator(); $validator->validate($data);
⚙️ Service Provider
Make sure Laravel detects the service provider automatically:
'providers' => [ SpeechTexter\Providers\SpeechTexterServiceProvider::class, ],
🏗 Running Migrations
php artisan migrate
🏗 Queue Processing
To handle speech recognition requests asynchronously:
php artisan queue:work
🔍 Continuous Integration (CI) Tests
This package is tested automatically using GitHub Actions with the following checks:
- Code Quality: Static analysis with PHPStan (
level=2
) to ensure code correctness. - Dependency Management: Ensures all dependencies are installed and autoloaded correctly.
- Laravel Optimization: Caches configurations and optimizes performance.
- Database Migrations: Runs migrations to verify schema integrity.
- Queue Handling: Configures queue driver for synchronous execution.
These tests ensure the package remains stable and functional in Laravel 11 environments.
🔒 Security
- Do not expose your API key in the frontend.
- Use environment variables for API keys and secrets.
- Ensure your file uploads are properly sanitized to prevent security risks.
📝 License
This package is open-source and licensed under the MIT License.
🤝 Contributing
We welcome contributions! Feel free to submit pull requests and report issues in the GitHub repository.
📞 Support
For support, please open an issue on GitHub or contact me personally via email at amirmahdifor@gmail.com.