"""Transcribe a WAV file using dTelecom STT.

Usage:
    export DTELECOM_PRIVATE_KEY="0x..."
    python transcribe_file.py path/to/audio.wav
"""

import asyncio
import os
import sys

from dtelecom_stt import STTClient


async def main():
    if len(sys.argv) < 2:
        print("Usage: python transcribe_file.py <audio.wav>")
        print("  Audio must be PCM16, 16kHz, mono.")
        print("  Set DTELECOM_PRIVATE_KEY env var with your wallet key.")
        sys.exit(1)

    wav_path = sys.argv[1]
    private_key = os.environ.get("DTELECOM_PRIVATE_KEY")
    if not private_key:
        print("Error: Set DTELECOM_PRIVATE_KEY environment variable")
        sys.exit(1)

    client = STTClient(private_key=private_key)

    # Check pricing first
    info = await client.pricing()
    print(f"Pricing: ${info.price_per_minute_usd}/min ({info.currency})")

    # Transcribe
    async with client.session(minutes=5, language="en") as stream:
        async for t in stream.transcribe_file(wav_path):
            start = f"{t.start:.1f}s" if t.start is not None else "?"
            print(f"  [{start}] {t.text}")

    print("Done.")


if __name__ == "__main__":
    asyncio.run(main())
