1
pip install pyttsx3
import pyttsx3
tts = pyttsx3.init()
tts.say("hello world") # 可以直接播放
# tts.save_to_file("hello world","test.mp3") # 可以输出到文件
tts.runAndWait()
tts.stop()
2
pip3 install edge-tts
edge-tts –list-voices # 有哪些模型可用
示例:
edge-tts –text “Hello, world!” –write-media hello.mp3
edge-tts –voice zh-CN-XiaoyiNeural –text “你好啊,我是智能语音助手” –write-media hello_in_cn.mp3
edge-tts –rate=-50% –voice zh-CN-XiaoyiNeural –text “你好啊,我是智能语音助手” –write-media hello_in_cn.mp3
edge-tts –volume=-50% –voice zh-CN-XiaoyiNeural –text “你好啊,我是智能语音助手” –write-media hello_in_cn.mp3
edge-playback –text “兄弟你好” –voice zh-CN-XiaoyiNeural #直接播放,需要安装mpv
import asyncio
import edge_tts
TEXT = "你好哟,我是智能语音助手,小伊"
VOICE = "zh-CN-XiaoyiNeural"
OUTPUT_FILE = "/Users/liuyue/Downloads/test.mp3"
async def _main() -> None:
communicate = edge_tts.Communicate(TEXT, VOICE)
await communicate.save(OUTPUT_FILE)
if __name__ == "__main__":
asyncio.run(_main())