1. Go to this page and download the library: Download afaya/edge-tts library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
afaya / edge-tts example snippets
faya\EdgeTTS\Service\EdgeTTS;
// Initialize the EdgeTTS service
$tts = new EdgeTTS();
// Get voices
$voices = $tts->getVoices();
// var_dump($voices); // array -> use ShortName with the name of the voice
// Synthesize text with options for voice, rate, volume, and pitch
$tts->synthesize("Hello, world!", 'en-US-AriaNeural', [
'rate' => '0%', // Speech rate (range: -100% to 100%)
'volume' => '0%', // Speech volume (range: -100% to 100%)
'pitch' => '0Hz' // Voice pitch (range: -100Hz to 100Hz)
]);
// Export synthesized audio in different formats
$base64Audio = $tts->toBase64(); // Get audio as base64
$tts->toFile("output.wav"); // Save audio to file
$rawAudio = $tts->toRaw(); // Get raw audio stream