Go to file
Rany 7c83923a5b
Bump edge_tts version to 6.1.18 (#310)
Signed-off-by: rany <rany2@riseup.net>
2024-11-11 13:04:56 +02:00
.github Resolve *almost* all pylint complaints and setup pylint 2023-01-05 07:52:51 +02:00
examples Fix minor typo in examples/sync_audio_stream_in_async_context.py 2024-04-21 18:09:54 +03:00
src Bump edge_tts version to 6.1.18 (#310) 2024-11-11 13:04:56 +02:00
tests Don't delete test outputs and only run cmp on srt 2024-05-21 17:05:32 +03:00
.gitignore Don't delete test outputs and only run cmp on srt 2024-05-21 17:05:32 +03:00
.isort.cfg Complete workflow fixing 2023-01-05 01:49:37 +02:00
build_and_publish.sh Merge all scripts for publishing into build_and_publish.sh 2023-01-05 07:59:43 +02:00
format.sh Complete workflow fixing 2023-01-05 01:49:37 +02:00
LICENSE Initial commit 2021-05-10 21:55:15 +03:00
lint.sh Update edge_tts to v6.1.3 2023-01-25 18:36:59 +02:00
mypy.ini Add support for clock adjustment for Sec-MS-GEC token (#309) 2024-11-11 13:03:40 +02:00
pylintrc Refactor communicate for better readability 2024-02-16 19:56:18 +02:00
README.md Add podcastfy example to README.md (#296) 2024-11-01 14:48:04 +02:00
setup.cfg Define version information in version.py 2023-01-09 21:17:25 +02:00
setup.py Don't pin certifi version 2024-02-16 17:59:02 +02:00

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

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

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

Note the above requires the installation of the mpv command line player.

All edge-tts commands work in edge-playback as well.

Changing the voice

If you want to change the language of the speech or more generally, the voice.

You must first check the available voices with the --list-voices option:

$ edge-tts --list-voices
Name: Microsoft Server Speech Text to Speech Voice (af-ZA, AdriNeural)
ShortName: af-ZA-AdriNeural
Gender: Female
Locale: af-ZA

Name: Microsoft Server Speech Text to Speech Voice (am-ET, MekdesNeural)
ShortName: am-ET-MekdesNeural
Gender: Female
Locale: am-ET

Name: Microsoft Server Speech Text to Speech Voice (ar-EG, SalmaNeural)
ShortName: ar-EG-SalmaNeural
Gender: Female
Locale: ar-EG

Name: Microsoft Server Speech Text to Speech Voice (ar-SA, ZariyahNeural)
ShortName: ar-SA-ZariyahNeural
Gender: Female
Locale: ar-SA

...

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

Custom SSML

Support for custom SSML has been removed since 5.0.0 because Microsoft has taken the initiative to prevent it from working. You cannot use custom SSML anymore.

Changing rate, volume and pitch

It is possible to make minor changes to the generated speech.

$ edge-tts --rate=-50% --text "Hello, world!" --write-media hello_with_rate_halved.mp3 --write-subtitles hello_with_rate_halved.vtt
$ edge-tts --volume=-50% --text "Hello, world!" --write-media hello_with_volume_halved.mp3 --write-subtitles hello_with_volume_halved.vtt
$ edge-tts --pitch=-50Hz --text "Hello, world!" --write-media hello_with_pitch_halved.mp3 --write-subtitles hello_with_pitch_halved.vtt

In addition, it is required to use --rate=-50% instead of --rate -50% (note the lack of an equal sign) otherwise the -50% would be interpreted as just another argument.

Note on the edge-playback command

edge-playback is just a wrapper around edge-tts that plays back the generated speech. It takes the same arguments as the edge-tts option.

Python module

It is possible to use the edge-tts module directly from Python. For a list of example applications: