Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/elevenlabs/conversational_ai/conversation.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from abc import ABC, abstractmethod
import base64
import json
import threading
from typing import Callable, Optional, Awaitable, Union, Any, Literal, Dict, Tuple
import asyncio
import base64
from concurrent.futures import ThreadPoolExecutor
from enum import Enum
import json
import logging
import threading
from typing import Any, Awaitable, Callable, Dict, Literal, Optional, Tuple, Union
import urllib.parse

from websockets.sync.client import connect, Connection
import websockets
from websockets.exceptions import ConnectionClosedOK
from websockets.sync.client import Connection, connect

from ..base_client import BaseElevenLabs
from ..version import __version__


logger = logging.getLogger(__name__)


class ClientToOrchestratorEvent(str, Enum):
"""Event types that can be sent from client to orchestrator."""

Expand Down Expand Up @@ -613,7 +617,7 @@ def send_user_message(self, text: str):
try:
self._ws.send(json.dumps(event.to_dict()))
except Exception as e:
print(f"Error sending user message: {e}")
logger.error(f"Error sending user message: {e}")
raise

def register_user_activity(self):
Expand All @@ -631,7 +635,7 @@ def register_user_activity(self):
try:
self._ws.send(json.dumps(event.to_dict()))
except Exception as e:
print(f"Error registering user activity: {e}")
logger.error(f"Error registering user activity: {e}")
raise

def send_contextual_update(self, text: str):
Expand All @@ -653,7 +657,7 @@ def send_contextual_update(self, text: str):
try:
self._ws.send(json.dumps(event.to_dict()))
except Exception as e:
print(f"Error sending contextual update: {e}")
logger.error(f"Error sending contextual update: {e}")
raise

def _run(self, ws_url: str):
Expand All @@ -674,7 +678,7 @@ def input_callback(audio):
except ConnectionClosedOK:
self.end_session()
except Exception as e:
print(f"Error sending user audio chunk: {e}")
logger.error(f"Error sending user audio chunk: {e}")
self.end_session()

self.audio_interface.start(input_callback)
Expand All @@ -689,7 +693,7 @@ def input_callback(audio):
except TimeoutError:
pass
except Exception as e:
print(f"Error receiving message: {e}")
logger.error(f"Error receiving message: {e}")
self.end_session()

self._ws = None
Expand Down Expand Up @@ -866,7 +870,7 @@ async def send_user_message(self, text: str):
try:
await self._ws.send(json.dumps(event.to_dict()))
except Exception as e:
print(f"Error sending user message: {e}")
logger.error(f"Error sending user message: {e}")
raise

async def register_user_activity(self):
Expand All @@ -884,7 +888,7 @@ async def register_user_activity(self):
try:
await self._ws.send(json.dumps(event.to_dict()))
except Exception as e:
print(f"Error registering user activity: {e}")
logger.error(f"Error registering user activity: {e}")
raise

async def send_contextual_update(self, text: str):
Expand All @@ -906,7 +910,7 @@ async def send_contextual_update(self, text: str):
try:
await self._ws.send(json.dumps(event.to_dict()))
except Exception as e:
print(f"Error sending contextual update: {e}")
logger.error(f"Error sending contextual update: {e}")
raise

async def _run(self, ws_url: str):
Expand All @@ -926,7 +930,7 @@ async def input_callback(audio):
except ConnectionClosedOK:
await self.end_session()
except Exception as e:
print(f"Error sending user audio chunk: {e}")
logger.error(f"Error sending user audio chunk: {e}")
await self.end_session()

await self.audio_interface.start(input_callback)
Expand All @@ -945,7 +949,7 @@ async def input_callback(audio):
await self.end_session()
break
except Exception as e:
print(f"Error receiving message: {e}")
logger.error(f"Error receiving message: {e}")
await self.end_session()
break
finally:
Expand Down
18 changes: 10 additions & 8 deletions src/elevenlabs/music_custom.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import typing
import json
import logging
import re
import typing
from dataclasses import dataclass

from elevenlabs.music.client import MusicClient as AutogeneratedMusicClient, AsyncMusicClient as AutogeneratedAsyncMusicClient
from elevenlabs.types.music_prompt import MusicPrompt
from elevenlabs.music.types.music_compose_detailed_request_output_format import MusicComposeDetailedRequestOutputFormat
from elevenlabs.core.request_options import RequestOptions
from elevenlabs.music.client import AsyncMusicClient as AutogeneratedAsyncMusicClient
from elevenlabs.music.client import MusicClient as AutogeneratedMusicClient
from elevenlabs.music.types.music_compose_detailed_request_output_format import MusicComposeDetailedRequestOutputFormat
from elevenlabs.types.music_prompt import MusicPrompt

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)

logger = logging.getLogger(__name__)


@dataclass
class SongMetadata:
Expand Down Expand Up @@ -103,9 +107,8 @@ def _parse_multipart(self, stream: typing.Iterator[bytes]) -> MultipartResponse:
if json_line.strip() and json_line.startswith('{'):
try:
json_data = json.loads(json_line)
print('✓ Successfully parsed JSON metadata')
except json.JSONDecodeError as e:
print(f'Failed to parse JSON: {e}')
logger.error(f'Failed to parse composition plan JSON: {e}')
break

# Extract filename from headers
Expand Down Expand Up @@ -232,9 +235,8 @@ async def _parse_multipart_async(self, stream: typing.AsyncIterator[bytes]) -> M
if json_line.strip() and json_line.startswith('{'):
try:
json_data = json.loads(json_line)
print('✓ Successfully parsed JSON metadata')
except json.JSONDecodeError as e:
print(f'Failed to parse JSON: {e}')
logger.error(f'Failed to parse JSON: {e}')
break

# Extract filename from headers
Expand Down