🎤Micdrop

OpenAI Speech to Text in Node.js

Real-time speech-to-text implementation using OpenAI’s WebSocket-based real-time transcription API.

Leave out the agent and the voice, and OpenaiSTT alone gives you speech to text with nothing answering back.

OpenAI deprecated gpt-4o-transcribe (the default), gpt-4o-mini-transcribe and whisper-1, which shut down on February 26, 2027. Their replacements, gpt-live-transcribe and gpt-transcribe, work with the same options: language is sent as the list of expected languages these models take. gpt-live-transcribe is recommended for new integrations.

Installation

Terminal window
npm install @micdrop/openai

The same package also provides an agent, a text to speech, the Realtime API and a classifier. The providers page shows what every provider covers.

Usage with MicdropServer

import { OpenaiSTT } from '@micdrop/openai'
import { MicdropServer } from '@micdrop/server'
const stt = new OpenaiSTT({
apiKey: process.env.OPENAI_API_KEY || '',
model: 'gpt-live-transcribe', // Default 'gpt-4o-transcribe', shut down on February 26, 2027
language: 'en', // Optional: specify language for better accuracy
prompt: 'Transcribe the incoming audio in real time.', // Optional: custom prompt
transcriptionTimeout: 4000, // Optional: timeout in ms for transcription
})
// Use with MicdropServer
new MicdropServer(socket, {
stt,
// ... other options
})

Usage without MicdropServer

import { OpenaiSTT } from '@micdrop/openai'
import { createReadStream } from 'fs'
const stt = new OpenaiSTT({
apiKey: process.env.OPENAI_API_KEY || '',
language: 'en',
})
stt.on('Transcript', (text) => console.log('Transcript:', text))
stt.on('Failed', (chunks) => console.error('Failed:', chunks.length, 'chunks'))
// Audio is raw PCM, 16 bits, 16 kHz, mono
stt.transcribe(createReadStream('speech.pcm'))

Events

EventPayloadDescription
TranscriptstringTranscription of one utterance, emitted once per utterance. The text is empty when nothing was recognized in time.
FailedBuffer[]Transcription gave up after its retries, with the audio chunks left pending.

See the STT interface for the full contract.

Options

OptionTypeDefaultDescription
apiKeystringRequiredYour OpenAI API key
modelstring'gpt-4o-transcribe'Real-time transcription model: gpt-live-transcribe and gpt-transcribe, or until February 26, 2027 gpt-4o-transcribe and gpt-4o-mini-transcribe
languagestring'en'Language code for transcription
promptstring'Transcribe the incoming audio in real time.'Custom prompt to guide transcription behavior
connectionTimeoutnumber5000Timeout in milliseconds for WebSocket connection
transcriptionTimeoutnumber4000Timeout in milliseconds to wait for transcription result
retryDelaynumber1000Delay in milliseconds between reconnection attempts
maxRetrynumber3Maximum number of reconnection attempts before failing

The connection opens again whenever it closes, a graceful close included. Each utterance keeps its audio until its transcript arrives, and a new connection receives the audio of every utterance still waiting, so none is lost in between. Once maxRetry attempts in a row failed, Failed hands that audio back, and the next utterance starts the connection over.