Skip to main content

Overview

By the end of this guide, you’ll have a working script that transcribes your microphone live, printing each turn as you speak. Build it with an AI coding agent, or write it yourself — both are below. Prefer to try it first? Transcribe audio without writing any code in the AssemblyAI Playground.
Streaming is billed per sessionStreaming Speech-to-Text is billed on the total duration that your WebSocket connection stays open, not on the amount of audio you send. Always send a termination message when you’re done with a stream — sessions that aren’t closed auto-close after 3 hours and are billed for the full duration. See Billing and pricing for details.

Before you begin

You’ll need:
  • An API key — grab one from your dashboard. Every example below reads it from an environment variable, so set it once:
  • Python 3.8+ or Node.js 18+, depending on which SDK you use.
  • A working microphone — these examples capture live audio from it.
Building with an AI coding agent? Wire it up to AssemblyAI’s live docs (MCP server) and the AssemblyAI skill so it writes correct, up-to-date code instead of relying on stale training data:
Then describe what you want to build. To get the same result as the steps below, paste:

Transcribe streaming audio

Prefer to write it yourself? Follow these steps to stream your microphone live. The AssemblyAI SDK manages the WebSocket connection, microphone capture, and session termination for you.

Step 1: Install the SDK

Step 2: Stream your first session

Save this as transcribe.py (Python) or transcribe.js (JavaScript). It streams your microphone and prints each turn until you press Ctrl+C:
Then run it — python transcribe.py or node transcribe.js — and start speaking. Each turn prints as you talk, and the session closes when you press Ctrl+C:
That’s a full real-time transcriber. Prefer raw WebSockets? See Using the WebSocket API directly below.

What you get back

The transcriber emits JSON messages (the SDK surfaces them as open / turn / close events). The one you handle most is Turn, sent repeatedly as someone speaks — end_of_turn: true marks a finalized turn, and transcript is the text so far:
You also receive a Begin message when the session opens ({ "type": "Begin", "id": "...", "expires_at": ... }) and a Termination message when it closes ({ "type": "Termination", "audio_duration_seconds": 10, "session_duration_seconds": 12 }). Word timings are in milliseconds. See the message sequence breakdown for the full event flow.

Using the WebSocket API directly

Not using an SDK? Connect to the streaming WebSocket at wss://streaming.assemblyai.com/v3/ws directly. Authenticate with your key in the Authorization header (no Bearer prefix), and manage the connection, microphone capture, the Begin / Turn / Termination messages, and session termination yourself — the SDK above does all of this for you. See the message sequence breakdown for the event flow and endpoints and data zones for regional endpoints. Both examples read your key from the same ASSEMBLYAI_API_KEY environment variable you set in Before you begin.
Streaming from a browser?Don’t ship your API key to client-side code. Authenticate from the browser with a short-lived temporary token instead.

Limits

  • Session length: a streaming session auto-closes after 3 hours.
  • Audio: mono 16-bit PCM; set sample_rate to match your source (16 kHz in these examples). Opus is also accepted (encoding=ogg_opus for Ogg streams, encoding=opus for raw packets) — see Sending audio.
  • Rate limit: new-session rate limits scale automatically with usage (default 5 for free accounts). Check yours on the rate limits page.

Next steps

To learn more about Streaming Speech-to-Text, see the following resources:

Need some help?

If you get stuck, or have any other questions, we’d love to help you out. Contact our support team at support@assemblyai.com or create a support ticket.