Skip to content

Commit

Permalink
Use default voice id as fallback in get_tts_audio (#123624)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorgfresser authored Sep 10, 2024
1 parent 47bcb21 commit dd08a65
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion homeassistant/components/elevenlabs/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def async_get_tts_audio(
"""Load tts audio file from the engine."""
_LOGGER.debug("Getting TTS audio for %s", message)
_LOGGER.debug("Options: %s", options)
voice_id = options[ATTR_VOICE]
voice_id = options.get(ATTR_VOICE, self._default_voice_id)
try:
audio = await self._client.generate(
text=message,
Expand Down
46 changes: 46 additions & 0 deletions tests/components/elevenlabs/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,49 @@ async def test_tts_service_speak_voice_settings(
voice_settings=tts_entity._voice_settings,
optimize_streaming_latency=tts_entity._latency,
)


@pytest.mark.parametrize(
("setup", "tts_service", "service_data"),
[
(
"mock_config_entry_setup",
"speak",
{
ATTR_ENTITY_ID: "tts.mock_title",
tts.ATTR_MEDIA_PLAYER_ENTITY_ID: "media_player.something",
tts.ATTR_MESSAGE: "There is a person at the front door.",
tts.ATTR_OPTIONS: {},
},
),
],
indirect=["setup"],
)
async def test_tts_service_speak_without_options(
setup: AsyncMock,
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
calls: list[ServiceCall],
tts_service: str,
service_data: dict[str, Any],
) -> None:
"""Test service call say with http response 200."""
tts_entity = hass.data[tts.DOMAIN].get_entity(service_data[ATTR_ENTITY_ID])
tts_entity._client.generate.reset_mock()

await hass.services.async_call(
tts.DOMAIN,
tts_service,
service_data,
blocking=True,
)

assert len(calls) == 1
assert (
await retrieve_media(hass, hass_client, calls[0].data[ATTR_MEDIA_CONTENT_ID])
== HTTPStatus.OK
)

tts_entity._client.generate.assert_called_once_with(
text="There is a person at the front door.", voice="voice1", model="model1"
)

0 comments on commit dd08a65

Please sign in to comment.