feat(deepgram): add Deepgram speech-to-text and text-to-speech provider

SA
16d ago
+2142-2

Adds a deepgram provider type: Deepgram's pre-recorded speech-to-text and its text-to-speech behind /v1/audio/transcriptions and /v1/audio/speech. Set DEEPGRAM_API_KEY to enable it.

Speech-to-text (POST /listen: audio as the request body, options as query parameters)

  • response_format json, text, verbose_json, srt and vtt are all built from Deepgram's result. Segments and caption cues come from its utterances, since Deepgram has no caption output of its own.
  • Without language the request sends detect_language=true, because Deepgram would otherwise assume English. smart_format=true is on by default so transcripts are punctuated like OpenAI's.
  • Other form fields are forwarded as query parameters (diarize, keyterm, smart_format=false, ...).
  • prompt, stream=true, callback, callback_method and multichannel return 400 instead of being dropped.
  • Deepgram's reported duration is returned as OpenAI's usage, so transcriptions are metered by audio seconds. For text, srt and vtt the duration travels beside the body in a new core.AudioResponse.AudioSeconds field, which the transcription handler prices from before measuring the upload.
  • With diarize=true, verbose_json segments and words carry Deepgram's speaker number.

Text-to-speech (POST /speak)

  • A Deepgram model id names the voice (aura-2-thalia-en) and there is no voice parameter. Send the full id as model, or the family aura-2 as model with voice: "thalia-en". A voice that names another voice than the model (for example alloy) returns 400.
  • response_format mp3, opus, aac, flac, wav and pcm map to Deepgram's encoding / container / sample_rate. speed is fitted to Deepgram's 0.7-1.5 range, as the ElevenLabs adapter does. instructions returns 400.
  • Deepgram's bit_rate, sample_rate, mip_opt_out and tag are forwarded from extra JSON members; callback, callback_method and stream_format: "sse" return 400.
  • Audio is relayed as Deepgram produces it and metered by input characters.

Models come from Deepgram's GET /models: the pre-recorded speech-to-text models and the voice models, plus the short ids Deepgram documents (nova-3 for nova-3-general) and the voice families.

Testing

  • Unit tests against a fake upstream.
  • A local gateway run against a fake Deepgram server: model listing, both endpoints, the 400 paths, and the usage rows (characters, audio seconds).
  • No Deepgram key was available, so the request and response mapping is not verified against the live API. It follows the published reference: pre-recorded audio, text-to-speech, media output settings, models, errors. Checked live: GET /v1/models (public, no key) and the error body for an invalid key. The docs page carries the same note.

Part of #739. Remaining: live streaming over Deepgram's WebSocket APIs (/v1/realtime relays OpenAI-shaped sessions and has no event translation), Flux text-to-speech (/v2/speak), and voice listing.