OpenAIWhisperEngine
OpenAI Whisper API transcription engine.
Note: This is NOT true real-time streaming. OpenAI's Whisper API processes complete audio files, so this engine buffers audio and sends it in chunks rather than doing true low-latency streaming.
This engine is best suited for:
Post-recording transcription
High accuracy requirements
Short audio clips
Example
val engine = OpenAIWhisperEngine(apiKey = "your-openai-api-key")
// Best used with complete recordings
val recording = recorder.getRecording()
recording?.asAudioFlow()?.transcribe(engine)?.collect { result ->
println("Transcription: ${result}")
}Browsers (JS / WasmJS)
OpenAI's API does not send Access-Control-Allow-Origin, so direct calls from a browser are blocked by CORS. Stand up a thin backend that forwards the multipart upload to OpenAI and point endpointUrl at it. Your backend keeps the API key; pass any auth headers it requires via additionalHeaders (and leave apiKey blank if your backend doesn't proxy the bearer token).
val engine = OpenAIWhisperEngine(
apiKey = "",
endpointUrl = "https://my-app.example.com/api/transcribe",
additionalHeaders = headersOf("X-App-Token", "client-secret"),
)Parameters
Your OpenAI API key. Leave empty when proxying through your own backend (see endpointUrl).
The Whisper model to use (default: "whisper-1").
HTTP client for API calls (default: platform createDefaultWhisperHttpClient).
Duration in seconds for each chunk (for streaming mode).
The URL to POST audio chunks to. Defaults to OpenAI's public endpoint; override to point at your own proxy when running in a browser (avoids CORS issues, see GitHub issue #16).
Extra headers appended to every request (useful for proxy authentication tokens, tracing, etc.).
Properties
The engine is available when either an apiKey is configured or the caller has pointed endpointUrl at a custom proxy that supplies its own authentication.
The provider type for this engine.
Functions
Transcribes audio from the given AudioFlow in real-time.