-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket connection terminates unexpectedly during conversation in Python SDK demo #434
Comments
The issue reported here may be related to conversation limit on free-tier accounts. In some cases, conversations are also being unexpectedly cut off even before reaching this limit. To address this, you can update the demo.py script with additional error handling that gracefully manages these situations. The core issue appears to stem from unhandled Here’s a simplified version of the script to illustrate a potential workaround: import os
from websockets.exceptions import ConnectionClosedError
from elevenlabs.client import ElevenLabs
from elevenlabs.conversational_ai.conversation import Conversation
from elevenlabs.conversational_ai.default_audio_interface import DefaultAudioInterface
def main():
AGENT_ID = os.environ.get('AGENT_ID')
API_KEY = os.environ.get('ELEVENLABS_API_KEY')
if not AGENT_ID:
print("AGENT_ID environment variable must be set")
return
client = ElevenLabs(api_key=API_KEY)
conversation = None
try:
# Initialize conversation
conversation = Conversation(
client,
AGENT_ID,
requires_auth=bool(API_KEY),
audio_interface=DefaultAudioInterface()
)
# Start the session
print("Starting conversation session...")
conversation.start_session()
conversation_id = conversation.wait_for_session_end()
print(f"Conversation ended. ID: {conversation_id}")
except ConnectionClosedError as e:
error_msg = str(e).lower()
if "exceeded maximum duration" in error_msg:
print("Session duration exceeded. Please restart the session.")
else:
print(f"WebSocket error: {e}")
except Exception as e:
print(f"Unexpected error occurred: {e}")
finally:
# Ensure session cleanup
if conversation:
try:
conversation.end_session()
print("Session ended successfully.")
except Exception as cleanup_error:
print(f"Error during cleanup: {cleanup_error}")
if __name__ == "__main__":
main() |
Hi, |
Description
When running the ElevenLabs Python SDK Conversational AI demo on a Raspberry Pi 5, the WebSocket connection terminates unexpectedly after a few conversation exchanges. The agent successfully responds to the first two conversation exchanges, but during the third exchange, the voice agent's reply is cut off mid-response, followed by a WebSocket connection closure error.
Steps to reproduce
AGENT_ID
andELEVENLABS_API_KEY
)What happened instead
The WebSocket connection closes unexpectedly with a timeout error (0.5 seconds) in the websocket receive operation, terminating the conversation prematurely:
See additional context for the complete console log.
Relevant parameters or configurations
Code example
poetry run python convai/demo.py
Additional context
Error Pattern
Error Details
The error occurs in two stages:
The text was updated successfully, but these errors were encountered: