Pick a depth. Each prompt opens in your AI pre-loaded with the lesson. Click a row to preview the prompt.
Text is text regardless of how you handle it, but audio has a physical shape — a sample rate, a bit depth, a number of channels — and every one of those numbers has real consequences for a realtime pipeline. Send 16kHz audio to a model expecting 8kHz telephony audio and you get garbled, chipmunked speech. Buffer audio in the wrong chunk size and you either add latency (chunks too big) or overwhelm your network with overhead (chunks too small). Most ASR and TTS providers standardize on 16-bit PCM at 16kHz or 24kHz mono for a reason: it's the smallest representation that still captures intelligible speech without wasting bandwidth. You don't need a signal-processing degree to build voice agents, but you do need to be fluent enough in these numbers that a garbled-audio bug doesn't send you down a two-hour rabbit hole that a single glance at the sample rate would have solved.
This snippet builds a small in-memory PCM buffer, computes how much audio a chunk represents in milliseconds, and shows what happens when a producer and consumer disagree about sample rate.
import struct
SAMPLE_RATE = 16_000 # samples per second, mono
BYTES_PER_SAMPLE = 2 # 16-bit PCM
def ms_of_audio(num_bytes: int, sample_rate: int = SAMPLE_RATE) -> float:
num_samples = num_bytes / BYTES_PER_SAMPLE
return (num_samples / sample_rate) * 1000
def make_silence(duration_ms: int, sample_rate: int = SAMPLE_RATE) -> bytes:
num_samples = int(sample_rate * duration_ms / 1000)
return struct.pack(f"<{num_samples}h", *([0] * num_samples))
chunk = make_silence(20) # a typical 20ms realtime audio chunk
print(f"a 20ms chunk at {SAMPLE_RATE}Hz is {len(chunk)} bytes")
print(f"round trip: {ms_of_audio(len(chunk)):.1f}ms")
# Now the same bytes misread at the wrong sample rate:
print(f"same bytes misread as 8kHz: {ms_of_audio(len(chunk), sample_rate=8_000):.1f}ms")
print("-> a receiver assuming the wrong rate thinks it got twice as much audio,")
print(" which is exactly why mismatched sample rate makes voices sound sped up or slowed down.")python3 main.py