Installation
composer require afaya/edge-tts
Add the service provider to config/app.php:
'providers' => [
// ...
Afaya\EdgeTTS\EdgeTTSPackage::class,
],
First Use Case: Basic TTS Conversion
use Afaya\EdgeTTS\EdgeTTS;
$edgeTTS = new EdgeTTS();
$audio = $edgeTTS->textToSpeech('Hello, world!');
file_put_contents('output.mp3', $audio);
Where to Look First
php artisan edge-tts:help for command-line usage.php artisan vendor:publish --provider="Afaya\EdgeTTS\EdgeTTSPackage".Programmatic TTS
$edgeTTS = new EdgeTTS(['voice' => 'en-US-JennyNeural']);
$audio = $edgeTTS->textToSpeech('Your text here');
$edgeTTS->save($audio, 'output.wav'); // Save to file
Streaming with Callbacks
$edgeTTS->stream('Streaming text...', function ($chunk) {
// Process audio chunks in real-time (e.g., send to a client)
echo $chunk;
});
Word Boundaries Metadata
$result = $edgeTTS->textToSpeechWithMetadata('Text with words');
foreach ($result['wordBoundaries'] as $word) {
echo "Word: {$word['text']}, Start: {$word['start']}ms\n";
}
CLI Integration
php artisan edge-tts:generate "Hello via CLI" --voice en-US-AriaNeural --output hello.mp3
use Afaya\EdgeTTS\Jobs\TextToSpeechJob;
TextToSpeechJob::dispatch('Queue text')->onQueue('tts');
Route::get('/tts', function () {
return response()->stream(function () {
$edgeTTS = new EdgeTTS();
$edgeTTS->stream('Live stream text', function ($chunk) {
echo $chunk;
});
}, 200, ['Content-Type' => 'audio/wav']);
});
$voices = $edgeTTS->getVoices();
dd($voices); // Array of supported voices (e.g., 'en-US-JennyNeural')
Rate Limiting
$edgeTTS->setRetryOptions(3, 1000); // Retry 3 times with 1s delay
Voice Availability
if (!in_array('en-US-JennyNeural', $edgeTTS->getVoices())) {
throw new \RuntimeException('Voice not available');
}
Memory Limits
memory_limit. Use streaming for long texts:
$edgeTTS->stream('Long text...', function ($chunk) {
// Process chunk-by-chunk
});
CLI Timeouts
max_execution_time. Increase it or use streaming:
php -d max_execution_time=300 artisan edge-tts:generate "Long text..."
Enable Verbose Logging
Add to config/edge-tts.php:
'debug' => true,
Logs will appear in storage/logs/edge-tts.log.
Check HTTP Headers
Use curl to inspect raw requests:
curl -v -X POST https://speech.platform.bing.com/synthesize ...
Custom Voices
Extend the Voice class to support additional metadata:
namespace Afaya\EdgeTTS\Extensions;
class CustomVoice extends \Afaya\EdgeTTS\Voice {
public function getCustomProperty() { ... }
}
Audio Format Conversion
Hook into the afterGenerate event to convert formats:
$edgeTTS->on('afterGenerate', function ($audio) {
return convertToMp3($audio); // Custom logic
});
Proxy Support
Configure proxy settings in config/edge-tts.php:
'proxy' => [
'http' => 'tcp://proxy.example.com:8080',
'https' => 'tcp://proxy.example.com:8080',
],
config/edge-tts.php:
'default_voice' => 'en-US-GuyNeural',
curl is available on the remote server:
# On remote server:
apt-get install curl
How can I help you explore Laravel packages today?