https://blog.csdn.net/weixin_62828995/article/details/136722656
https://github.com/rany2/edge-tts
安装语音引擎
pip install edge-tts -i https://pypi.tuna.tsinghua.edu.cn/simple
其他的一些云
http://mirrors.aliyun.com/pypi/simple/
http://pypi.douban.com/simple/
https://pypi.mirrors.ustc.edu.cn/simple/
https://pypi.zju.edu.cn/simple
https://mirror.ccs.tencentyun.com/pypi/simple
https://mirrors.huaweicloud.com/repository/pypi/simple
https://pypi.bjtu.edu.cn/simple
https://pypi.nju.edu.cn/simple/
生成一个mp3
edge-tts --text "hello world" --write-media hello.mp3
列出可用的音色
edge-tts --list-voices
zh-CN-XiaoxiaoNeural Female News, Novel Warm
zh-CN-XiaoyiNeural Female Cartoon, Novel Lively
zh-CN-YunjianNeural Male Sports, Novel Passion
zh-CN-YunxiNeural Male Novel Lively, Sunshine
zh-CN-YunxiaNeural Male Cartoon, Novel Cute
zh-CN-YunyangNeural Male News Professional, Reliable
zh-CN-liaoning-XiaobeiNeural Female Dialect Humorous
zh-CN-shaanxi-XiaoniNeural Female Dialect Bright
zh-HK-HiuGaaiNeural Female General Friendly, Positive
zh-HK-HiuMaanNeural Female General Friendly, Positive
zh-HK-WanLungNeural Male General Friendly, Positive
zh-TW-HsiaoChenNeural Female General Friendly, Positive
zh-TW-HsiaoYuNeural Female General Friendly, Positive
zh-TW-YunJheNeural Male General Friendly, Positive
zu-ZA-ThandoNeural Female General Friendly, Positive
zu-ZA-ThembaNeural Male General Friendly, Positive
使用不同音色
edge-tts --voice zh-CN-YunyangNeural --text "大家好,今天天气不错,不如出去晒太阳钓鱼吧" --write-media hello_in_cn.mp3
edge-tts --voice zh-CN-XiaoxiaoNeural --text "大家好,今天天气不错,不如出去晒太阳钓鱼吧" --write-media hello_in_cn.mp3
可以对生成的语音进行细微修改。
$ 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
import edge_tts
import asyncio
# 读取文本文件内容
TEXT = ""
with open('path_to_your_text_file.txt', 'rb') as f:
data = f.read()
TEXT = data.decode('utf-8')
# 设置语音参数
voice = 'zh-CN-YunxiNeural' # 你可以选择其他支持的语音
output = 'output_audio.mp3' # 输出音频文件的路径
# 异步执行TTS转换
async def my_function():
tts = edge_tts.Communicate(text=TEXT, voice=voice)
await tts.save(output)
if __name__ == '__main__':
asyncio.run(my_function())
edge-tts --file path_to_your_text_file.txt --write-media output_audio.mp3
这条命令会读取指定的文本文件,并生成一个名为output_audio.mp3的音频文件
#!/usr/bin/env python3
"""
Basic example of edge_tts usage.
"""
import asyncio
import edge_tts
TEXT = "大家好,欢迎关注语音之家,语音之家是一个助理AI语音开发者的社区。"
VOICE = "zh-CN-YunyangNeural"
OUTPUT_FILE = "d:/test.mp3"
async def amain() -> None:
"""Main function"""
communicate = edge_tts.Communicate(TEXT, VOICE)
await communicate.save(OUTPUT_FILE)
if name == "__main__":
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(amain())
finally:
loop.close()
评论区