TL;DR: I built a Go call-transcriber for Jitsi group calls: audio in from JVB, transcription via Deepgram, storage in MongoDB, events out on NATS.
Five protocol-level bugs shaped how it works.
Studying opus-transcriber-proxy
opus-transcriber-proxy is a transcription proxy from the Jitsi project: multi-provider (OpenAI, Deepgram, Gemini, xAI), built-in failover, translation. I studied it as a reference for how JVB’s transcription protocol works (a WebSocket JVB opens to stream conference audio out to a listener), and how a production relay handles multi-provider routing. Then I built a smaller version.
Its code revealed the protocol. More importantly, it showed me what this call flow actually needs: one provider, plus the app integration on top of it (correlating a transcript to the right conversation, since Jicofo’s MEETING_ID identifies one call, not the conversation; attributing each segment to a speaker as participants join and leave; storing all of it).
Reading opus-transcriber-proxy’s code settled a design question before writing any Go: which STT provider needs which audio format.
Deepgram accepts raw Opus passthrough; OpenAI, Gemini, and xAI need decoded PCM. The reference implementation decodes Opus in WebAssembly (a native addon is optional). So I went with Deepgram: no decoding needed.
Two other things carried over: the multiplexing pattern (one connection, tagged streams, described below), and how sessionId and tag are used.
sessionId is a query param that identifies which conference the connection belongs to. tag travels in each media event and identifies which participant within it. The reference implementation treats both as opaque strings (it doesn’t interpret their contents, just keys on them). It doesn’t specify how sessionId is assigned, just that the caller provides one. Jicofo fills it in, with the conference’s MEETING_ID.
Storing transcripts tied to a conversation needs a stable identity across calls. A MEETING_ID lasts for a single call, and a conversation spans many. That’s the problem a later section covers.
Architecture
JVB dials in as the client, and the transcriber runs an HTTP server waiting for it: ws://agent:8090/transcribe?sessionId={{MEETING_ID}}&sendBack=true.
JVB also retries a dropped connection indefinitely, with exponential backoff (0/1/2/4/8/16s, capped at 30s). The transcriber has no way to tell Prosody/Jicofo to turn that off.
To bound STT costs (Deepgram bills for the audio duration), the transcriber caps STT usage per transcript, configurable per deployment. To avoid reconnect storms, it doesn’t reject JVB’s connections. Instead, it tracks usage across reconnects and stops dialing Deepgram once the budget is exhausted. Only time with audio arriving is counted, so muted time adds no usage.
The transcriber turns unreliable signals from JVB and Deepgram into stored, queryable state.
Internally, one WebSocket connection carries every participant’s audio for a conference. JVB multiplexes each speaker’s stream onto it, distinguished by a tag field, rather than opening one connection per participant. The session’s read loop dispatches on message type:
// simplified
switch env.Event {
case "media":
sess.handleMedia(raw, logger) // base64 Opus payload, tagged per participant
case "start":
// a new participant stream began
case "ping":
// answered with a pong, shown below
}
Each media event carries base64-encoded Opus for a tag. The session keeps a map[string]Provider keyed per participant (not per conference), so handleMedia decodes the payload and forwards it to that tag’s stream.
Five bugs
Most of these failed quietly. The system looked healthy until I measured.
Deepgram’s KeepAlive timeout (30–64 seconds into a call)
Transcription would cut off mid-call after ~30–64 seconds, even though the connection looked healthy. A pause in the speech closed the connection, because Deepgram drops connections that receive neither audio nor a message within its inactivity timeout.
A goroutine now sends Deepgram’s documented KeepAlive message on a fixed ticker, whether or not audio is flowing:
func (p *deepgramProvider) keepAliveLoop() {
ticker := time.NewTicker(keepAliveInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
p.writeMu.Lock()
err := p.conn.WriteJSON(map[string]string{"type": "KeepAlive"})
p.writeMu.Unlock()
if err != nil {
return
}
case <-p.stopKeepAlive:
return
case <-p.done:
return
}
}
}
The keepAlive loop needs its own goroutine so it sends KeepAlive messages on a fixed schedule, independent of audio flow. If it were serialized with SendAudio, a pause in incoming frames could delay the KeepAlive and trigger Deepgram’s idle timeout.
This loop and SendAudio both write to the same WebSocket connection from different goroutines, and gorilla/websocket only allows one writer at a time, so writeMu guards every write.
The JVB connection needs the same rule. The pong from the read loop and each participant’s transcription results are written from different goroutines, so session.writeJSON holds a mutex around every write:
func (sess *session) writeJSON(v any) error {
sess.writeMu.Lock()
defer sess.writeMu.Unlock()
return sess.conn.WriteJSON(v)
}
Two cancellation channels (stopKeepAlive, done) let the loop exit cleanly instead of leaking a goroutine after the session ends.
Deepgram’s idle timeout isn’t a bug. It’s a constraint the transcriber works within.
JVB’s WebSocket ping/pong ID echo
The WebSocket connection to JVB was reconnecting every ~13 seconds, even though data flowed fine and the transcriber logged no errors. JVB sends a JSON ping event with an id and expects a pong with the matching id. The transcriber answered with id 0 every time, so JVB reconnected after its ping interval plus timeout (~13 seconds). JVB logs Received pong with id=..., expected id=... when the two differ. Echoing the id stopped it (the call now goes through the writeJSON mutex described above):
-_ = sess.conn.WriteJSON(Envelope{Event: "pong"})
+_ = sess.conn.WriteJSON(Envelope{Event: "pong", Id: env.Id})
Missing audio parameters (0-duration transcriptions)
Deepgram connections would “succeed” (the handshake completed, no errors logged), but transcription would silently produce 0 seconds of audio processed, with empty transcripts. Deepgram’s WebSocket endpoint for raw Opus accepts ?encoding=opus&channels=2&sample_rate=48000, and the connection request sent encoding=opus but omitted channels and sample_rate. Deepgram accepted the connection with no error, but couldn’t decode the frames without knowing the channel count and sample rate, so it silently processed 0 seconds.
Including all required parameters solved it:
q.Set("encoding", "opus")
// ...
q.Set("channels", "2")
q.Set("sample_rate", "48000")
The end-of-stream metadata from Deepgram showed duration=0.0 and channels=0.
Unhandled Deepgram messages
Transcription would stop and the logs showed nothing. readLoop skipped any message it couldn’t parse or didn’t expect, and ignored close codes, with a bare continue. That silence also hid the three problems above for longer than it should have. It now logs the close code and reason, and any message that isn’t a result:
if resp.Type != "" && resp.Type != "Results" {
p.logger.Warn("deepgram non-transcript message", "type", resp.Type, "raw", string(raw))
continue
}
Like the missing audio parameters, this took longer to catch. The system just quietly did less than it should.
Writes to a closed Deepgram stream (log flood)
When Deepgram closed a connection, the session kept the closed stream in its map. Every later audio frame for that participant tried to write to it and failed, which flooded the logs with send failures. A failed send now ends that stream: dropStream removes it, and the next frame opens a fresh connection.
if err := stream.SendAudio(opus); err != nil {
logger.Error("provider send failed, dropping closed stream", "tag", ev.Media.Tag, "error", err)
sess.dropStream(ev.Media.Tag)
}
This recovers a closed stream without a restart. It adds no delay between attempts, so if Deepgram refuses new connections, each frame would still try one. I have not tested that case.
Session correlation: the per-call MEETING_ID problem
Jicofo only knows its MEETING_ID, not one-chat’s conversationId, so passing the conversation ID isn’t an option. Prosody generates that MEETING_ID when it creates the room and keeps it until the room is destroyed, and Jicofo copies it into the transcription URL. A participant who reconnects to a live room keeps the same ID, but the next call in the same conversation gets a new ID. So MEETING_ID names a call, not the conversation, and I couldn’t query “all transcripts for conversation X”.
Querying JVB’s /debug endpoint resolves the stable Room ID, cached since the mapping is static for the life of a conference:
func (r *ConversationIDResolver) Resolve(meetingID string) (string, bool) {
// ... return the cached ID if present, else GET baseURL + "/debug"
for _, conf := range body.Conferences {
if conf.MeetingID != meetingID {
continue
}
// name is a room JID like "<conversationId>@muc.meet.example.com"
conversationID, _, ok := strings.Cut(conf.Name, "@")
if !ok || conversationID == "" {
return "", false
}
r.mu.Lock()
r.cache[meetingID] = conversationID
r.mu.Unlock()
return conversationID, true
}
return "", false
}
JVB’s /debug response only exposes the conversation ID inside a room JID (<conversationId>@muc.meet.example.com), so the identifier is the local part before the @.
The MEETING_ID is resolved once per conference; everything stored after that is keyed on the conversation ID.
Speaker attribution
Once transcripts are stored, the next challenge is speaker attribution. JVB’s media.tag identifies an audio source, not a user, and Jitsi’s participant metadata (usernames, IDs) lives in memory in JVB. A CallParticipant collection written by the backend maps one to the other:
{
conversationId: ObjectId,
jitsiParticipantId: string, // JVB endpoint ID
user: ObjectId,
joinedAt: Date,
}
The tag turned out to be <endpointId>-<ssrc>. The lookup keeps only the part before the -:
endpointID, _, _ := strings.Cut(tag, "-")
When a transcript segment arrives, the lookup runs on conversationId and jitsiParticipantId, and the resulting userId is stored with the segment.
Then it publishes to NATS on the subject transcription.segment; userId is omitted when the speaker doesn’t resolve:
{
"conversationId": "...",
"userId": "...",
"text": "...",
"timestamp": 1695412567890,
"confidence": 0.98,
"isFinal": true
}
Downstream consumers (frontends, analytics, summarization workflows) subscribe to this event and build their views.
Publishing events decouples the source of truth (the transcriber) from its consumers (UI, analytics, workflows). Each one reacts on its schedule, without the transcriber needing to know who’s listening.
Takeaways
What I learned building this:
Each protocol had requirements that only showed up under real audio. The KeepAlive message, the matching pong
id, the channel and sample-rate parameters and the tag suffix all surfaced when I ran a call through the stack, not when I read about it.Silent failures are difficult to catch. Most of the bugs above logged no error and left a healthy-looking connection. A local run with real audio in a real conference exposed them.
Most of the work was keeping state consistent. Who is speaking, which call this is and which conversation it belongs to mattered more than calling Deepgram. MEETING_ID names a call, so I matched it to the conversation’s stable ID.
Timeouts are normal operation here. KeepAlive, JVB’s ping interval and JVB’s reconnect backoff are not edge cases, and the transcriber works within them.
What’s next
It’s deployed and running.
Segments already publish to NATS as they’re finalized, but nothing subscribes yet. The frontend gets its live updates from a MongoDB Change Stream instead. Next is wiring NATS consumers so they can react to those events.