Text to speech with the voices of Microsoft Edge
More than 300 neural voices in over 100 languages, with the timing of every word. No API key, no Windows, no Edge. One library for PHP, Node.js, browsers and Go.
This page runs afaya/edge-tts on the server.
The browser section runs @andresaya/edge-tts in your browser.
Playground
generate() returns the audio, the timing of each word and sentence, and the estimated duration in one result.
Rate, pitch and volume go to the library as numbers; strings such as '+10%' work too.
Word timings and subtitles
The service says when each word and sentence starts and how long it lasts, in 100-nanosecond ticks.
The highlighted word below comes from wordBoundaries; the caption in the player comes from the WebVTT file
written by toVTT(). Click a word to jump to it.
The service drops the opening punctuation of sentences: it sends Cómo estás?
for ¿Cómo estás?
.
The library puts it back from your text. Try the Spanish sample and open Sentences.
Streaming
stream() yields the audio while the service is still producing it.
The PHP endpoint echoes and flushes each chunk, and this page feeds them to a MediaSource,
so playback starts with the first chunk. It streams the text and voice of the playground;
the long sample shows the gap best. Stopping closes the connection to the service.
Voices
Loading voices…
| Voice | Locale | Gender | Personality | Scenarios |
|---|
Output formats
The service takes three formats and refuses the rest. This sends the first 300 characters of the playground text once per format, in parallel. The duration is estimated from the size and bitrate, without decoding.
Errors you can catch
Each case sends a real request that fails, and shows what the library threw. Bad options fail in milliseconds, before connecting; refusals from the service take a round trip and carry its reason.
Straight from the browser
The Node.js package has a browser build. Here it loads from jsDelivr and talks to Microsoft from this page, with no server in between.
The service only accepts the user agent of Microsoft Edge, and a page cannot change the one its browser sends.
In Chrome, Firefox or Safari synthesis fails with HANDSHAKE and needs a relay such as
relay-server.mjs, passed as wssUrl.
Server libraries, like the PHP one behind this page, are not affected.
Command line
The PHP, Node.js and Go packages ship a CLI with the same options. The first command uses the playground settings.
Options
All optional. When Microsoft changes the service, you can point the library at the new values without waiting for a release.