安装
pip install edge-tts
部分代码,呢个库一定要和asyncio携程一起用
import edge_tts
import asyncio
voice = 'zh-CN-YunxiNeural'
output = 'demo.mp3'
rate = '-4%'
volume = '+0%'
TEXT = "你好,我叫通少,我很头铁,一般一个打10个20个叶问"
WEBVTT_FILE = "test.vtt"
async def my_function():
tt = edge_tts.Communicate(text=TEXT, voice=voice, rate=rate, volume=volume)
await tt.save(output)
submaker = edge_tts.SubMaker()
with open(WEBVTT_FILE, "w", encoding="utf-8") as file:
file.write(submaker.generate_subs())
if name == 'main':
asyncio.run(my_function())