Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/sim/lib/media/falai-audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ function buildInput(
): Record<string, unknown> {
const input: Record<string, unknown> = {}
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`.
Expand Down
38 changes: 38 additions & 0 deletions apps/sim/lib/media/falai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
])
})
})
Loading