HoneyTian's picture
update
f25c867
raw
history blame
1.24 kB
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import asyncio
import tempfile
import edge_tts
from project_settings import project_path
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--text",
default="学而时习之,不亦悦乎。",
type=str
)
parser.add_argument(
"--speaker",
default="zh-CN-XiaoxiaoNeural",
type=str
)
args = parser.parse_args()
return args
async def print_edge_voices():
voices = await edge_tts.list_voices()
for voice in voices:
print(voice)
async def edge_text_to_speech(text: str, speaker: str):
communicate = edge_tts.Communicate(text, speaker)
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
tmp_path = tmp_file.name
await communicate.save(tmp_path)
print(tmp_path)
return f"Speech synthesis completed for: {text}", tmp_path
def main():
args = get_args()
loop = asyncio.get_event_loop()
loop.run_until_complete(print_edge_voices())
loop.run_until_complete(edge_text_to_speech(
text=args.text,
speaker=args.speaker,
))
return
if __name__ == '__main__':
main()