Download the PHP package afaya/edge-tts without Composer
On this page you can find all versions of the php package afaya/edge-tts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download afaya/edge-tts
More information about afaya/edge-tts
Files in afaya/edge-tts
Package edge-tts
Short Description Edge TTS is a PHP package that allows access to the online text-to-speech service used by Microsoft Edge without the need for Microsoft Edge, Windows, or an API key.
License GPL-3.0-or-later
Homepage https://github.com/andresayac/edge-tts-php
Informations about the package edge-tts
Edge TTS for PHP
Edge TTS turns text into natural-sounding speech with the online text-to-speech service of Microsoft Edge, without Edge, Windows or an API key.
Available in three languages
The same library for the Edge text-to-speech service, in Node.js, PHP and Go:
| Language | Install | Repository |
|---|---|---|
| Node.js and browsers | npm install @andresaya/edge-tts |
andresayac/edge-tts |
| PHP (this one) | composer require afaya/edge-tts |
andresayac/edge-tts-php |
| Go | go get github.com/andresayac/edge-tts-go |
andresayac/edge-tts-go |
Features
- Text-to-speech with more than 300 neural voices in over 100 locales.
- Streaming: get the audio as it arrives, with a
foreachor a callback. - Word and sentence boundaries: know when each word and sentence is spoken.
- Subtitles: SRT or WebVTT, one cue per sentence.
- Voice filtering by language and gender, with the list cached for 10 minutes.
- Pitch, rate and volume control.
- Configurable: override the endpoint, headers and timeout without waiting for a release.
- No event loop: it works inside Laravel, Symfony, WordPress or a plain script.
- Verified TLS, on Windows too, without configuring a CA bundle.
- Command-line tool included.
Requirements
- PHP 7.4 or later (tested on 7.4, 8.1, 8.2, 8.3 and 8.4)
- The
jsonandopensslextensions
Installation
Quick start
Command-line interface
| Option | Description | Default |
|---|---|---|
-t, --text |
Text to convert to audio | |
-f, --file |
Input file (text); --file=- reads from stdin |
|
--voice |
Voice to use | en-US-AriaNeural |
-r, --rate |
Rate of speech | 0% |
-l, --volume |
Volume of speech | 0% |
-p, --pitch |
Pitch of speech | 0Hz |
-o, --output |
Output file name; the extension is added when missing | output_<timestamp> |
--format |
Output format | audio-24khz-48kbitrate-mono-mp3 |
--subtitles |
Write subtitles: .srt, or .vtt for WebVTT |
edge-tts:synthesize and edge-tts:voice-list still work as names of the commands.
API
Configuration
Every option is optional. The defaults come from Constants, so when Microsoft changes the service you can set the new values yourself instead of waiting for a release.
A misspelled option throws InvalidArgumentException.
Voices
Each voice has Name, OriginalName, ShortName, DisplayName, LocalName, Gender, Locale, LocaleName, SecondaryLocaleList, VoiceType, VoiceTag and FriendlyName.
Synthesis
Every option is optional, and numbers work too: 'rate' => 50 is +50% and 'pitch' => -5 is -5Hz.
Output formats
Constants::OUTPUT_FORMAT key |
Format | Extension |
|---|---|---|
AUDIO_24KHZ_48KBITRATE_MONO_MP3 (default) |
audio-24khz-48kbitrate-mono-mp3 |
.mp3 |
AUDIO_24KHZ_96KBITRATE_MONO_MP3 |
audio-24khz-96kbitrate-mono-mp3 |
.mp3 |
WEBM_24KHZ_16BIT_MONO_OPUS |
webm-24khz-16bit-mono-opus |
.webm |
These are the only formats the service accepts. It refuses the other Azure formats (WAV, PCM, OGG, 48 kHz MP3...) with "Unsupported Edge output format".
Matching the voice to the text
Voices are locale specific. A voice can only read text written in the script of its own language, so passing Chinese, Cyrillic, Arabic or Devanagari text to an English voice returns no audio. synthesize() then throws EmptyAudioException:
Streaming
stream() yields the audio as it arrives, so you can start playing or sending it before the synthesis ends:
Leaving the loop early closes the connection. If you prefer a callback:
Everything in one result
generate() returns the audio, the boundaries and the duration in a SynthesisResult, and leaves the instance as it was:
Getting the audio
After synthesize(), stream() or synthesizeStream():
Word and sentence boundaries
The service leaves the opening punctuation out of its sentences, so "¿Cómo estás?" comes back as "Cómo estás?". The library puts it back from your text: ¿ ¡ « " ' “ ‘ ( [.
Subtitles
Errors
| Exception | When |
|---|---|
InvalidArgumentException |
An empty text, an invalid pitch, rate or volume, or checkVoice() with an unknown voice |
Afaya\EdgeTTS\Exception\EmptyAudioException |
The voice cannot read the text |
Afaya\EdgeTTS\Exception\HandshakeException |
The service refused the connection; getStatusCode() has the HTTP status |
Afaya\EdgeTTS\Exception\EdgeTTSException |
Any other error of the service or the network, such as "The service refused the request: Unsupported voice xx-XX-NobodyNeural." |
RuntimeException |
Asking for audio or metadata before a synthesis |
Every exception of the service extends EdgeTTSException, which extends RuntimeException.
A machine whose clock is off by more than a few minutes is refused by the service. The client then corrects its clock from the response and tries once more.
Upgrading
Version 1.7 stopped working when Microsoft moved the service to a new endpoint; 1.8.3 and later use the new one. What changed in each version, and what to look at when upgrading, is in the CHANGELOG.
Examples
examples/basic.php: synthesize to a file and list voices.examples/stream.php: stream the audio with a generator and with a callback.examples/subtitles.php: generate the audio and its subtitles in one call.
Testing
The tests replay a recorded session of the service, through a fake and through a local server on real sockets, so they need no network.
License
GPL-3.0-or-later. See LICENSE.txt.
Acknowledgments
All versions of edge-tts with dependencies
ext-json Version *
ext-openssl Version *
composer/ca-bundle Version ^1.3
symfony/console Version ^5.4|^6.0|^7.0|^8.0