Repository navigation
Conversation
…h models shut down OpenAI shuts down gpt-4o-mini-tts, tts-1 and tts-1-hd on 6 January 2027, and their successors speak only over the Realtime API. Only the openai entry in synthesisBackends changes: it opens one Realtime session per piece with the existing Effect Socket and Node's WebSocket, and streams the 24 kHz PCM through the existing lamejs loader to MP3. The per-piece key check, size cap and stall timeout are shared with the HTTP backends. A response that does not complete, or a session that closes before response.done, fails the piece. Like xAI and OpenRouter, it sends no word timings: players estimate them from the audio length. Numbers, dates, money, versions and IDs in English text are spelled as words before the model sees them. Digits joined to letters, hyphens, slashes or more digits, such as 1.2s or 3-5, stay as written, so no token is half spelled. With spelled numbers, gpt-realtime-2.1 read every digit and table row in a test on five real replies; the mini model repeated and dropped table rows, so it is not offered. Saved voices and model ids of the retired models fall back to marin and gpt-realtime-2.1. Follow-up to pingdotgg#35910. Custom: no OSS fit. Evaluated: to-words 7.5.1 (MIT), n2words 6.3.1 (MIT), number-to-words 1.2.5 (MIT). Bar failed: appropriate scale. The speller needs English cardinals only, about 15 lines, and a new server package must be proven to load in the single-executable CLI, which needs a full executable build.
daTuzzo
force-pushed
the
fix/openai-read-aloud-realtime
branch
from
November 25, 2026 10:05
e0870b2 to
cef8852
Compare
…fix/openai-read-aloud-realtime
Collaborator
|
I played around with the realtime API and I don't think it'll cut it for TTS, thanks for this though I'll probably remove OpenAI TTS now that I know it'll be deprecated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #35910. This PR targets
feat/read-aloud-providers, so its diff shows only this change. It can be merged into #35910, or retargeted tomainafter #35910 lands, whichever you prefer.Problem
OpenAI shuts down
gpt-4o-mini-tts,tts-1andtts-1-hdon 6 January 2027 (deprecations, text-to-speech guide). Theopenaientry ofsynthesisBackendsfrom #35910 calls/v1/audio/speechwith exactly those three models, so OpenAI read-aloud stops working on that date. Their replacement models speak only through the Realtime API, which has no HTTP speech endpoint.Change
Only the
openaientry insynthesisBackendschanges. Clients, contracts and saved settings stay as they are.apps/server/src/speech/CloudSpeech.ts: the entry opens one Realtime session per text piece atwss://api.openai.com/v1/realtime?model=gpt-realtime-2.1, with the EffectSocketand Node's WebSocket, asDeviceHubProxyalready does. It sendssession.update(audio output only, PCM 24 kHz, the chosen voice, turn detection off, reader instructions), thenresponse.createwithconversation: "none"and the piece wrapped as JSON. It readsresponse.output_audio.deltauntilresponse.doneorerror. The per-piece key check, the 32 MB size cap and the 30 s stall timeout are the sameboundedwrapper the HTTP backends use, now typed for theSpeechSynthesisPartstream from feat(read-aloud): highlight the paragraph and word being read #39836. The socket has a 10 s open timeout and closes when the piece ends or fails.wordTimingsand streams MP3 parts only. The timings route reportsdurationSecondsfrom the MP3 frames once synthesis ends, and players estimate the words over it. Estimated highlighting follows the written text, so it can drift a little around spelled numbers. Word timings from the Realtimeresponse.output_audio_transcript.deltaevents could be a later follow-up.apps/server/src/speech/synthesisAudio.ts:encodeMp3Streamencodes the PCM to MP3 as it arrives, with the existing lamejs loader. A delta that ends inside a sample keeps its odd byte for the next one. The audio route still serves one MP3 stream, and the first audio does not wait for the whole piece.apps/server/src/speech/spokenNumbers.ts: numbers, dates, times, money, percentages, versions, IP addresses and IDs are spelled as English words before the model sees the text. Long unseparated numbers and#references are read digit by digit. Digits joined to letters, hyphens, slashes or more digits (1.2s,3-5,utf-8,12:30pm) stay as written, so a token is never half spelled. This runs only for English text: languageen*, orautowith no letters outside A to Z. Other languages keep their digits.marin(default),cedar,alloy,ash,ballad,coral,echo,sage,shimmer,verse. A saved voice of the old models (fable,onyx,nova) or a saved old model id falls back to the default, so existing settings keep working.speedAppliedByProvideris nowfalsefor OpenAI. The session takes no speed setting, so players speed up playback, as they already do for OpenRouter and ElevenLabs.invalid_api_keygives "rejected the API key",rate_limit_exceededandinsufficient_quotagive "reached a usage limit", and anything else gives "could not generate speech". A response that endsfailed,incompleteorcancelled, or a session that closes beforeresponse.done, fails the stream, so cut-off audio never ends as if complete. Upstream error text never reaches the error message.Only
gpt-realtime-2.1is offered. An earlier comparison on 5 real T3 Code replies (voicemarin, PCM 24 kHz, each audio file run through speech-to-text, each number difference confirmed by two or three speech-to-text models) gave these results:gpt-realtime-2.1-mini, read exactlygpt-realtime-2.1-mini, numbers spelled in codegpt-realtime-2.1, read exactlygpt-realtime-2.1, numbers spelled in code, wording smoothed for listeningThe exact setup of this PR (
gpt-realtime-2.1, exact reading, numbers spelled in code) then ran live on 3 new replies. Every number and every table row came back right. See Verification.Size: 649 changed lines (+543, -106), over the 300-line guide. Tests are 289 of them. The source is 360: 110 for the number speller, 25 for the streaming encoder, and 225 in
CloudSpeech.ts, of which 64 are deleted lines, mostly the old HTTP entry, its model list and the stall wrapper that moved up to be shared. The old HTTP test cases for key locking and CJK splitting now run against xAI, which still speaks over HTTP.Scope
Requested on #35910 (comment): "Everything OpenAI-specific sits in the
openaientry ofsynthesisBackendsinapps/server/src/speech/CloudSpeech.ts, so a follow-up can replace it without touching the clients. Your results on digits and table rows are worth carrying into that follow-up." Without it, OpenAI read-aloud breaks on 6 January 2027.Verification
Tests, with no network and no real key:
src/speech/synthesis.test.ts, "speaks OpenAI replies over Realtime sessions and fails on a provider error": a fake Realtime server on 127.0.0.1 receives the connection through a stubbed global WebSocket. It checks the requested URL, the bearer header, thesession.updateandresponse.createfields, and the spelled text. It sends a tone as two audio deltas split inside a sample, then a cleanresponse.done. The result is 24 kHz MP3, byte for byte the same as the whole tone encoded in one piece. ThroughSpeechSynthesisStreams, the timings answer{ words: [], done: true }withdurationSecondsequal to the 11 MP3 frames of the tone, and the catalog has nowordTimings. A savedgpt-4o-mini-ttsmodel andfablevoice fall back togpt-realtime-2.1andmarin. A Spanish request keeps its digits. Anerrorevent withinvalid_api_keygivesrejected-key, afailedresponse withinsufficient_quotagivesrate-limit, anincompleteresponse givesunavailable, and a session that closes beforeresponse.donegivesunavailable. A session that never answers fails at the 30 s stall timeout. The upstream diagnostic text never reaches the error message.src/speech/spokenNumbers.test.ts: the digits from the measured misreads (35910, 840, 123633), an IP address, versions, an ISO date with a time, money, percentages and grouped numbers.1.2s,1,000ms,2x,3-5,utf-8and12:30pmstay as written, and9:00reads "nine o'clock". Text in Spanish, German and Bulgarian keeps its digits. A markdown table passed throughreadAloudTextkeeps every row and every value in order, with its numbers spelled.status !== "completed"tostatus === "failed"makes the Realtime test fail. Dropping the odd byte thatencodeMp3Streamcarries between deltas makes it fail on the byte comparison. Dropping the encoder's final flush makes it fail only on the timings length (0.168 s instead of 0.264 s).vp test run src/speech/spokenNumbers.test.ts src/speech/synthesis.test.ts src/speech/CloudSpeech.test.ts src/speech/synthesisStreams.test.ts src/speech/synthesisTimings.test.tsinapps/server: 57 passed.vp run check:changed origin/feat/read-aloud-providers --concurrency 1: format, lint, knip, graphql, typecheck of 3 packages and the tests beside the changed files (50 tests in 4 files) all pass.Live check against OpenAI: this branch's dev server ran with an empty data folder and an OpenAI key copied into it. Three made-up replies went through the read-aloud route (
POST /api/voice/synthesis/openai/stream, then the MP3 audio route) with voicemarinand languageauto. The table reply went throughreadAloudTextfirst, as the client does. Each MP3 then went throughwhisper-1.1.2s, a version, an ISO date and a timewhisper-1wrote "bill" for "build" in reply 1, andgpt-transcribeheard "build" in the same file, so that was a transcription error.errorevent withinvalid_api_keyand closes with code 3000. The route answered 422 with reasonrejected-key.{ words: [], done: true, durationSeconds: 12.048 }, the same as the MP3 frame length.gpt-transcribeheard every number correctly.Not checked:
marin, and therate_limit_exceededandinsufficient_quotacodes. The tests coverinsufficient_quotawith a fake server.speedAppliedByProviderisfalse.