diff --git a/.github/workflows/check-actionlint.yaml b/.github/workflows/check-actionlint.yaml index 7e6404e4..34ecdbc7 100644 --- a/.github/workflows/check-actionlint.yaml +++ b/.github/workflows/check-actionlint.yaml @@ -14,7 +14,6 @@ jobs: checkactionlint: name: Check actionlint # Only run this job if we're in the main repo, not a fork. - if: github.repository == 'deepgram/deepgram-python-sdk' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/check-all.yaml b/.github/workflows/check-all.yaml index 915c464e..db2b2001 100644 --- a/.github/workflows/check-all.yaml +++ b/.github/workflows/check-all.yaml @@ -11,7 +11,6 @@ jobs: build: name: Change to Main/Release Branch # Only run this job if we're in the main repo, not a fork. - if: github.repository == 'deepgram/deepgram-python-sdk' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/check-lint.yaml b/.github/workflows/check-lint.yaml index d6b15c48..73aa7831 100644 --- a/.github/workflows/check-lint.yaml +++ b/.github/workflows/check-lint.yaml @@ -14,7 +14,6 @@ jobs: checklint: name: Check shell # Only run this job if we're in the main repo, not a fork. - if: github.repository == 'deepgram/deepgram-python-sdk' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/check-mdlint.yaml b/.github/workflows/check-mdlint.yaml index 0546ae6f..1243c132 100644 --- a/.github/workflows/check-mdlint.yaml +++ b/.github/workflows/check-mdlint.yaml @@ -15,7 +15,6 @@ jobs: checkmdlint: name: Check mdlint # Only run this job if we're in the main repo, not a fork. - if: github.repository == 'deepgram/deepgram-python-sdk' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/check-shell.yaml b/.github/workflows/check-shell.yaml index 09627f22..4e0fd851 100644 --- a/.github/workflows/check-shell.yaml +++ b/.github/workflows/check-shell.yaml @@ -16,7 +16,6 @@ jobs: checkshell: name: Check shell # Only run this job if we're in the main repo, not a fork. - if: github.repository == 'deepgram/deepgram-python-sdk' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/check-static.yaml b/.github/workflows/check-static.yaml index f692ab0a..4767d30e 100644 --- a/.github/workflows/check-static.yaml +++ b/.github/workflows/check-static.yaml @@ -14,7 +14,6 @@ jobs: checkstatic: name: Check static # Only run this job if we're in the main repo, not a fork. - if: github.repository == 'deepgram/deepgram-python-sdk' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/check-yaml.yaml b/.github/workflows/check-yaml.yaml index bbee1bee..3b262ecb 100644 --- a/.github/workflows/check-yaml.yaml +++ b/.github/workflows/check-yaml.yaml @@ -14,7 +14,6 @@ jobs: checkmdlint: name: Check mdlint # Only run this job if we're in the main repo, not a fork. - if: github.repository == 'deepgram/deepgram-python-sdk' runs-on: ubuntu-latest steps: diff --git a/deepgram/clients/common/v1/abstract_async_websocket.py b/deepgram/clients/common/v1/abstract_async_websocket.py index 2cb9fb13..c7cbd715 100644 --- a/deepgram/clients/common/v1/abstract_async_websocket.py +++ b/deepgram/clients/common/v1/abstract_async_websocket.py @@ -10,7 +10,6 @@ from abc import ABC, abstractmethod import websockets -from websockets.client import WebSocketClientProtocol from ....audio import Speaker from ....utils import verboselogs @@ -25,6 +24,8 @@ ) from .websocket_events import WebSocketEvents +WEBSOCKETS_CURRENT_MAJOR_VERSION = int(websockets.version.version.split(".", 1)[0]) + ONE_SECOND = 1 HALF_SECOND = 0.5 DEEPGRAM_INTERVAL = 5 @@ -44,7 +45,7 @@ class AbstractAsyncWebSocketClient(ABC): # pylint: disable=too-many-instance-at _endpoint: str _websocket_url: str - _socket: Optional[WebSocketClientProtocol] = None + _socket: Optional[websockets.connect] = None _listen_thread: Union[asyncio.Task, None] _delegate: Optional[Speaker] = None @@ -134,10 +135,20 @@ async def start( url_with_params = append_query_params(self._websocket_url, combined_options) try: + ws_connect_kwargs: Dict = { + "ping_interval": PING_INTERVAL, + } + + # Backward compatibility support with older versions of websockets. + # "extra_headers" was renamed to "additional_headers" in Python Websockets version 14 + if WEBSOCKETS_CURRENT_MAJOR_VERSION < 14: + ws_connect_kwargs["extra_headers"] = combined_headers + else: + ws_connect_kwargs["additional_headers"] = combined_headers + self._socket = await websockets.connect( url_with_params, - extra_headers=combined_headers, - ping_interval=PING_INTERVAL, + **ws_connect_kwargs, ) self._exit_event.clear() diff --git a/pyproject.toml b/pyproject.toml index 34893aac..0f29b781 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" httpx = "^0.25.2" -websockets = "^12.0" +websockets = ">=12.0" typing-extensions = "^4.9.0" dataclasses-json = "^0.6.3" aiohttp = "^3.9.1" diff --git a/requirements.txt b/requirements.txt index 53571822..96851807 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # pip install -r requirements.txt # standard libs -websockets==12.* +websockets>=12.0 httpx==0.* dataclasses-json==0.* dataclasses==0.* diff --git a/setup.py b/setup.py index 8e397772..3d844162 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ packages=find_packages(exclude=["tests"]), install_requires=[ "httpx>=0.25.2", - "websockets>=12.0,<14.0", + "websockets>=12.0", "dataclasses-json>=0.6.3", "typing_extensions>=4.9.0", "aiohttp>=3.9.1",