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.
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
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.
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