diff --git a/custom_components/elevenlabs_tts/const.py b/custom_components/elevenlabs_tts/const.py index 48bd65a..5bbc5fe 100644 --- a/custom_components/elevenlabs_tts/const.py +++ b/custom_components/elevenlabs_tts/const.py @@ -26,3 +26,5 @@ DEFAULT_STYLE = 0.2 CONF_USE_SPEAKER_BOOST = "use_speaker_boost" DEFAULT_USE_SPEAKER_BOOST = True + +LEGACY_VOICE_SUFFIX = " (Legacy)" diff --git a/custom_components/elevenlabs_tts/elevenlabs.py b/custom_components/elevenlabs_tts/elevenlabs.py index 912ca23..f8b50b5 100644 --- a/custom_components/elevenlabs_tts/elevenlabs.py +++ b/custom_components/elevenlabs_tts/elevenlabs.py @@ -22,6 +22,7 @@ DEFAULT_STYLE, DEFAULT_USE_SPEAKER_BOOST, DEFAULT_VOICE, + LEGACY_VOICE_SUFFIX, ) _LOGGER = logging.getLogger(__name__) @@ -92,20 +93,26 @@ async def post( async def get_voices(self) -> dict: """Get voices from the API.""" - endpoint = "voices" + endpoint = "voices?show_legacy=true" voices = await self.get(endpoint) self._voices = voices.get("voices", []) self.voices = [] for voice in self._voices: - new_voice = Voice(voice_id=voice["voice_id"], name=voice["name"]) + if voice.get("is_legacy"): + name = voice["name"] + LEGACY_VOICE_SUFFIX + else: + name = voice["name"] + new_voice = Voice(voice_id=voice["voice_id"], name=name) self.voices.append(new_voice) return self._voices async def get_voice_by_name_or_id(self, identifier: str) -> dict: """Get a voice by its name or ID.""" + # Remove potential legacy suffix from identifier + identifier = identifier.replace(LEGACY_VOICE_SUFFIX, "") _LOGGER.debug("Looking for voice with identifier %s", identifier) for voice in self._voices: if voice["name"] == identifier or voice["voice_id"] == identifier: diff --git a/tests/test_elevenlabs.py b/tests/test_elevenlabs.py index cac7850..8450961 100644 --- a/tests/test_elevenlabs.py +++ b/tests/test_elevenlabs.py @@ -199,7 +199,10 @@ async def test_get_voices(client): assert voices == mock_response["voices"] # Assert that the request was made with the correct URL and headers - assert respx.calls[0].request.url == "https://api.elevenlabs.io/v1/voices" + assert ( + respx.calls[0].request.url + == "https://api.elevenlabs.io/v1/voices?show_legacy=true" + ) assert respx.calls[0].request.headers["xi-api-key"] == client._api_key # Assert that the client's _voices attribute is updated correctly