Skip to content

Move OpenAI text-to-speech to the Realtime API before tts-1 shuts down - #248

Merged
rouges78 merged 2 commits into
mainfrom
openai-tts-realtime
Nov 24, 2026
Merged

rouges78 merged 2 commits into
mainfrom
openai-tts-realtime

Conversation

@rouges78

Copy link
Copy Markdown
Owner

Why

OpenAI shuts down tts-1, tts-1-hd and gpt-4o-mini-tts on 6 January 2027 (deprecations, TTS guide). The named replacement, gpt-realtime-2.1-mini, is not supported on /v1/audio/speech. It only runs through the Realtime API.

Refs #247. That issue only pointed at tts-1-hd in voice-clone.ts. tts-1 was also used in tts-preview.tsx and voice-translator.tsx.

What changed

  • New lib/voice/openai-realtime-tts.ts. It works in three steps:
    1. It calls POST /v1/realtime/client_secrets with the user's key and gets back an ephemeral key, with the session already configured.
    2. It opens wss://api.openai.com/v1/realtime using only the ephemeral key, passed in the subprotocol.
    3. After session.created it sends the text and collects response.output_audio.delta until response.done. The PCM16 24 kHz audio comes back wrapped in a WAV blob.
  • All three call sites now use the new module. The local XTTS clone path in the Voice Translator is unchanged.
  • Voices: fable, nova and onyx only exist for tts-1/tts-1-hd. The pickers now offer Realtime voices instead, including the recommended marin and cedar. Settings saved with the old voices are mapped to verse, coral and ash instead of failing. The three ttsPreviewComp i18n keys were renamed in all 12 locales.
  • Speed: clamped to the Realtime range, 0.25–1.5 (tts-1 allowed up to 4). Duration matching with OpenAI voices now tops out at 1.5x.
  • CSP: added wss://api.openai.com to the Tauri CSP and to the production CSP in middleware.ts. Without it the WebView cannot open the socket.

What reviewers should know

  • Not tested against the live API. The tests use a fake Realtime server built from the documented event shapes. Before merging, someone with a key should run a few lines through the TTS preview and /dubbing.
  • The model is conversational. The session instructions tell it to read the text word for word, but OpenAI says instructions are not guaranteed to be followed. Try lines that look like questions or commands.
  • Output is now WAV instead of MP3, so files are larger. For OpenAI, SynthesisRequest.outputFormat no longer applies.
  • The CSP gained one origin. It is scoped to wss://api.openai.com only.

Checks

  • npm run typecheck: clean
  • npm run i18n:check: no new hardcoded strings (770 = baseline)
  • ESLint on the touched files: no new warnings
  • npx vitest run: 1255 passed, 37 skipped. New tests are in __tests__/lib/voice/openai-realtime-tts.test.ts; the two voice tests that checked /v1/audio/speech were updated.

🤖 Generated with Claude Code

rouges78 and others added 2 commits November 24, 2026 03:49
OpenAI shuts down tts-1, tts-1-hd and gpt-4o-mini-tts on 6 January 2027.
The named replacement, gpt-realtime-2.1-mini, does not work on
/v1/audio/speech and only runs through the Realtime API.

- Add lib/voice/openai-realtime-tts.ts: mints an ephemeral key with the
  user's key, opens the Realtime WebSocket with it, sends the text, and
  wraps the returned PCM16 24 kHz audio in a WAV blob.
- Use it in voice-clone.ts (tts-1-hd), tts-preview.tsx and
  voice-translator.tsx (tts-1). The local XTTS clone path is unchanged.
- Replace the tts-1-only voices (fable, nova, onyx) with Realtime voices
  in the pickers; saved settings that still hold them are mapped to
  verse, coral and ash.
- Clamp speed to the Realtime range (0.25-1.5); duration matching with
  OpenAI voices now tops out at 1.5x.
- Allow wss://api.openai.com in the Tauri and production CSP.

Reported in a GitHub issue. Not yet tested against the live API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rouges78
rouges78 merged commit 794ec5b into main Nov 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant