mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-27 06:13:07 +00:00
fix(elevenlabs): map wav and pcm TTS formats to 24kHz output formats (#48455)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
768960610b
commit
3beee3cfe9
3 changed files with 31 additions and 3 deletions
|
|
@ -56,9 +56,9 @@ class ElevenLabsTextToSpeechConfig(BaseTextToSpeechConfig):
|
|||
# Response format mappings from OpenAI to ElevenLabs
|
||||
FORMAT_MAPPINGS = {
|
||||
"mp3": "mp3_44100_128",
|
||||
"pcm": "pcm_44100",
|
||||
"pcm": "pcm_24000",
|
||||
"opus": "opus_48000_128",
|
||||
# ElevenLabs does not support WAV, AAC, or FLAC formats.
|
||||
"wav": "wav_24000",
|
||||
}
|
||||
|
||||
ELEVENLABS_QUERY_PARAMS_KEY = "__elevenlabs_query_params__"
|
||||
|
|
|
|||
|
|
@ -314,4 +314,4 @@ class TestElevenLabsTextToSpeechTransformation:
|
|||
)
|
||||
|
||||
assert voice_id in url
|
||||
assert "output_format=pcm_44100" in url
|
||||
assert "output_format=pcm_24000" in url
|
||||
|
|
|
|||
|
|
@ -55,3 +55,31 @@ def test_speech_keeps_an_internal_prefixed_kwarg_out_of_the_elevenlabs_request(r
|
|||
sent: Final = json.loads(respx_mock.calls[0].request.content)
|
||||
assert "_litellm_undeclared_sentinel" not in sent, sent
|
||||
assert sent["text"] == "hi"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("response_format", "expected_output_format"),
|
||||
[("wav", "wav_24000"), ("pcm", "pcm_24000")],
|
||||
)
|
||||
def test_speech_maps_wav_and_pcm_to_elevenlabs_output_formats(
|
||||
respx_mock: respx.MockRouter,
|
||||
response_format: str,
|
||||
expected_output_format: str,
|
||||
) -> None:
|
||||
api_base: Final = "http://localhost:12346"
|
||||
mock_route: Final = respx_mock.post(url__regex=rf"{api_base}/v1/text-to-speech/.*").mock(
|
||||
return_value=httpx.Response(status_code=200, content=b"audio", headers={"content-type": "audio/mpeg"})
|
||||
)
|
||||
|
||||
litellm.speech(
|
||||
model="elevenlabs/eleven_multilingual_v2",
|
||||
input="hi",
|
||||
voice="21m00Tcm4TlvDq8ikWAM",
|
||||
response_format=response_format,
|
||||
api_base=api_base,
|
||||
api_key="fake_elevenlabs_api_key",
|
||||
)
|
||||
|
||||
assert mock_route.called
|
||||
request_url: Final = httpx.URL(str(respx_mock.calls[0].request.url))
|
||||
assert request_url.params["output_format"] == expected_output_format
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue