Skip to main content
This guide provides a complete working example of how to use our WebSocket API for real-time audio streaming and transcription.

Sample Project

Below is a complete HTML file that demonstrates:
  • WebSocket connection and authentication
  • Microphone access and audio processing
  • Real-time audio streaming
  • Handling transcription responses
You can save the following two blocks of code as HTML and Javascript files respectively and serve them using a local server to test it directly in your browser:

webSocketClient.html

audioProcessorWorklet.js

Key Features

This sample project demonstrates several important features:
  1. WebSocket Connection: Establishes a secure WebSocket connection with verbose mode enabled
  2. Audio Processing:
    • Captures audio from the microphone
    • Resamples to 16kHz
    • Converts to the correct format (16-bit PCM WAV)
  3. Streaming Protocol:
    • Sends audio in chunks
    • Tracks packet positions
    • Calculates audio volumes
    • Handles final message with final: true
  4. Response Handling:
    • Authentication responses
    • Info messages (in verbose mode)
    • Transcription updates
    • Error handling

Usage

  1. Replace <YOUR_API_KEY> with your actual API key
  2. Replace <YOUR_ACCESS_TOKEN> with your access token
  3. Save the file with a .html extension
  4. Open in a modern web browser
  5. Click “Start Streaming” to begin recording and transcribing
  6. Click “Stop Streaming” to end the session
Make sure you’re using a modern browser that supports the WebAudio API and WebSocket connections. The sample requires HTTPS or localhost for microphone access. Safari is known to handle microphone access differently.