Skip to content

Commit

Permalink
Merge pull request #25 from jhakulin/jhakulin/reconnect-fix
Browse files Browse the repository at this point in the history
Fix reconnection
  • Loading branch information
jhakulin authored Jan 13, 2025
2 parents 8da1ef7 + 17f247b commit 1c664ae
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 4 deletions.
19 changes: 19 additions & 0 deletions THIRD_PARTY_LICENSES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Third-Party Components and Licenses

This file provides information regarding third-party components included in this project (or referenced by it) and their respective licenses. Please review these licenses to ensure compliance.

---

## 1. Silero Voice Activity Detector (VAD) Model

- **Repository:**
[https://github.com/snakers4/silero-vad](https://github.com/snakers4/silero-vad)

- **License:**
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)

- **Full License Text:**
The full text of the CC BY-NC-SA 4.0 license can be accessed here:
[https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode](https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode)

**NOTE:** The Silero VAD model is not bundled directly in this repository’s wheel by default. If you opt to download and use it, you must comply with the CC BY-NC-SA 4.0 license—particularly regarding noncommercial use and share-alike obligations. Our code remains licensed under the MIT License, found in `LICENSE.md`.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
https://github.com/jhakulin/realtime-ai/releases/download/v0.1.7/realtime_ai-0.1.7-py3-none-any.whl
https://github.com/jhakulin/realtime-ai/releases/download/v0.1.8/realtime_ai-0.1.8-py3-none-any.whl
pyaudio
numpy
websockets
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="realtime-ai",
version="0.1.7",
version="0.1.8",
description="Python SDK for real-time audio processing with OpenAI's Realtime REST API.",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down
2 changes: 2 additions & 0 deletions src/realtime_ai/aio/realtime_ai_service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,6 @@ def options(self):
@options.setter
def options(self, options: RealtimeAIOptions):
self._options = options
if self._websocket_manager:
self._websocket_manager.options = options
logger.info("RealtimeAIServiceManager: Options updated.")
11 changes: 10 additions & 1 deletion src/realtime_ai/aio/web_socket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def _receive_messages(self):
async for message in self._websocket:
await self._service_manager.on_message_received(message)
logger.debug(f"WebSocketManager: Received message: {message}")
if "session_expired" in message and "maximum duration of 15 minutes" in message:
if "session_expired" in message and "Your session hit the maximum duration" in message:
logger.info("WebSocketManager: Reconnecting due to maximum duration reached.")
await asyncio.sleep(self._reconnect_delay)
await self.connect(reconnection=True)
Expand Down Expand Up @@ -101,3 +101,12 @@ async def send(self, message: dict):
else:
logger.error("WebSocketManager: Cannot send message. WebSocket is not connected.")
raise ConnectionError("WebSocket is not connected.")

@property
def options(self):
return self._options

@options.setter
def options(self, options: RealtimeAIOptions):
self._options = options
logger.info(f"WebSocketManager: Options updated: {options}")
2 changes: 2 additions & 0 deletions src/realtime_ai/realtime_ai_service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,6 @@ def options(self):
@options.setter
def options(self, options: RealtimeAIOptions):
self._options = options
if self._websocket_manager:
self._websocket_manager.options = options
logger.info("RealtimeAIServiceManager: Options updated.")
12 changes: 11 additions & 1 deletion src/realtime_ai/web_socket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def _on_close(self, ws, close_status_code, close_msg):
self._service_manager.on_disconnected(close_status_code, close_msg)

# If the session ended due to maximum duration, attempt to reconnect
if close_status_code == 1001 and "maximum duration of 15 minutes" in close_msg:
if close_status_code == 1001 and "Your session hit the maximum duration" in close_msg:
print("Session ended due to maximum duration. Reconnecting...")
logger.debug("WebSocketManager: Session ended due to maximum duration. Reconnecting...")
if self._options.enable_auto_reconnect:
self._schedule_reconnect()
Expand All @@ -119,3 +120,12 @@ def _schedule_reconnect(self):
time.sleep(self._reconnect_delay)
self._is_reconnection = True
self.connect()

@property
def options(self):
return self._options

@options.setter
def options(self, options: RealtimeAIOptions):
self._options = options
logger.info(f"WebSocketManager: Options updated: {options}")

0 comments on commit 1c664ae

Please sign in to comment.