Microsoft Edge TTS Python Library
edge-tts is a Python library (current version 7.2.8) that provides access to Microsoft Edge's online text-to-speech (TTS) service. It allows developers to convert text into natural-sounding speech without needing the Edge browser, Windows, or an API key, by leveraging the same cloud voices used by Edge. The library maintains an active release cadence, frequently updating to address changes in the underlying Microsoft service.
Warnings
- breaking The library relies on a reverse-engineered Microsoft API, which is subject to unannounced changes by Microsoft. This can lead to sudden breakages or requiring rapid updates to the `edge-tts` library to maintain functionality.
- breaking Support for custom SSML (Speech Synthesis Markup Language) beyond basic prosody (rate, volume, pitch) was removed because Microsoft's service only permits SSML that could be generated by Microsoft Edge itself, limiting advanced custom tags.
- gotcha Since `edge-tts` uses `asyncio`, all calls to `Communicate` methods (like `save()` or `stream()`) must be `await`ed within an `async` function, and the main execution flow needs `asyncio.run()`.
- gotcha Encountering 'NoAudioReceived' errors or unexpected silence is common. This often indicates issues with the chosen voice, network connectivity, or temporary service unavailability on Microsoft's end.
- deprecated The `merge_cues` support and `words-in-cue` functionality were dropped as `SentenceBoundary` metadata became the default and rendered them obsolete.
Install
-
pip install edge-tts
Imports
- edge_tts
import edge_tts
Quickstart
import asyncio
import edge_tts
import os
TEXT = "Hello, this is a test of the Microsoft Edge Text-to-Speech library."
VOICE = "en-US-JennyNeural" # You can list available voices with `edge-tts --list-voices`
OUTPUT_FILE = "hello.mp3"
async def main():
print(f"Generating speech for: '{TEXT}' with voice '{VOICE}'")
try:
communicate = edge_tts.Communicate(text=TEXT, voice=VOICE)
await communicate.save(OUTPUT_FILE)
print(f"Audio saved to {OUTPUT_FILE}")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure you have a stable internet connection and the voice name is correct.")
if __name__ == "__main__":
asyncio.run(main())