Skip to content

docs(examples): add resilient live transcription reconnection example - #776

Merged
GregHolmes merged 2 commits into
mainfrom
gh/example-live-reconnect
Sep 2, 2026
Merged

docs(examples): add resilient live transcription reconnection example#776
GregHolmes merged 2 commits into
mainfrom
gh/example-live-reconnect

Conversation

@dg-coreylweathers

@dg-coreylweathers dg-coreylweathers commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

What

Adds examples/17-transcription-live-reconnect.py, a production-oriented reconnection example for streaming speech-to-text that will back the upcoming speech-to-text/streaming/guides/production docs page. Also adds the previously missing README entry for example 16.

What it demonstrates

  • Exponential backoff with full jitter and a retry cap
  • Reconnect-worthy close codes (1006/1011/1012/1013) distinguished from normal (1000/1001) and fatal closure
  • Audio buffered in a producer thread during the disconnect gap, drained after reconnect at no more than 1.25x real time
  • Original connection options stored once and re-applied verbatim on every reconnect
  • Continuous timestamps across sessions via an offset
  • Deterministic producer shutdown on successful, fatal, and interrupted paths
  • Clean shutdown via CloseStream
  • An opt-in, clearly fenced demo fault injector (SIMULATE_DROP=1) that severs the TCP socket mid-stream to demonstrate recovery

Uses only this SDK's Listen V1 socket client; every method and event name is verified against source.

Validation

  • Live normal run: transcribed the bundled WAV and exited 0 over one connection
  • Live forced-drop run: recovered from a mid-stream 1006 close, resumed with increasing timestamps, and exited 0 over two connections
  • Live bad-key run: exited 1 with a one-line message; the key never appeared in output
  • Live probe: confirmed the documented silence timeout closes with 1011 and NET-0001
  • Full CI: Python 3.10-3.13 compile and test matrix passed
  • Local Docker-backed suite: 1007 passed, 1 skipped
  • Ruff and mypy clean

Related finding

The bad-key probe surfaced a pre-existing SDK compatibility issue: core/websocket_compat.py may bind legacy InvalidStatusCode while sync clients raise distinct InvalidStatus on rejected WebSocket handshakes in some supported websockets versions. This example handles both shapes; the SDK-wide generator versus hand-patch decision remains separate from this example.

Adds examples/17-transcription-live-reconnect.py demonstrating the
resilience patterns recommended for production streaming STT:
exponential backoff with full jitter and a retry cap, reconnect-worthy
close codes distinguished from normal/fatal closure, audio buffered
across the disconnect gap and resumed on reconnect, original connection
options re-applied, continuous timestamps across sessions, and clean
shutdown via CloseStream. Includes a demo-only fault injector that
severs the TCP socket mid-stream to show recovery; validated live
against api.deepgram.com.

Also lists the previously missing example 16 in examples/README.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Branch Rate Complexity Health
src.deepgram 97% 94% 0
src.deepgram.agent 100% 100% 0
src.deepgram.agent.v1 98% 100% 0
src.deepgram.agent.v1.settings 100% 100% 0
src.deepgram.agent.v1.settings.think 100% 100% 0
src.deepgram.agent.v1.settings.think.models 97% 100% 0
src.deepgram.auth 100% 100% 0
src.deepgram.auth.v1 100% 100% 0
src.deepgram.auth.v1.tokens 97% 100% 0
src.deepgram.core 88% 81% 0
src.deepgram.errors 100% 100% 0
src.deepgram.helpers 100% 95% 0
src.deepgram.listen 100% 100% 0
src.deepgram.listen.v1 98% 93% 0
src.deepgram.listen.v1.media 97% 100% 0
src.deepgram.listen.v2 98% 93% 0
src.deepgram.manage 100% 100% 0
src.deepgram.manage.v1 100% 100% 0
src.deepgram.manage.v1.models 96% 100% 0
src.deepgram.manage.v1.projects 97% 100% 0
src.deepgram.manage.v1.projects.billing 100% 100% 0
src.deepgram.manage.v1.projects.billing.balances 96% 100% 0
src.deepgram.manage.v1.projects.billing.breakdown 97% 100% 0
src.deepgram.manage.v1.projects.billing.fields 97% 100% 0
src.deepgram.manage.v1.projects.billing.purchases 97% 100% 0
src.deepgram.manage.v1.projects.keys 96% 100% 0
src.deepgram.manage.v1.projects.members 97% 100% 0
src.deepgram.manage.v1.projects.members.invites 96% 100% 0
src.deepgram.manage.v1.projects.members.scopes 96% 100% 0
src.deepgram.manage.v1.projects.models 96% 100% 0
src.deepgram.manage.v1.projects.usage 98% 100% 0
src.deepgram.manage.v1.projects.usage.breakdown 97% 100% 0
src.deepgram.manage.v1.projects.usage.fields 97% 100% 0
src.deepgram.read 100% 100% 0
src.deepgram.read.v1 100% 100% 0
src.deepgram.read.v1.text 98% 100% 0
src.deepgram.self_hosted 100% 100% 0
src.deepgram.self_hosted.v1 100% 100% 0
src.deepgram.self_hosted.v1.distribution_credentials 96% 100% 0
src.deepgram.speak 100% 100% 0
src.deepgram.speak.v1 98% 97% 0
src.deepgram.speak.v1.audio 91% 80% 0
src.deepgram.speak.v2 98% 93% 0
src.deepgram.speak.v2.audio 100% 100% 0
src.deepgram.voice_agent 100% 100% 0
src.deepgram.voice_agent.configurations 95% 100% 0
src.deepgram.voice_agent.variables 95% 100% 0
Summary 95% (6498 / 6813) 91% (1419 / 1552) 0

Scope: hand-maintained SDK logic. Fern-generated data models (types/, requests/), package __init__.py files, version.py, and the unused core/http_sse/ scaffolding are excluded — see .coveragerc. Unscoped whole-package coverage is ~70%.

@GregHolmes GregHolmes changed the title docs: add production-grade live transcription reconnection example docs(examples): add resilient live transcription reconnection example Sep 2, 2026
@GregHolmes
GregHolmes merged commit 96b2d11 into main Sep 2, 2026
12 checks passed
@GregHolmes
GregHolmes deleted the gh/example-live-reconnect branch September 2, 2026 09:56
GregHolmes added a commit that referenced this pull request Sep 3, 2026
🤖 I have created a release *beep* *boop*
---


##
[7.8.1](v7.8.0...v7.8.1)
(2026-09-03)


### Bug Fixes

* **TextBuilder:** `ssml_to_deepgram()` now preserves a `<phoneme>`
pronunciation when its valid `ph` and `alphabet` attributes appear in
either order.
([#741](#741))
([7fd4b63](7fd4b63))
* **Credentials:** Explicitly passing `api_key=None` continues to
disable ambient `DEEPGRAM_API_KEY` lookup, which is important for
multi-tenant and test environments.
([#778](#778))
([e675990](e675990))
* **Credentials:** `DeepgramClient()` and `AsyncDeepgramClient()` now
resolve `DEEPGRAM_API_KEY` when constructed, so `load_dotenv()` can run
after importing the SDK. Closes
[#734](#734).
([#767](#767))
([ec362ec](ec362ec))
* **Custom transports:** Speak V2 WebSocket connections now honor
`transport_factory`, matching the routing behavior of other WebSocket
APIs for proxies, test doubles, and custom-hosted transports.
([#766](#766))
([0980663](0980663))


### Documentation

* **Transcription:** Clarified that Nova-3 assumes English when
`language` is omitted; non-English and multilingual audio require an
explicit language such as `fr` or `multi`.
([#771](#771))
([4574337](4574337))
* **Examples:** Added Listen V1 live microphone transcription with
optional `sounddevice`, device selection, bounded audio buffering,
transcript output, and clean Ctrl-C shutdown.
([#780](#780))
([08f0471](08f0471))
* **Examples:** Added a resilient Listen V1 live transcription pattern
with exponential backoff, reconnect-aware audio buffering, timestamp
continuity, and clean shutdown.
([#776](#776))
([96b2d11](96b2d11))
* **Examples:** Added an application-owned Voice Agent session recorder
that serializes received transcripts, function calls, and latency
reports as JSON while leaving consent, redaction, retention, and storage
policy to the application. Closes
[#775](#775).
([#781](#781))
([30ad152](30ad152))
* **Text-to-Speech:** Corrected streaming synthesis snippets to iterate
the response byte chunks instead of accessing a nonexistent `.stream`
attribute.
([#749](#749))
([178724e](178724e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Greg Holmes <greg.holmes@deepgram.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants