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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.egg-info
*/__pycache__/
dist/
dist/
.venv
venv/
venv.bak/
2 changes: 1 addition & 1 deletion deepgram/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.5'
__version__ = '0.2.6'
13 changes: 11 additions & 2 deletions deepgram/transcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async def __call__(

class LiveTranscription:
_root = "/listen"
MESSAGE_TIMEOUT = 1.0

def __init__(self, options: Options,
transcription_options: LiveOptions) -> None:
Expand All @@ -65,8 +66,16 @@ async def __call__(self) -> 'LiveTranscription':
async def _start(self) -> None:
asyncio.create_task(self._receiver())
self._ping_handlers(LiveTranscriptionEvent.OPEN, self)

while not self.done:
incoming, body = await self._queue.get()
try:
incoming, body = await asyncio.wait_for(self._queue.get(), self.MESSAGE_TIMEOUT)
except asyncio.TimeoutError:
if self._socket.closed:
self.done = True
break
continue

if incoming:
try:
parsed: Union[
Expand Down Expand Up @@ -98,7 +107,7 @@ async def _receiver(self) -> None:
body = await self._socket.recv()
self._queue.put_nowait((True, body))
except Exception as exc:
pass # socket closed, will terminate on next loop
self.done = True # socket closed, will terminate on next loop

def _ping_handlers(self, event_type: LiveTranscriptionEvent,
body: Any) -> None:
Expand Down