From 933214666f4979ebef33fd31079711ddbb83a64a Mon Sep 17 00:00:00 2001 From: Andrei Fedoseev Date: Thu, 12 Nov 2026 19:33:43 +0100 Subject: [PATCH] fix(elevenlabs): send the model given to using() for text to speech --- .../Maps/TextToSpeechRequestMapper.php | 2 +- tests/Providers/ElevenLabs/AudioTest.php | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Providers/ElevenLabs/Maps/TextToSpeechRequestMapper.php b/src/Providers/ElevenLabs/Maps/TextToSpeechRequestMapper.php index 7e7a547d6..11b08d67a 100644 --- a/src/Providers/ElevenLabs/Maps/TextToSpeechRequestMapper.php +++ b/src/Providers/ElevenLabs/Maps/TextToSpeechRequestMapper.php @@ -29,7 +29,7 @@ public function toPayload(): array $voiceSettings = $providerOptions['voice_settings'] ?? []; $supportedOptions = [ - 'model_id' => $providerOptions['model_id'] ?? null, + 'model_id' => $providerOptions['model_id'] ?? ($this->request->model() !== '' ? $this->request->model() : null), 'voice_settings' => [ 'stability' => $voiceSettings['stability'] ?? null, 'use_speaker_boost' => $voiceSettings['use_speaker_boost'] ?? null, diff --git a/tests/Providers/ElevenLabs/AudioTest.php b/tests/Providers/ElevenLabs/AudioTest.php index ecde3caad..9d64d1820 100644 --- a/tests/Providers/ElevenLabs/AudioTest.php +++ b/tests/Providers/ElevenLabs/AudioTest.php @@ -40,6 +40,39 @@ }); }); + it('sends the model given to using() as the model_id', function (): void { + FixtureResponse::fakeResponseSequence( + 'text-to-speech/onwK4e9ZLuTAKqWW03F9', + 'elevenlabs/text-to-speech-basic', + ['Content-Type' => 'audio/wav'] + ); + + Prism::audio() + ->using('elevenlabs', 'eleven_flash_v2_5') + ->withInput('Hello world!') + ->withVoice('onwK4e9ZLuTAKqWW03F9') + ->asAudio(); + + Http::assertSent(fn (Request $request): bool => $request->data()['model_id'] === 'eleven_flash_v2_5'); + }); + + it('lets the model_id provider option win over the model given to using()', function (): void { + FixtureResponse::fakeResponseSequence( + 'text-to-speech/onwK4e9ZLuTAKqWW03F9', + 'elevenlabs/text-to-speech-basic', + ['Content-Type' => 'audio/wav'] + ); + + Prism::audio() + ->using('elevenlabs', 'eleven_flash_v2_5') + ->withInput('Hello world!') + ->withVoice('onwK4e9ZLuTAKqWW03F9') + ->withProviderOptions(['model_id' => 'eleven_multilingual_v2']) + ->asAudio(); + + Http::assertSent(fn (Request $request): bool => $request->data()['model_id'] === 'eleven_multilingual_v2'); + }); + it('can generate audio with different response format', function (): void { FixtureResponse::fakeResponseSequence( 'text-to-speech/onwK4e9ZLuTAKqWW03F9',