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
这是什么?edge-tts 是一个 Python 模块和命令行工具,可以让你在代码或终端里使用 Microsoft Edge 的在线文字转语音服务,无需安装 Microsoft Edge 浏览器、Windows 系统,也不需要 API 密钥。
这是库还是命令行工具?两者都是:它是一个可以导入使用的 Python 模块,同时也提供两个命令行命令:edge-tts(生成音频或字幕)和 edge-playback(生成后立即播放)。
我该怎么安装和使用?用 'pip install edge-tts' 安装(如果只需要命令行命令,可以用 'pipx install edge-tts'),然后运行类似这样的命令:'edge-tts --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.srt'。
我需要 Microsoft Edge、Windows 或 API 密钥吗?都不需要。它直接连接 Edge 的在线文字转语音服务,所以无需 Edge 浏览器、Windows 或任何 API 密钥。如果想在非 Windows 系统上使用 edge-playback,唯一额外的依赖是 mpv 命令行播放器。
我能用自定义 SSML 来微调语音吗?不能,自定义 SSML 支持已被移除,因为微软只允许 Edge 自身能够生成的 SSML,所以你只能使用该工具提供的语速、音量、音调和语音选项。
有哪些语音和语言可用?它支持大量微软 Edge 神经网络语音,涵盖多种语言(例如阿拉伯语、阿姆哈拉语、南非荷兰语等),可以用 'edge-tts --list-voices' 查看完整列表。
它能在 Windows、macOS 和 Linux 上运行吗?可以。它是纯 Python 包,只要 Python 和 pip 能运行的地方就能用;只有 edge-playback 依赖的 mpv 在不同系统上有所不同,而 Windows 上不需要它。
我能调整语速、音量和音调吗?可以,使用 --rate、--volume 和 --pitch 参数,例如 --rate=-50% 或 --pitch=-50Hz;注意负值需要用 '=' 语法,否则会被当作单独的命令行参数解析。
它能同时生成音频和字幕吗?可以,edge-tts 命令可以在一次调用中同时写出音频文件和 .srt 字幕文件,例如 --write-media hello.mp3 --write-subtitles hello.srt。
还有哪些项目在使用 edge-tts?README 中提到了 hass-edge-tts、Podcastfy,以及一个存放语音样例的 'tts-samples' 仓库,它们都是基于 edge-tts 模块构建的项目示例。
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