@@ -42,41 +42,63 @@ tests/wire/__init__.py
4242tests/manual
4343
4444# WebSocket socket client files with manual fixes for binary audio data support:
45- # The generator incorrectly types \*\_media methods as `str` and uses `_send_model()` which
46- # calls `.dict()` on the input, causing runtime errors. These files are manually fixed to:
47- # 1. Change parameter type from `str` to `bytes` for all `*_media` methods
45+ # The generator incorrectly types media methods as `str` and uses `_send_model()` which calls
46+ # `.dict()` on the input, causing runtime errors. Additionally, response types and recv/iterator
47+ # methods don't handle binary audio data properly. These files are manually fixed to:
48+ # 1. Change parameter type from `str` to `bytes` for `send_media()` methods
4849# 2. Change from `_send_model()` to `_send()` to properly handle binary data
50+ # 3. Change response union types from `str` to `bytes` where binary audio is received
51+ # 4. Update recv(), __iter__(), __aiter__(), and start_listening() methods to handle both
52+ # binary bytes and JSON text messages
4953#
5054# src/deepgram/listen/v1/socket_client.py:
51- # - Line 57: Changed `async def send_listen_v_1_media (self, message: str)` to `message: bytes`
55+ # - Line 57: Changed `async def send_media (self, message: str)` to `message: bytes`
5256# - Line 60: Updated docstring from "sent as a str" to "sent as bytes"
5357# - Line 62: Changed `await self._send_model(message)` to `await self._send(message)`
54- # - Line 138: Changed `def send_listen_v_1_media (self, message: str)` to `message: bytes`
58+ # - Line 138: Changed `def send_media (self, message: str)` to `message: bytes`
5559# - Line 141: Updated docstring from "sent as a str" to "sent as bytes"
5660# - Line 143: Changed `self._send_model(message)` to `self._send(message)`
61+ # Note: Listen V1 only sends binary audio, receives JSON transcriptions (no binary response handling needed)
5762#
5863# src/deepgram/listen/v2/socket_client.py:
59- # - Line 54: Changed `async def send_listen_v_2_media (self, message: str)` to `message: bytes`
64+ # - Line 54: Changed `async def send_media (self, message: str)` to `message: bytes`
6065# - Line 57: Updated docstring from "sent as a str" to "sent as bytes"
6166# - Line 59: Changed `await self._send_model(message)` to `await self._send(message)`
62- # - Line 121: Changed `def send_listen_v_2_media (self, message: str)` to `message: bytes`
67+ # - Line 121: Changed `def send_media (self, message: str)` to `message: bytes`
6368# - Line 124: Updated docstring from "sent as a str" to "sent as bytes"
6469# - Line 126: Changed `self._send_model(message)` to `self._send(message)`
70+ # Note: Listen V2 only sends binary audio, receives JSON transcriptions (no binary response handling needed)
6571#
6672# src/deepgram/agent/v1/socket_client.py:
67- # - Line 136: Changed `async def send_agent_v_1_media(self, message: str)` to `message: bytes`
68- # - Line 139: Updated docstring from "sent as a str" to "sent as bytes"
69- # - Line 141: Changed `await self._send_model(message)` to `await self._send(message)`
70- # - Line 245: Changed `def send_agent_v_1_media(self, message: str)` to `message: bytes`
71- # - Line 248: Updated docstring from "sent as a str" to "sent as bytes"
72- # - Line 250: Changed `self._send_model(message)` to `self._send(message)`
73+ # - Line 53: Changed response union from `str` to `bytes` for binary audio responses
74+ # - Line 62-67: Updated `__aiter__()` to check `isinstance(message, bytes)` before JSON parsing
75+ # - Line 81-87: Updated `start_listening()` to handle binary messages in async loop
76+ # - Line 142-147: Added `async def send_media(self, message: bytes)` method (was missing from generator)
77+ # - Line 149-157: Updated `recv()` to check `isinstance(data, bytes)` before JSON parsing
78+ # - Line 179-184: Updated `__iter__()` to check `isinstance(message, bytes)` before JSON parsing
79+ # - Line 198-204: Updated `start_listening()` to handle binary messages in sync loop
80+ # - Line 259-264: Added `def send_media(self, message: bytes)` method (was missing from generator)
81+ # - Line 266-274: Updated `recv()` to check `isinstance(data, bytes)` before JSON parsing
82+ # Reason: Agent API sends binary audio input and receives binary audio output + JSON events
7383#
74- # Reason: Audio data must be sent as binary bytes, not strings. The `_send_model()` method
75- # expects Pydantic models and calls `.dict()` which fails on bytes/str. The `_send()` method
76- # properly handles bytes by passing them directly to the websocket connection.
77- # src/deepgram/listen/v1/socket_client.py
78- # src/deepgram/listen/v2/socket_client.py
79- # src/deepgram/agent/v1/socket_client.py
84+ # src/deepgram/speak/v1/socket_client.py:
85+ # - Line 25: Changed response union from `str` to `bytes` for binary audio responses
86+ # - Line 33-38: Updated `__aiter__()` to check `isinstance(message, bytes)` before JSON parsing
87+ # - Line 52-57: Updated `start_listening()` to handle binary messages in async loop
88+ # - Line 90-94: Updated `recv()` to check `isinstance(data, bytes)` before JSON parsing
89+ # - Line 115-120: Updated `__iter__()` to check `isinstance(message, bytes)` before JSON parsing
90+ # - Line 135-141: Updated `start_listening()` to handle binary messages in sync loop
91+ # - Line 177-181: Updated `recv()` to check `isinstance(data, bytes)` before JSON parsing
92+ # Reason: Speak API sends JSON text commands and receives binary audio output + JSON metadata
93+ #
94+ # General reason: Audio data must be sent/received as binary bytes, not strings. The `_send_model()`
95+ # method expects Pydantic models and calls `.dict()` which fails on bytes. The `_send()` method
96+ # properly handles bytes by passing them directly to the websocket connection. Response handling
97+ # must distinguish between binary audio data and JSON text messages.
98+ src/deepgram/listen/v1/socket_client.py
99+ src/deepgram/listen/v2/socket_client.py
100+ src/deepgram/agent/v1/socket_client.py
101+ src/deepgram/speak/v1/socket_client.py
80102
81103# Folders to ignore
82104.github
0 commit comments