()
| 295 | # await socket.send_user_input(user_input_message) |
| 296 | |
| 297 | async def main() -> None: |
| 298 | # Retrieve any environment variables stored in the .env file |
| 299 | load_dotenv() |
| 300 | |
| 301 | # Retrieve the API key, Secret key, and EVI config id from the environment variables |
| 302 | HUME_API_KEY = os.getenv("HUME_API_KEY") |
| 303 | HUME_SECRET_KEY = os.getenv("HUME_SECRET_KEY") |
| 304 | HUME_CONFIG_ID = os.getenv("HUME_CONFIG_ID") |
| 305 | |
| 306 | # Initialize the asynchronous client, authenticating with your API key |
| 307 | client = AsyncHumeClient(api_key=HUME_API_KEY) |
| 308 | |
| 309 | # Define options for the WebSocket connection, such as an EVI config id and a secret key for token authentication |
| 310 | # See the full list of query parameters here: https://dev.hume.ai/reference/empathic-voice-interface-evi/chat/chat#request.query |
| 311 | options = ChatConnectOptions(config_id=HUME_CONFIG_ID, secret_key=HUME_SECRET_KEY) |
| 312 | |
| 313 | # Instantiate the WebSocketHandler |
| 314 | websocket_handler = WebSocketHandler() |
| 315 | |
| 316 | # Open the WebSocket connection with the configuration options and the handler's functions |
| 317 | async with client.empathic_voice.chat.connect_with_callbacks( |
| 318 | options=options, |
| 319 | on_open=websocket_handler.on_open, |
| 320 | on_message=websocket_handler.on_message, |
| 321 | on_close=websocket_handler.on_close, |
| 322 | on_error=websocket_handler.on_error |
| 323 | ) as socket: |
| 324 | |
| 325 | # Set the socket instance in the handler |
| 326 | websocket_handler.set_socket(socket) |
| 327 | |
| 328 | # Create an asynchronous task to continuously detect and process input from the microphone, as well as play audio |
| 329 | microphone_task = asyncio.create_task( |
| 330 | MicrophoneInterface.start( |
| 331 | socket, |
| 332 | allow_user_interrupt=False, |
| 333 | byte_stream=websocket_handler.byte_strs |
| 334 | ) |
| 335 | ) |
| 336 | |
| 337 | # Create an asynchronous task to send messages over the WebSocket connection |
| 338 | message_sending_task = asyncio.create_task(sending_handler(socket)) |
| 339 | |
| 340 | # Schedule the coroutines to occur simultaneously |
| 341 | await asyncio.gather(microphone_task, message_sending_task) |
| 342 | |
| 343 | if __name__ == "__main__": |
| 344 | asyncio.run(main()) |
no test coverage detected