edge-tts is a Python module for calling Microsoft Edge's online text-to-speech service in Python code or via the command line, without needing to install the Microsoft Edge browser. This project is maintained by rany2 and hosted on GitHub.
Purpose: Convert text to speech, can generate audio files, and can also play directly and display subtitles.
Main capabilities:
- Call the text-to-speech service in code via a Python module.
- Provides two command-line tools, edge-tts and edge-playback.
- Supports switching voices with the --voice option, and listing all available voices with --list-voices.
- Supports adjusting speech rate, volume, and pitch with the --rate, --volume, and --pitch options. When using negative values, write --[option]=-50% instead of --[option] -50%, to avoid it being parsed as a command-line option.
- When generating audio, if stderr is a terminal, a progress bar will be displayed; the progress percentage is based on the estimated total length of the received audio and the service boundary metadata, reflecting the remaining workload rather than the amount of text already read aloud. When stderr is redirected, when --write-subtitles - is used to write subtitles to stderr, or when --no-progress is passed, the progress bar is suppressed.
- Supports direct playback and subtitle display (edge-playback), but requires the mpv command-line player to be installed (except on Windows).
- All edge-tts commands can be used for edge-playback, except for the --write-media, --write-subtitles, and --list-voices options.
Usage: Installation: Can be installed via pip; if only using the edge-tts and edge-playback commands, pipx is recommended. Command-line example: Run the edge-tts command to use it; if you want to play immediately and display subtitles, you can use the edge-playback command. Python module: Can be used directly by importing the edge-tts module in Python; the project's own example is located at /src/edge_tts/util.py.
Applicable scenarios:
- In Python integrate text-to-speech functionality into projects.
- Quickly convert text to audio files via the command line.
- Scenarios where you need to preview different voices and adjust speech rate/volume/pitch.
- Other projects can refer to using the edge-tts module, for example the tts-samples project provides a collection of mp3 voice samples, making it easy to choose voices for a project.
Limitations:
- Custom SSML support has been removed, because Microsoft prohibits the use of any SSML that cannot be generated by Microsoft Edge itself. This means all scenarios where custom SSML would be useful cannot be supported; the service only allows a single <voice> tag containing a single <prosody> tag. The customization options that can be used within the <prosody> tag are already provided through the library or the command line.
- edge-playback requires the mpv command-line player to be installed on non-Windows systems.
- Some options (--write-media, --write-subtitles, --list-voices) are not available for edge-playback.
Other information: The project accepts sponsorships.