Skip to navigation

Live Audio Capture & Frame Decoding

View as Markdown

MeetStream streams real-time meeting audio to your application over a WebSocket connection. Audio arrives as speaker-tagged binary frames. Google Meet and Microsoft Teams send frames of type 0x01 at 48 kHz. Zoom sends frames of type 0x04, which carry the sample rate in the header (32 kHz).


Overview

When you create a bot with the live_audio_required configuration, MeetStream opens a WebSocket connection from the bot to your server and continuously streams binary audio frames for the duration of the meeting.

Enabling Live Audio

Include live_audio_required in your Create Bot API request:

{
"meeting_link": "https://meet.google.com/abc-defg-hij",
"live_audio_required": {
"websocket_url": "wss://your-server.com/audio"
}
}

The websocket_url is a WebSocket endpoint you host. MeetStream connects to it as a client.


Connection Lifecycle

1. Bot connects to your WebSocket endpoint

The bot initiates the connection when it joins the meeting.

2. Bot sends a JSON text handshake

The first message is always a JSON text frame:

{
"type": "ready",
"bot_id": "bot_abc123",
"message": "Ready to receive messages"
}

3. Binary audio frames stream continuously

Every subsequent message is a binary WebSocket frame containing PCM audio with embedded speaker metadata. Frames arrive continuously for the duration of the meeting.

4. Connection closes when the bot leaves

The WebSocket closes with a normal 1000 close code when the bot exits the meeting.

Timeline

Connection Lifecycle


Binary Frame Format

Every audio frame is a single binary WebSocket message. Byte 0 is the message type:

  • 0x01: Google Meet and Microsoft Teams. PCM16 mono at 48 kHz.
  • 0x04: Zoom. The header carries the sample rate and the channel count.

Type 0x01 (Google Meet and Microsoft Teams):

┌──────────┬────────────┬────────────┬──────────────┬──────────────┬──────────────────┐
│ msg_type │ sid_length │ speaker_id │ sname_length │ speaker_name │ pcm_audio_data │
│ 1 byte │ 2 bytes │ L1 bytes │ 2 bytes │ L2 bytes │ remaining bytes │
└──────────┴────────────┴────────────┴──────────────┴──────────────┴──────────────────┘

Type 0x04 (Zoom):

┌──────────┬─────────────┬──────────┬────────────┬────────────┬──────────────┬──────────────┬──────────────────┐
│ msg_type │ sample_rate │ channels │ sid_length │ speaker_id │ sname_length │ speaker_name │ pcm_audio_data │
│ 1 byte │ 4 bytes │ 1 byte │ 2 bytes │ L1 bytes │ 2 bytes │ L2 bytes │ remaining bytes │
└──────────┴─────────────┴──────────┴────────────┴────────────┴──────────────┴──────────────┴──────────────────┘

Field-by-Field Breakdown

H is the header length before the speaker fields: 1 for 0x01 frames and 6 for 0x04 frames.

OffsetSizeTypeFieldDescription
01 byteuint8msg_typeMessage type. 0x01 for Google Meet and Teams (48 kHz mono). 0x04 for Zoom: bytes 1 to 4 are the sample rate (unsigned 32-bit little-endian) and byte 5 is the channel count. The speaker fields follow.
14 bytesuint32 LEsample_rate0x04 frames only. Sample rate in Hz, for example 32000.
51 byteuint8channels0x04 frames only. Channel count, 1 (mono).
H2 bytesuint16 LEsid_lengthByte length of the speaker_id string that follows.
H + 2L1 bytesUTF-8speaker_idPlatform-specific unique identifier for the speaker.
H + 2 + L12 bytesuint16 LEsname_lengthByte length of the speaker_name string that follows.
H + 4 + L1L2 bytesUTF-8speaker_nameDisplay name of the speaker as shown in the meeting.
H + 4 + L1 + L2remainingint16 LEpcm_audioRaw PCM audio samples.

Important

  • There are no delimiters between fields. The format is length-prefixed: you read the 2-byte length, then read that many bytes for the string.
  • The sid_length and sname_length values change depending on the length of the speaker’s name and ID. These are not fixed values or delimiters. They are standard unsigned 16-bit little-endian integers encoding a string length.
  • Read byte 0 first. 0x01 and 0x04 are the audio message types. Skip frames with any other type, so that your code keeps working if new types are added.

Audio Properties

PropertyValue
EncodingSigned 16-bit integer (PCM16)
Byte orderLittle-endian
Sample rateGoogle Meet and Teams: 48,000 Hz. Zoom: the rate in the 0x04 header (32,000 Hz)
Channels1 (mono)
Bit depth16 bits (2 bytes per sample)
ContainerNone: raw samples, no WAV/MP3/Ogg headers

To calculate duration from a frame:

duration_seconds = (len(pcm_audio_data) / 2) / sample_rate

Hex Dump Walkthrough

A Google Meet frame (0x01) from a speaker named "Alice" with ID "user_42":

Hex: 01 07 00 75 73 65 72 5F 34 32 05 00 41 6C 69 63 65 XX XX XX XX ...
── ───── ───────────────────── ───── ─────────────── ─────────────
│ │ │ │ │ │
│ │ │ │ │ └─ PCM16 LE audio samples
│ │ │ │ └─ "Alice" (5 bytes UTF-8)
│ │ │ └─ sname_length = 5
│ │ └─ "user_42" (7 bytes UTF-8)
│ └─ sid_length = 7
└─ msg_type = 0x01 (PCM audio)

A Teams frame (0x01) from "James Chen" with ID "James Chen":

Hex: 01 0A 00 4A 61 6D 65 73 20 43 68 65 6E 0A 00 4A 61 6D 65 73 20 43 68 65 6E XX XX ...
── ───── ────────────────────────────── ───── ────────────────────────────── ────────
│ │ │ │ │ │
│ │ │ │ │ └─ PCM audio
│ │ │ │ └─ "James Chen" (10 bytes)
│ │ │ └─ sname_length = 10 (0x0A)
│ │ └─ "James Chen" (10 bytes)
│ └─ sid_length = 10 (0x0A)
└─ msg_type = 0x01

A Zoom frame (0x04) at 32 kHz mono from "Alice" with ID "16778240":

Hex: 04 00 7D 00 00 01 08 00 31 36 37 37 38 32 34 30 05 00 41 6C 69 63 65 XX XX ...
── ─────────── ── ───── ─────────────────────── ───── ────────────── ────────
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ └─ PCM audio
│ │ │ │ │ │ └─ "Alice" (5 bytes)
│ │ │ │ │ └─ sname_length = 5
│ │ │ │ └─ "16778240" (8 bytes)
│ │ │ └─ sid_length = 8
│ │ └─ channels = 1
│ └─ sample_rate = 32000 (0x00007D00, little-endian)
└─ msg_type = 0x04 (PCM audio with format header)

Note: 0x07 = 7, 0x0A = 10, 0x0E = 14, etc. These are string lengths, not protocol markers.


Decoding Examples

Each decoder reads byte 0, takes the sample rate from the frame, and returns it with the speaker fields and the audio.

Python

def decode_audio_frame(data: bytes):
"""Decode a MeetStream binary audio frame.
Returns:
tuple: (speaker_id, speaker_name, sample_rate, pcm_bytes) on success
None: if the frame is malformed or has an unknown type
"""
if len(data) < 5:
return None
if data[0] == 0x01: # Google Meet and Microsoft Teams: 48 kHz mono
sample_rate, off = 48000, 1
elif data[0] == 0x04: # Zoom: sample rate and channels in the header
sample_rate, off = int.from_bytes(data[1:5], "little"), 6
else:
return None
# Speaker ID: 2-byte length prefix + UTF-8 string
sid_len = int.from_bytes(data[off : off + 2], "little")
off += 2
speaker_id = data[off : off + sid_len].decode("utf-8")
off += sid_len
# Speaker Name: 2-byte length prefix + UTF-8 string
sname_len = int.from_bytes(data[off : off + 2], "little")
off += 2
speaker_name = data[off : off + sname_len].decode("utf-8")
off += sname_len
# Remaining bytes are raw PCM16 LE audio
return speaker_id, speaker_name, sample_rate, data[off:]

JavaScript / Node.js

function decodeAudioFrame(buffer) {
if (buffer.length < 5) return null;
let sampleRate, off;
if (buffer[0] === 0x01) { // Google Meet and Microsoft Teams: 48 kHz mono
sampleRate = 48000; off = 1;
} else if (buffer[0] === 0x04) { // Zoom: sample rate and channels in the header
if (buffer.length < 8) return null;
sampleRate = buffer.readUInt32LE(1); off = 6;
} else {
return null;
}
// Speaker ID
const sidLen = buffer.readUInt16LE(off);
off += 2;
const speakerId = buffer.subarray(off, off + sidLen).toString("utf-8");
off += sidLen;
// Speaker Name
const snameLen = buffer.readUInt16LE(off);
off += 2;
const speakerName = buffer.subarray(off, off + snameLen).toString("utf-8");
off += snameLen;
// PCM audio
const pcmData = buffer.subarray(off);
return { speakerId, speakerName, sampleRate, pcmData };
}

Go

import (
"encoding/binary"
"errors"
)
type AudioFrame struct {
SpeakerID string
SpeakerName string
SampleRate int
PCMData []byte
}
func DecodeAudioFrame(data []byte) (*AudioFrame, error) {
if len(data) < 5 {
return nil, errors.New("invalid frame")
}
var sampleRate, off int
switch data[0] {
case 0x01: // Google Meet and Microsoft Teams: 48 kHz mono
sampleRate, off = 48000, 1
case 0x04: // Zoom: sample rate and channels in the header
if len(data) < 8 {
return nil, errors.New("frame too short for header")
}
sampleRate, off = int(binary.LittleEndian.Uint32(data[1:5])), 6
default:
return nil, errors.New("unknown message type")
}
sidLen := int(binary.LittleEndian.Uint16(data[off : off+2]))
off += 2
if len(data) < off+sidLen+2 {
return nil, errors.New("frame too short for speaker ID")
}
speakerID := string(data[off : off+sidLen])
off += sidLen
snameLen := int(binary.LittleEndian.Uint16(data[off : off+2]))
off += 2
if len(data) < off+snameLen {
return nil, errors.New("frame too short for speaker name")
}
speakerName := string(data[off : off+snameLen])
off += snameLen
return &AudioFrame{
SpeakerID: speakerID,
SpeakerName: speakerName,
SampleRate: sampleRate,
PCMData: data[off:],
}, nil
}

Java

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
public class MeetstreamAudioFrame {
public final String speakerId;
public final String speakerName;
public final int sampleRate;
public final byte[] pcmData;
private MeetstreamAudioFrame(String speakerId, String speakerName, int sampleRate, byte[] pcmData) {
this.speakerId = speakerId;
this.speakerName = speakerName;
this.sampleRate = sampleRate;
this.pcmData = pcmData;
}
public static MeetstreamAudioFrame decode(byte[] data) {
if (data.length < 5) return null;
ByteBuffer buf = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
int msgType = buf.get() & 0xFF;
int sampleRate;
if (msgType == 0x01) { // Google Meet and Microsoft Teams: 48 kHz mono
sampleRate = 48000;
} else if (msgType == 0x04) { // Zoom: sample rate and channels in the header
if (data.length < 8) return null;
sampleRate = buf.getInt();
buf.get(); // channels
} else {
return null;
}
int sidLen = buf.getShort() & 0xFFFF;
byte[] sidBytes = new byte[sidLen];
buf.get(sidBytes);
String speakerId = new String(sidBytes, StandardCharsets.UTF_8);
int snameLen = buf.getShort() & 0xFFFF;
byte[] snameBytes = new byte[snameLen];
buf.get(snameBytes);
String speakerName = new String(snameBytes, StandardCharsets.UTF_8);
byte[] pcmData = new byte[buf.remaining()];
buf.get(pcmData);
return new MeetstreamAudioFrame(speakerId, speakerName, sampleRate, pcmData);
}
}

Full Receiver Examples

Python — Receive and Log

import asyncio
import json
import websockets
async def receive_audio():
async with websockets.connect("wss://your-server.com/audio") as ws:
async for message in ws:
# First message is a JSON text handshake
if isinstance(message, str):
handshake = json.loads(message)
print(f"Bot connected: {handshake['bot_id']}")
continue
# All subsequent messages are binary audio frames
result = decode_audio_frame(message)
if result is None:
continue
speaker_id, speaker_name, sample_rate, pcm_bytes = result
num_samples = len(pcm_bytes) // 2
duration_ms = (num_samples / sample_rate) * 1000
print(f"[{speaker_name}] {num_samples} samples ({duration_ms:.0f}ms)")
asyncio.run(receive_audio())

Node.js — Receive and Log

const WebSocket = require("ws");
const ws = new WebSocket("wss://your-server.com/audio");
ws.on("message", (data, isBinary) => {
if (!isBinary) {
const handshake = JSON.parse(data.toString());
console.log(`Bot connected: ${handshake.bot_id}`);
return;
}
const frame = decodeAudioFrame(data);
if (!frame) return;
const numSamples = frame.pcmData.length / 2;
const durationMs = (numSamples / frame.sampleRate) * 1000;
console.log(`[${frame.speakerName}] ${numSamples} samples (${durationMs.toFixed(0)}ms)`);
});

Working with PCM Audio

Convert to NumPy Array (Python)

import numpy as np
# To int16 sample array
samples = np.frombuffer(pcm_bytes, dtype=np.int16)
# To float32 (-1.0 to 1.0) — standard format for ML models and audio libraries
float_samples = samples.astype(np.float32) / 32768.0

Save as WAV File (Python)

import wave
def save_wav(pcm_bytes: bytes, path: str, sample_rate: int = 48000):
with wave.open(path, "wb") as wf:
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(sample_rate)
wf.writeframes(pcm_bytes)

Accumulate and Save a Full Meeting Recording

import wave
audio_buffer = bytearray()
recording_rate = 48000
# Inside your receive loop:
result = decode_audio_frame(message)
if result is not None:
speaker_id, speaker_name, recording_rate, pcm_bytes = result
audio_buffer.extend(pcm_bytes)
# When the meeting ends:
with wave.open("meeting_recording.wav", "wb") as wf:
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(recording_rate)
wf.writeframes(bytes(audio_buffer))

Resample to a Different Rate (Python)

Many speech-to-text services expect 16 kHz audio. Resample with numpy:

import numpy as np
def resample_pcm16(pcm_bytes: bytes, src_rate: int, dst_rate: int) -> bytes:
if src_rate == dst_rate:
return pcm_bytes
samples = np.frombuffer(pcm_bytes, dtype=np.int16).astype(np.float32)
num_output = int(len(samples) * dst_rate / src_rate)
t_in = np.linspace(0, 1, len(samples), endpoint=False)
t_out = np.linspace(0, 1, num_output, endpoint=False)
resampled = np.interp(t_out, t_in, samples)
return np.clip(resampled, -32768, 32767).astype(np.int16).tobytes()
# Example: frame rate (48 kHz or 32 kHz) → 16 kHz
pcm_16k = resample_pcm16(pcm_bytes, sample_rate, 16000)

Convert to Int16 Array in JavaScript

function pcmBytesToInt16Array(buffer) {
const int16 = new Int16Array(buffer.length / 2);
for (let i = 0; i < int16.length; i++) {
int16[i] = buffer.readInt16LE(i * 2);
}
return int16;
}
function pcmBytesToFloat32Array(buffer) {
const float32 = new Float32Array(buffer.length / 2);
for (let i = 0; i < float32.length; i++) {
float32[i] = buffer.readInt16LE(i * 2) / 32768.0;
}
return float32;
}

Speaker Identification

Each frame includes both a speaker_id and a speaker_name:

FieldDescriptionExample
speaker_idA platform-specific unique identifier. Stable within a session."user_42", "1234567890", "NoSpeaker"
speaker_nameThe display name shown in the meeting UI. May not be unique."Alice", "David Hill", "NoSpeaker"

Platform Behavior

Platformspeaker_idspeaker_name
Google MeetThe participant deviceId, for example spaces/AbCdEf/devices/185Display name in the meeting
ZoomThe Zoom user ID (the number in zoom_user_<id>)Display name in the meeting
TeamsDominant speaker display nameDominant speaker display name

Handling "NoSpeaker"

When no speaker is identified for a frame, both fields are "NoSpeaker", for example in the first moments of a meeting.


Message Types on the Audio Channel

Byte 0TypeFormatDescription
N/AHandshakeJSON textSent once on connect. {"type": "ready", ...}
0x01PCM AudioBinaryGoogle Meet and Teams. Speaker-tagged audio frame at 48 kHz (described above)
0x04PCM Audio with formatBinaryZoom. Speaker-tagged audio frame with the sample rate and channel count in the header

Check byte 0 and skip unknown types, so that your code keeps working if new types are added.


FAQ

Google Meet and Teams: 48,000 Hz. Zoom: 32,000 Hz. Read the rate from the 0x04 header, so that your code also works if the rate changes.

Google Meet: mixed audio, tagged with the active speaker. Teams: mixed audio, tagged with the dominant speaker. When per-participant audio is on, Teams sends per-participant frames. Zoom: one frame for each speaker, with that speaker’s speech only.

Frame sizes vary. Typical frames contain 1,000 to 50,000+ samples (20 ms to 1+ seconds of audio). The size depends on the platform’s audio capture interval and buffering.

Filter on speaker_id or speaker_name after you decode each frame. On Zoom, each frame carries one speaker’s speech. On Google Meet and Teams, frames carry mixed audio tagged with the active or dominant speaker. For one file for each participant after the call, use per-participant audio.

No. The protocol is fire-and-forget. The bot streams continuously and does not expect any response on the audio channel.

Frames will buffer in the WebSocket layer. If the buffer grows too large, the connection may drop. Ensure your receiver processes or discards frames promptly.

The 2-byte length field reflects the byte length of the speaker’s ID string. Different speakers have different name/ID lengths:

  • "Alice" = 5 bytes → sid_length = 0x05 0x00
  • "James Chen" = 10 bytes → sid_length = 0x0A 0x00
  • "Bob" = 3 bytes → sid_length = 0x03 0x00

This is not a delimiter or protocol variation. It is a standard length-prefixed string encoding.

Always read the 2-byte length, then read exactly that many bytes. Never hard-code expected length values. A correct parser:

off = 1 if data[0] == 0x01 else 6 # header length: 0x01 or 0x04
sid_len = int.from_bytes(data[off : off + 2], "little") # read length
speaker_id = data[off + 2 : off + 2 + sid_len].decode("utf-8") # read exactly that many bytes

An incorrect parser:

# BAD: hard-codes an expected "delimiter" byte
if data[1] == 0x09 and data[2] == 0x00:
...

Yes. Speaker names are UTF-8 encoded. A name like "Javier Martínez" is 16 bytes, while "佐藤太郎" is 12 bytes (3 bytes per CJK character). Always use the length prefix. Never scan for fixed byte patterns.

Skip past the headers:

def extract_audio_only(data: bytes) -> bytes:
if len(data) < 5 or data[0] not in (0x01, 0x04):
return b""
off = 1 if data[0] == 0x01 else 6 # 0x04 frames carry rate and channels
sid_len = int.from_bytes(data[off:off + 2], "little")
off += 2 + sid_len
sname_len = int.from_bytes(data[off:off + 2], "little")
off += 2 + sname_len
return data[off:]

The audio is at 48 kHz for 0x01 frames. For 0x04 frames, read the rate from bytes 1 to 4.