Getting Started
This guide will walk you through setting up and running the AssemblyAI Real-Time Transcription Browser Example. This application captures audio from your microphone and sends it over a WebSocket to AssemblyAI for real-time transcription using Express and the AudioWorklet API.Install dependencies
Install the required dependencies using your preferred package manager:The project requires the following dependencies:
express- Web server frameworkaxios- HTTP client for API requestsdotenv- Environment variable management
Configure your API key
Create a
.env file in the root directory and add your AssemblyAI API key:You can find your API key in your AssemblyAI dashboard. The API key is used to generate temporary tokens for secure WebSocket connections.
Start the server
Start the Express server:The server will start on port 8000. You should see:Open your browser and navigate to
http://localhost:8000.Start recording
Click the Start button on the page to begin recording. Here’s what happens:
- Microphone permission request: The browser will ask for permission to access your microphone
-
Token generation: The client fetches a temporary token from the server:
-
WebSocket connection: A WebSocket connection is established with AssemblyAI:
-
Audio streaming: Audio is captured using the AudioWorklet API at 16kHz sample rate and sent to AssemblyAI in real-time:
-
Transcription display: As AssemblyAI transcribes your speech, the transcription appears on the page:
How It Works
Token Generation
The server generates temporary tokens for secure authentication with AssemblyAI’s real-time API:server.js
generateTempToken function calls AssemblyAI’s token API:
tokenGenerator.js
Audio Processing
The application uses the Web Audio API’s AudioWorklet to process audio at the correct sample rate (16kHz) before sending it to AssemblyAI. Audio chunks are buffered and sent every 100ms to balance latency and network efficiency.Next Steps
Now that you have the basic example running, you can:- Explore the source code to understand the WebSocket message handling
- Customize the UI and add additional features
- Learn more about AssemblyAI’s Real-Time API
- Experiment with different audio configurations and sample rates