""" Main entry point for voicebot. This module provides the main entry point and orchestration for the voicebot application. It can run in either client mode (connecting to a lobby) or provider mode (serving bots). """ import argparse import asyncio import sys import os # Add the parent directory to sys.path to allow absolute imports sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from voicebot.models import VoicebotArgs, VoicebotMode from voicebot.client_main import main_with_args, start_client_with_reload from voicebot.bot_orchestrator import start_bot_provider from voicebot.client_app import get_app # Create app instance for uvicorn import uvicorn_app = get_app() async def main(): """Example usage of the WebRTC signaling client with CLI options to create session and lobby.""" parser = argparse.ArgumentParser(description="Python WebRTC voicebot client") parser.add_argument( "--server-url", default="http://localhost:8000/ai-voicebot", help="AI-Voicebot lobby and signaling server base URL (http:// or https://)", ) parser.add_argument( "--lobby", default="default", help="Lobby name to create or join" ) parser.add_argument( "--session-name", default="Python Bot", help="Session (user) display name" ) parser.add_argument( "--session-id", default=None, help="Optional existing session id to reuse" ) parser.add_argument( "--password", default=None, help="Optional password to register or takeover a name", ) parser.add_argument( "--private", action="store_true", help="Create the lobby as private" ) parser.add_argument( "--insecure", action="store_true", help="Allow insecure server connections when using SSL (accept self-signed certs)", ) args = parser.parse_args() # Convert argparse Namespace to VoicebotArgs for type safety voicebot_args = VoicebotArgs.from_argparse(args) await main_with_args(voicebot_args) if __name__ == "__main__": # Install required packages: # pip install aiortc websockets opencv-python numpy # Check if we're being run as a bot provider or as a client parser = argparse.ArgumentParser(description="AI Voicebot - WebRTC client or bot provider") parser.add_argument("--mode", choices=["client", "provider"], default="client", help="Run as client (connect to lobby) or provider (serve bots)") # Provider mode arguments parser.add_argument("--host", default="0.0.0.0", help="Host for provider mode") parser.add_argument("--port", type=int, default=8788, help="Port for provider mode") parser.add_argument("--reload", action="store_true", help="Enable auto-reload for development") # Client mode arguments parser.add_argument("--server-url", default="http://localhost:8000/ai-voicebot", help="AI-Voicebot lobby and signaling server base URL (for client mode) or provider registration URL (for provider mode)") parser.add_argument("--lobby", default="default", help="Lobby name to create or join (client mode)") parser.add_argument("--session-name", default="Python Bot", help="Session (user) display name (client mode)") parser.add_argument("--session-id", default=None, help="Optional existing session id to reuse (client mode)") parser.add_argument("--password", default=None, help="Optional password to register or takeover a name (client mode)") parser.add_argument("--private", action="store_true", help="Create the lobby as private (client mode)") parser.add_argument("--insecure", action="store_true", help="Allow insecure connections") parser.add_argument("--registration-check-interval", type=float, default=30.0, help="Interval in seconds for checking registration status (5.0-300.0)") args = parser.parse_args() # Convert argparse Namespace to VoicebotArgs for type safety voicebot_args = VoicebotArgs.from_argparse(args) if voicebot_args.mode == VoicebotMode.PROVIDER: start_bot_provider( host=voicebot_args.host, port=voicebot_args.port, server_url=voicebot_args.server_url, insecure=voicebot_args.insecure, reload=voicebot_args.reload ) else: if voicebot_args.reload: start_client_with_reload(voicebot_args) else: asyncio.run(main_with_args(voicebot_args))