← All @molecule/* packages · App templates
@molecule/api-ai-speech-openaiProvider bond · ai-speech · API (Node) · v1.0.1 · Apache-2.0
OpenAI speech provider for molecule.dev — Whisper STT + TTS
npm install @molecule/api-ai-speech-openainpm · Source on GitHub · Implements @molecule/api-ai-speech
@molecule/api-ai-speech-openai is a provider bond on the API (Node) side: it implements the ai-speech core interface (@molecule/api-ai-speech) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { setProvider, requireProvider } from '@molecule/api-ai-speech'
import { provider } from '@molecule/api-ai-speech-openai'
setProvider(provider) // at startup — lazy; reads OPENAI_API_KEY on first use
const speech = requireProvider()
const { audio, contentType } = await speech.synthesize({ input: 'Hello!', voice: 'alloy' })
const { text } = await speech.transcribe!({ audio: buf, model: 'whisper-1' })Works with: @molecule/api-ai-speech, @molecule/api-secrets
Secrets: OPENAI_API_KEY
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
OpenAI ai-speech provider for molecule.dev.
Text-to-speech (tts-1 family) plus Whisper speech-to-text: transcription in the source language and direct speech-to-English translation.
import { setProvider, requireProvider } from '@molecule/api-ai-speech'
import { provider } from '@molecule/api-ai-speech-openai'
setProvider(provider) // at startup — lazy; reads OPENAI_API_KEY on first use
const speech = requireProvider()
const { audio, contentType } = await speech.synthesize({ input: 'Hello!', voice: 'alloy' })
const { text } = await speech.transcribe!({ audio: buf, model: 'whisper-1' })
provider
npm install @molecule/api-ai-speech-openai @molecule/api-ai-speech @molecule/api-secrets
OpenaiSpeechConfigConfiguration for the OpenAI speech provider.
interface OpenaiSpeechConfig {
/** OpenAI API key. Defaults to OPENAI_API_KEY env var. */
apiKey?: string
/** Base URL for the OpenAI API. Defaults to 'https://api.openai.com'. */
baseUrl?: string
/** Default TTS model. Defaults to 'tts-1'. */
defaultTTSModel?: string
/** Default STT model. Defaults to 'whisper-1'. */
defaultSTTModel?: string
/** Default voice for TTS. Defaults to 'alloy'. */
defaultVoice?: string
/** Default audio output format for TTS. Defaults to 'mp3'. */
defaultResponseFormat?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm'
/** Default speech speed for TTS (0.25–4.0). Defaults to 1.0. */
defaultSpeed?: number
}
createProvider(config)Creates an OpenAI speech provider instance.
function createProvider(config?: OpenaiSpeechConfig): AISpeechProvider
config — OpenAI-specific configuration (API key, models, voice, base URL).Returns: An AISpeechProvider backed by OpenAI TTS and Whisper APIs.
aiSpeechOpenaiSecretDefinitionsSecret definitions required by the OpenAI speech bond.
const aiSpeechOpenaiSecretDefinitions: SecretDefinition[]
providerThe provider implementation.
const provider: AISpeechProvider
Implements @molecule/api-ai-speech interface.
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/api-ai-speech'
import { provider } from '@molecule/api-ai-speech-openai'
export function setupAiSpeechOpenai(): void {
setProvider(provider)
}
Peer dependencies:
@molecule/api-ai-speech >=1.0.1@molecule/api-secrets ^1.0.1OPENAI_API_KEY (required) — OpenAI API key
sk-proj-...@molecule/api-ai-speech
@molecule/api-secrets
Wiring: bond the lazy provider export once — setProvider(provider) — or
setProvider(createProvider(config?)) to pass explicit config. Use the core's
setProvider, NOT bond('ai-speech', …) (the core keeps its own singleton).
Subset: implements synthesize, transcribe, and translate. It does NOT
implement synthesizeSpeech/synthesizeStream/listVoices — feature-detect per
the core; pick @molecule/api-ai-speech-elevenlabs for streaming TTS/voice lists.
Config: OPENAI_API_KEY (required, SERVER-side only); OPENAI_BASE_URL (optional)
overrides the API origin, default https://api.openai.com.
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip. The wired provider implements a subset (TTS, STT, or both) — feature-detect and run only the direction(s) it actually exposes:
audio/mpeg) and non-trivial bytes (not a 0-byte file, not a
JSON-encoded blob), and the UI's <audio>/player actually plays it. The
spoken audio reflects the input text you sent.voice/voiceId) or output format (responseFormat/
outputFormat) changes the returned audio (audible voice, Content-Type,
or file extension); an unknown voice/format surfaces a visible error
rather than silently falling back.