From 8b2141be6cdbc96de691cb547896941c98d55e9e Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sun, 18 Oct 2026 14:04:49 -0700 Subject: [PATCH] fix(media): send ElevenLabs TTS text under the field fal requires --- apps/sim/lib/media/falai-audio.ts | 5 ++-- apps/sim/lib/media/falai.test.ts | 38 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/apps/sim/lib/media/falai-audio.ts b/apps/sim/lib/media/falai-audio.ts index f55b27d633d..6754794cb05 100644 --- a/apps/sim/lib/media/falai-audio.ts +++ b/apps/sim/lib/media/falai-audio.ts @@ -55,8 +55,9 @@ function buildInput( ): Record { const input: Record = {} if (type === 'speech') { - // Gemini 3.1 Flash TTS takes the text (with optional inline tags) in `prompt`. - input.prompt = params.prompt + // ElevenLabs TTS requires `text`; Gemini 3.1 Flash TTS takes the text (with optional inline tags) in `prompt`. + if (model.includes('elevenlabs/tts')) input.text = params.prompt + else input.prompt = params.prompt if (params.voice) input.voice = params.voice } else if (type === 'sfx') { // ElevenLabs sound-effects take `text`. diff --git a/apps/sim/lib/media/falai.test.ts b/apps/sim/lib/media/falai.test.ts index 5407736b4d0..abb5c3c231f 100644 --- a/apps/sim/lib/media/falai.test.ts +++ b/apps/sim/lib/media/falai.test.ts @@ -399,3 +399,41 @@ describe('billing a fal generation', () => { expect(onCost).not.toHaveBeenCalled() }) }) + +describe('the speech request fal receives', () => { + beforeEach(() => { + vi.stubEnv('FALAI_API_KEY', 'key') + }) + + /** fal validates the submit body and rejects it; the stub records what was submitted. */ + function stubRejectingFalSubmit() { + const submitted: Array<{ url: string; body: unknown }> = [] + vi.stubGlobal( + 'fetch', + vi.fn(async (url: string, init: RequestInit = {}) => { + submitted.push({ url, body: JSON.parse(String(init.body)) }) + return jsonResponse({ detail: 'rejected by stub' }, 422) + }) + ) + return submitted + } + + it.each([ + ['fal-ai/elevenlabs/tts/eleven-v3', { text: 'Hello there', voice: 'Aria' }], + ['fal-ai/elevenlabs/tts/multilingual-v2', { text: 'Hello there', voice: 'Aria' }], + [undefined, { prompt: 'Hello there', voice: 'Aria' }], + ])('submits the text %s requires', async (model, expectedBody) => { + const submitted = stubRejectingFalSubmit() + + await expect( + generateFalAudio({ prompt: 'Hello there', voice: 'Aria', model, onCost: vi.fn() }) + ).rejects.toThrow() + + expect(submitted).toEqual([ + { + url: `https://queue.fal.run/${model ?? 'fal-ai/gemini-3.1-flash-tts'}`, + body: expectedBody, + }, + ]) + }) +})