add configurable provider in settings.py and update ElevenLabs Api (#2065) (#2074)

This commit is contained in:
Nihar
2025-10-22 21:37:21 +05:30
committed by GitHub
parent c4e8daf50e
commit f448e4a615
7 changed files with 112 additions and 12 deletions

View File

@@ -16,12 +16,25 @@ def test_elevenlabs_text_to_speech_monkeypatched_client(monkeypatch):
class DummyClient:
def __init__(self, api_key):
created["api_key"] = api_key
self.generate_calls = []
self.convert_calls = []
def generate(self, *, text, model, voice):
self.generate_calls.append({"text": text, "model": model, "voice": voice})
yield b"chunk-one"
yield b"chunk-two"
class TextToSpeech:
def __init__(self, outer):
self._outer = outer
def convert(self, *, voice_id, model_id, text, output_format):
self._outer.convert_calls.append(
{
"voice_id": voice_id,
"model_id": model_id,
"text": text,
"output_format": output_format,
}
)
yield b"chunk-one"
yield b"chunk-two"
self.text_to_speech = TextToSpeech(self)
client_module = ModuleType("elevenlabs.client")
client_module.ElevenLabs = DummyClient
@@ -35,8 +48,13 @@ def test_elevenlabs_text_to_speech_monkeypatched_client(monkeypatch):
audio_base64, lang = tts.text_to_speech("Speak")
assert created["api_key"] == "api-key"
assert tts.client.generate_calls == [
{"text": "Speak", "model": "eleven_multilingual_v2", "voice": "Brian"}
assert tts.client.convert_calls == [
{
"voice_id": "nPczCjzI2devNBz1zQrb",
"model_id": "eleven_multilingual_v2",
"text": "Speak",
"output_format": "mp3_44100_128",
}
]
assert lang == "en"
assert base64.b64decode(audio_base64.encode()) == b"chunk-onechunk-two"