Streaming Migration Guide: Deepgram to AssemblyAI
This guide walks through the process of migrating from Deepgram to AssemblyAI for transcribing streaming audio.
Get Started
Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for a free account and get your API key from your dashboard.
Side-By-Side Code Comparison
Below is a side-by-side comparison of a basic snippet to transcribe live audio by Deepgram and AssemblyAI using a microphone:
Deepgram
AssemblyAI
Authentication
Deepgram
AssemblyAI
When migrating from Deepgram to AssemblyAI, you’ll first need to handle authentication:
Get your API key from your AssemblyAI dashboard
Protect Your API Key
For improved security, store your API key as an environment variable.
Connection Parameters & Microphone Setup
Deepgram
AssemblyAI
Here are helpful things to know about connecting our streaming model:
-
One universal model – no model param needed - Just connect to
wss://streaming.assemblyai.com/v3/ws
. The live endpoint always uses our latest, best-performing model, so you can drop Deepgram’smodel="nova-3"
line entirely. -
format_turns=True
≈ Deepgram’spunctuate=true
- When the flag is set toTrue
, every Final message arrives with smart punctuation & casing. Set it toFalse
(or omit it) to get raw, lowercase text — useful if you do your own formatting. -
Partials are always on - like Deepgram’s
interim_results=true
- AssemblyAI streams immutable interim results automatically. There’s no switch to toggle. Expect fast, token-level updates that refine until each Final is emitted.
Opening the WebSocket
Deepgram
AssemblyAI
Tip: Adding error-handling and log lines (as in the AssemblyAI snippet) lets you see exactly when the socket opens, audio starts, or a read fails—catching issues early saving time debugging silent failures.
Receiving Messsages from the WebSocket
Deepgram
AssemblyAI
Helpful things to know about AssemblyAI’s message payloads:
-
Clear message types – Instead of checking
is_final
, you’ll receive explicit"Begin"
,"Turn"
, and"Termination"
events, making your logic simpler and more readable. -
Session metadata up-front – The first
"Begin"
message delivers asession_id
and expiry timestamp. You can log or surface these for tracing or billing. -
Formatted vs. raw finals – Each
"Turn"
object includes a booleanturn_is_formatted
. When you setformat_turns
toTrue
, punctuation/casing appears in theFinal Transcript
, so you can toggle display styles on the fly.
Handling Errors
Deepgram
AssemblyAI
Capture and log any errors emitted by the WebSocket connection to streamline troubleshooting and maintain smooth operation.
Closing the WebSocket
Deepgram
AssemblyAI
Helpful things to know about AssemblyAI’s WebSocket Closure:
-
Connection diagnostics on tap - If the socket closes unexpectedly, AssemblyAI supplies both a status code and a reason message (close_status_code, close_msg), so you know immediately whether the server timed out, refused auth, or encountered another error.
-
Metadata arrives at session start, not at close - Deepgram sends its final metadata only when the socket closes. AssemblyAI delivers session information up front in the initial “Begin” message, so you can log IDs and expiry times right away.
Opening the Microphone Stream & Creating a WebSocket
Deepgram
AssemblyAI
Session Shutdown
Deepgram
AssemblyAI
Helpful things to know about AssemblyAI’s shutdown:
-
JSON payload difference - When closing the stream with AssemblyAI, your JSON payload will be
{"type: "Terminate" }
instead of{"type: "CloseStream" }
-
Server handles idle timeouts - If you forget to send
"Terminate"
, AssemblyAI will close the socket after an idle window of one minute. -
No metadata race condition - Because AssemblyAI already provided session info at “Begin” and doesn’t append extra data at shutdown, you don’t have to sleep (time.sleep(0.5)) to wait for “final metadata” before closing—making the exit faster and less error-prone.
Resources
For additional information about using AssemblyAI’s Streaming Speech-To-Text API you can also refer to: