Skip to main content

Overview

By the end of this guide, you’ll have a working script that transcribes a live internet radio stream, printing each turn as it plays. No microphone required, so it runs anywhere, including a coding agent’s sandbox. 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.
  • Nothing else. The examples pull a public AAC radio stream over HTTP, so no microphone or audio hardware is needed.
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 a live radio URL. The AssemblyAI SDK manages the WebSocket connection 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 about 25 seconds of a live radio URL, prints each turn, then closes the session:
Then run it with python transcribe.py or node transcribe.js. Each turn prints as the audio plays. Terminating finalizes the open turn, so its final transcript prints just before the session ends after about 25 seconds. Because internet radio bursts audio faster than real time, the server may still be catching up when you stop sending, so the last final can arrive a few seconds later than a real-time source like a microphone would show it:
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:
Live radio is continuous speech, so finalized turns arrive at natural pauses. Expect several partial updates before each end_of_turn: true. 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, the audio source, 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 by default; set sample_rate to match your source. These examples use AAC (encoding=aac, ADTS framing). Opus is also accepted (encoding=ogg_opus for Ogg streams, encoding=opus for raw Opus 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.