import asyncio
import argparse
import edge_tts

async def generate_speech(text, voice, output_file):
    communicate = edge_tts.Communicate(text, voice)
    await communicate.save(output_file)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Text to Speech using Edge TTS')
    parser.add_argument('--text', required=True, help='Text to convert to speech')
    parser.add_argument('--voice', required=True, help='Voice to use (e.g., zh-CN-YunxiNeural)')
    parser.add_argument('--output', required=True, help='Output MP3 file path')

    args = parser.parse_args()

    try:
        asyncio.run(generate_speech(args.text, args.voice, args.output))
        print(f"Success: {args.output}")
    except Exception as e:
        print(f"Error: {e}")
        exit(1)
