edge-tts README

The project's README from github.com/rany2/edge-tts. As one markdown file: README.md.

edge-tts

edge-tts is a Python module that allows you to use Microsoft Edge's online text-to-speech service from within your Python code or using the provided edge-tts or edge-playback command.

Installation

To install it, run the following command:

$ pip install edge-tts

If you only want to use the edge-tts and edge-playback commands, it would be better to use pipx:

$ pipx install edge-tts

Usage

Basic usage

If you want to use the edge-tts command, you can simply run it with the following command:

$ edge-tts --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.srt

If you wish to play it back immediately with subtitles, you could use the edge-playback command:

$ edge-playback --text "Hello, world!"

Note that edge-playback requires the installation of the mpv command line player, except on Windows.

All edge-tts commands work with edge-playback with the exception of the --write-media, --write-subtitles and --list-voices options.

Changing the voice

You can change the voice used by the text-to-speech service by using the --voice option. The --list-voices option can be used to list all available voices.

$ edge-tts --list-voices
Name                               Gender    ContentCategories      VoicePersonalities
---------------------------------  --------  ---------------------  --------------------------------------
af-ZA-AdriNeural                   Female    General                Friendly, Positive
af-ZA-WillemNeural                 Male      General                Friendly, Positive
am-ET-AmehaNeural                  Male      General                Friendly, Positive
am-ET-MekdesNeural                 Female    General                Friendly, Positive
ar-AE-FatimaNeural                 Female    General                Friendly, Positive
ar-AE-HamdanNeural                 Male      General                Friendly, Positive
ar-BH-AliNeural                    Male      General                Friendly, Positive
ar-BH-LailaNeural                  Female    General                Friendly, Positive
ar-DZ-AminaNeural                  Female    General                Friendly, Positive
ar-DZ-IsmaelNeural                 Male      General                Friendly, Positive
ar-EG-SalmaNeural                  Female    General                Friendly, Positive
...

$ edge-tts --voice ar-EG-SalmaNeural --text "مرحبا كيف حالك؟" --write-media hello_in_arabic.mp3 --write-subtitles hello_in_arabic.srt

Custom SSML

Support for custom SSML was removed because Microsoft prevents the use of any SSML that could not be generated by Microsoft Edge itself. This means that all the cases where custom SSML would be useful cannot be supported as the service only permits a single <voice> tag with a single <prosody> tag inside it. Any available customization options that could be used in the <prosody> tag are already available from the library or the command line itself.

Changing rate, volume and pitch

You can change the rate, volume and pitch of the generated speech by using the --rate, --volume and --pitch options. When using a negative value, you will need to use --[option]=-50% instead of --[option] -50% to avoid the option being interpreted as a command line option.

$ edge-tts --rate=-50% --text "Hello, world!" --write-media hello_with_rate_lowered.mp3 --write-subtitles hello_with_rate_lowered.srt
$ edge-tts --volume=-50% --text "Hello, world!" --write-media hello_with_volume_lowered.mp3 --write-subtitles hello_with_volume_lowered.srt
$ edge-tts --pitch=-50Hz --text "Hello, world!" --write-media hello_with_pitch_lowered.mp3 --write-subtitles hello_with_pitch_lowered.srt

Python module

It is possible to use the edge-tts module directly from Python. Examples from the project itself include:

Other projects that use the edge-tts module include:

edge-tts (rany2/edge-tts)

Searching Database…

12.3K ·GitHub
What is this?edge-tts is a Python module and CLI that lets you use Microsoft Edge's online text-to-speech service from your code or terminal, without needing Microsoft Edge, Windows, or an API key.
Is this a library or a command-line tool?Both: it's a Python module you can import, and it also ships two CLI commands, edge-tts (generate audio/subtitles) and edge-playback (generate and play immediately).
How do I install and use it?Install with 'pip install edge-tts' (or 'pipx install edge-tts' if you only need the CLI commands), then run something like 'edge-tts --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.srt'.
Do I need Microsoft Edge, Windows, or an API key?No - it talks directly to Edge's online TTS service, so you don't need the Edge browser, Windows, or any API key. The only extra dependency is the mpv command-line player if you want to use edge-playback on non-Windows systems.
Can I use custom SSML to fine-tune the speech?No, custom SSML support was removed because Microsoft only allows SSML that Edge itself could generate, so you're limited to the rate, volume, pitch, and voice options exposed by the tool.
Which voices and languages are available?It supports a large list of Microsoft Edge neural voices across many languages (e.g. Arabic, Amharic, Afrikaans, and many more), viewable with 'edge-tts --list-voices'.
Does it work on Windows, macOS, and Linux?Yes, it's a pure Python package that works wherever Python/pip runs; only edge-playback's dependency on mpv differs, and that's not required on Windows.
Can I adjust speech rate, volume, and pitch?Yes, use the --rate, --volume and --pitch flags, e.g. --rate=-50% or --pitch=-50Hz; note negative values need the '=' syntax to avoid being parsed as separate CLI flags.
Does it generate subtitles along with audio?Yes, the edge-tts command can write both an audio file and an .srt subtitle file in the same call, e.g. --write-media hello.mp3 --write-subtitles hello.srt.
What other projects use edge-tts?README mentions hass-edge-tts, Podcastfy, and a 'tts-samples' repo of voice samples as examples of projects built on the edge-tts module.
What are similar projects?AuK, yovoice, bark, OpenVoice, dia, csm, supertonic, Speech
Creator
rany2
Size
2.1 MB
Stars
12.3K
Age
5y
Commits · 90 Days