Package: edge-tts-ext
say it firstThe project was modified fromhttps://pypi.org/project/edge-tts/, but the original project was a CLI and was not easy to call externally, so it was tweaked briefly and may be integrated with Azure TTS capabilities laterbuild参考文档:https://zhuanlan.zhihu.com/p/128020789pip install --upgrade setuptools如果构建出错:
pip uninstall setuptools wheel -y
pip install setuptools wheel
rm -rf build dist
python setup.py sdist bdist_wheeledge-ttsedge-ttsis a Python module that allows you to use Microsoft Edge's online text-to-speech service from within your Python code or using the providededge-ttsoredge-playbackcommand.InstallationTo install it, run the following command:$ pip install edge-ttsIf you only want to use theedge-ttsandedge-playbackcommands, it would be better to use pipx:$ pipx install edge-ttsUsageBasic usageIf you want to use theedge-ttscommand, you can simply run it with the following command:$ edge-tts --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.vttIf you wish to play it back immediately with subtitles, you could use theedge-playbackcommand:$ edge-playback --text "Hello, world!"Note the above requires the installation of thempvcommand line player.Alledge-ttscommands work inedge-playbackas well.Changing the voiceIf you want to change the language of the speech or more generally, the voice.You must first check the available voices with the--list-voicesoption:$ 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.vttCustom SSMLSupport 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 and volumeIt 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.vttIn 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:--pitchwas removed in 6.0.3 as it no longer appears to have any effect.Note on theedge-playbackcommandedge-playbackis just a wrapper aroundedge-ttsthat plays back the generated speech. It takes the same arguments as theedge-ttsoption.Python moduleIt is possible to use theedge-ttsmodule directly from Python. For a list of example applications:https://github.com/rany2/edge-tts/blob/master/examples/basic_generation.pyhttps://github.com/rany2/edge-tts/blob/master/examples/dynamic_voice_selection.pyhttps://github.com/rany2/edge-tts/blob/master/examples/basic_audio_streaming.pyhttps://github.com/rany2/edge-tts/blob/master/examples/streaming_with_subtitles.pyhttps://github.com/rany2/edge-tts/blob/master/src/edge_tts/util.pyhttps://github.com/hasscc/hass-edge-tts/blob/main/custom_components/edge_tts/tts.py