"""Turn Urdu text into speech with Microsoft's Urdu neural voices."""

import asyncio
import sys
from pathlib import Path

import edge_tts


async def main() -> None:
    if len(sys.argv) != 4:
        print("usage: tts_speak.py TEXT_FILE OUT_FILE VOICE", file=sys.stderr)
        raise SystemExit(2)

    text_file, out_file, voice = sys.argv[1:]
    text = Path(text_file).read_text(encoding="utf-8").strip()
    if not text:
        print("empty text", file=sys.stderr)
        raise SystemExit(3)

    communicate = edge_tts.Communicate(text, voice, rate="-6%")
    await communicate.save(out_file)


if __name__ == "__main__":
    asyncio.run(main())
