TTS Providers

OpenAI TTS

Generate voiceover narration using OpenAI's text-to-speech API.

Setup

The OpenAI provider uses the openai npm package as a peer dependency. Install it alongside playwright-recast:

npm install openai

Set your API key as an environment variable:

export OPENAI_API_KEY="sk-..."

Usage

import { Recast } from 'playwright-recast'
import { OpenAIProvider } from 'playwright-recast/providers/openai'

await Recast
  .from('./traces')
  .parse()
  .subtitlesFromSrt('./narration.srt')
  .voiceover(OpenAIProvider({
    voice: 'nova',
    speed: 1.2,
    instructions: 'Professional product demo narration.',
  }))
  .render({ format: 'mp4' })
  .toFile('demo.mp4')

Configuration options

OptionTypeDefaultDescription
voicestring'nova'Voice to use for synthesis
modelstring'gpt-4o-mini-tts'OpenAI TTS model
speednumber1.0Speech speed multiplier
instructionsstringundefinedSystem prompt for voice style and tone
apiKeystringprocess.env.OPENAI_API_KEYAPI key (overrides env variable)

Available voices

OpenAI provides six built-in voices:

VoiceDescription
alloyNeutral, balanced
echoWarm, conversational
fableExpressive, storytelling
onyxDeep, authoritative
novaFriendly, natural
shimmerClear, polished

Instructions

The instructions parameter lets you control the voice style and tone. This maps to OpenAI's system-level instructions for TTS:

OpenAIProvider({
  voice: 'nova',
  instructions: 'Calm, professional demo narration. Speak clearly with moderate pacing.',
})

CLI usage

npx playwright-recast -i ./traces --srt narration.srt --provider openai --voice nova
npx playwright-recast -i ./traces --srt narration.srt --provider openai --voice shimmer --tts-speed 1.2

Environment variable

VariableRequiredDescription
OPENAI_API_KEYYes (unless apiKey is set)Your OpenAI API key

On this page