"""Local mic/speaker loop with LiveKit WebRTC AEC3 echo cancellation.

When running without headphones, the TTS output bouncing back into the
mic re-triggers VAD/STT (the bot listens to itself). The shortcut
``enable_echo_cancellation=True`` turns on a default
``EchoCancellationConfig``; ``EasyConfig.browser()`` sets it
automatically since browser clients always loop transport audio back.

Setup: export OPENAI_API_KEY=...; uv sync --extra quickstart --group dev
       uv run easycat doctor
       uv run easycat doctor --env-file .env  # if keys live in .env
       uv run easycat doctor --env-file .env --json  # for parseable checks
Run:   uv run python examples/echo_cancellation.py
       uv run --env-file .env python examples/echo_cancellation.py  # if keys live in .env
"""

try:
    from agents import Agent  # type: ignore[import-untyped]
except ImportError as exc:
    raise SystemExit(
        "openai-agents is required. For an app, run: "
        "uv add 'easycat[quickstart]'. In this repo, run: "
        "uv sync --extra quickstart --group dev"
    ) from exc

from easycat import EasyConfig, run

run(
    EasyConfig.mic(
        agent=Agent(name="assistant", instructions="You are a helpful voice assistant."),
        enable_echo_cancellation=True,
    )
)
