python edge_tts(文本转音频)
pythonedge_tts 文本转音频,带字幕
·
1. 安装插件edge-tts
pip install edge-tts
2.文本转音频
"""
:param voice: 指定声音名称
:param content: 文本内容
:param audioFile: 音频输出文件
:param vttFile: 字幕输出文件
"""
async def create_tts_mp3(voice: str, content: str, audioFile: str, vttFile:str) -> None:
communicate = edge_tts.Communicate(content, voice)
submaker = edge_tts.SubMaker()
with open(audioFile, "wb") as file:
async for chunk in communicate.stream():
if chunk["type"] == "audio":
file.write(chunk["data"])
elif chunk["type"] == "WordBoundary":
submaker.create_sub((chunk["offset"], chunk["duration"]), chunk["text"])
with open(vttFile, "w", encoding="utf-8") as file:
file.write(submaker.generate_subs())
3.voice选择说明
edge-tts --list-voices

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)