Skip to content

fix(stt): switch DeepGram from streaming to batch mode to fix truncation#44

Open
ReneXiong wants to merge 1 commit into
tover0314-w:mainfrom
ReneXiong:fix/deepgram-batch-mode
Open

fix(stt): switch DeepGram from streaming to batch mode to fix truncation#44
ReneXiong wants to merge 1 commit into
tover0314-w:mainfrom
ReneXiong:fix/deepgram-batch-mode

Conversation

@ReneXiong

@ReneXiong ReneXiong commented May 27, 2026

Copy link
Copy Markdown

Summary

Fix DeepGram speech-to-text truncation issue by switching from streaming WebSocket mode to batch REST API mode. Long utterances were being cut short because DeepGram's streaming mode sends truncated is_final at sentence boundaries.

Change Type

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • CI / Infrastructure

Changes

DeepGram's streaming WebSocket mode has a known issue where is_final transcripts can be truncated at sentence boundaries, causing long utterances to be cut short. The partial transcript before the is_final is often more complete than the final itself.

  • Batch mode: Buffer all audio during recording, send as WAV via POST /v1/listen REST API on disconnect
  • WAV builder: Add build_wav() helper to construct WAV header for raw PCM audio
  • Audio buffer limit: Cap at ~24 MB (~12.5 min at 16kHz mono) to prevent memory issues
  • Retry logic: Server errors (5xx) and timeouts retry up to 3 times with exponential backoff
  • Client injection: create_provider() now passes reqwest::Client to DeepGram via with_client()

Test Plan

  • Tested locally on macOS 26.5 (25F71) ARM-64
  • npm run build passes
  • npx vitest run passes (pre-existing failures in api.test.ts/authStore.test.ts unrelated to this change)
  • cargo clippy -- -D warnings passes
  • No regressions in existing functionality

Screenshots / Recordings

N/A (no UI changes)

Related Issues

Fixes DeepGram truncation issue where long utterances were cut short at sentence boundaries

DeepGram's streaming WebSocket mode sends truncated is_final at
sentence boundaries, causing long utterances to be cut off.

- Replace WebSocket streaming with REST API batch mode (POST /v1/listen)
- Buffer audio during recording, send all at once on stop
- No more truncation, no need for delay workarounds
- Pass reqwest::Client to DeepGram provider for connection reuse
@ReneXiong
ReneXiong requested a review from tover0314-w as a code owner May 27, 2026 02:15
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.

1 participant