当前位置: 欣欣网 > 码农

Edge-TTS:微软最新开源的支持多种中文音色的文本转语音工具,平替付费软件降低开发成本

2024-03-08码农

项目简介

Edge-TTS是由微软推出的文本转语音Python库,通过微软Azure Cognitive Services转化文本为自然语音。适合需要语音功能的开发者,GitHub上超3000星。作为国内付费TTS服务的替代品,Edge-TTS支持40多种语言和300种声音,提供优质的语音输出,满足不同开发需求。

扫码加入交流群

获得更多技术支持和交流

(请注明自己的职业)

安装

要安装它,运行以下命令:

$ pip install edge-tts

如果只想使用edge-tts和edge-playback命令,最好使用 pipx:

$ pipx install edge-tts

用法

基本用法

如果你想使用edge-tts命令,只需使用以下命令运行即可:

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

如果你想立即播放带有字幕的内容,可以使用以下edge-playback命令:

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

注意以上需要安装mpv命令行播放器。

所有命令也都edge-tts可以工作。edge-playback

改变声音

如果你想改变语音的语言或者更一般地,改变语音本身。

你首先需要使用 --list-voices 选项检查可用的语音。

$ edge-tts --list-voicesName: Microsoft Server Speech Text to Speech Voice(af-ZA, AdriNeural)ShortName: af-ZA-AdriNeuralGender: FemaleLocale: af-ZAName: Microsoft Server Speech Text to Speech Voice(am-ET, MekdesNeural)ShortName: am-ET-MekdesNeuralGender: FemaleLocale: am-ETName: Microsoft Server Speech Text to Speech Voice(ar-EG, SalmaNeural)ShortName: ar-EG-SalmaNeuralGender: FemaleLocale: ar-EGName: Microsoft Server Speech Text to Speech Voice(ar-SA, ZariyahNeural)ShortName: ar-SA-ZariyahNeuralGender: FemaleLocale: ar-SA...$ edge-tts --voice ar-EG-SalmaNeural --text "مرحبا كيف حالك؟" --write-media hello_in_arabic.mp3 --write-subtitles hello_in_arabic.vtt

调整语速、音量和音调

可以对生成的语音进行细微修改。

$ 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

此外,必须使用 --rate=-50% 而不是 --rate -50%(注意等号的缺失),否则 -50% 将被解释为另一个参数。

关于 edge-playback 命令的说明

edge-playback 实际上是 edge-tts 的一个封装,用于播放生成的语音。它接受与 edge-tts 选项相同的参数。

项目链接

https://github.com/rany2/edge-tts

关注「 AGI光年 」公众号