Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ElevenLabs text-to-speech integration #115645

Merged
merged 30 commits into from
Jul 31, 2024

Conversation

sorgfresser
Copy link
Contributor

Breaking change

Proposed change

Add ElevenLabs as a TTS-integration with support for custom voices and different models.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

Copy link
Contributor

@autinerd autinerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the contribution! Here are a few comments.

homeassistant/components/elevenlabstts/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/elevenlabstts/manifest.json Outdated Show resolved Hide resolved
homeassistant/generated/integrations.json Show resolved Hide resolved
homeassistant/components/elevenlabstts/tts.py Outdated Show resolved Hide resolved
@sorgfresser
Copy link
Contributor Author

Thanks a lot for the review @autinerd
I have added the suggestions and would love to get your opinion on the sync / async part

@sorgfresser
Copy link
Contributor Author

Hey @autinerd, sorry it's been a while, I have finally added the async functionality and made the client an attribute of the entity, thus not generating it every single time

@synesthesiam synesthesiam self-assigned this Apr 24, 2024
@synesthesiam
Copy link
Contributor

@sorgfresser Can you rebase on dev again? I don't think the mypy errors are from you.

@sorgfresser
Copy link
Contributor Author

@synesthesiam thanks for pointing that out! Should be rebased now.

@sorgfresser
Copy link
Contributor Author

There are still some failing pytests, but I'm quite sure they aren't related to this PR either.

except KeyError:
errors[CONF_API_KEY] = "No API-Key provided"
except ApiError:
errors[CONF_API_KEY] = "ElevenLabs API responded with an Error!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors should be keys that refer errors defined in strings.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the error string now.

Comment on lines 13 to 44
"""Set up ElevenLabs text-to-speech from a config entry."""
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate the API key still works before forwarding entry setup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once validated, set the AsynClient as entry.runtime_data to be consumed in tts.py

@synesthesiam
Copy link
Contributor

Tests are now passing locally for me 👍

@sorgfresser
Copy link
Contributor Author

I just bumped elevenlabs and renamed the model accordingly. I verified tests run locally as well as that the integration works as expected as a custom component. Still, the attr_name is an instance attribute as of now. It would be nice to figure out what exactly happens when we move this into a class variable. Somehow the tts does not work with the dynamically created attr_name...

@sorgfresser
Copy link
Contributor Author

Glad to hear that @synesthesiam and same here! I am still wondering why 990c6f2 was necessary though

@sorgfresser
Copy link
Contributor Author

I am not quite sure what's happening to mypy in the CI

@synesthesiam
Copy link
Contributor

The mypy error seems unrelated. I'd keep rebasing on dev and seeing if it fixes itself.

@sorgfresser
Copy link
Contributor Author

I am not sure, but maybe flushing the action caches (https://github.com/home-assistant/core/actions/caches?query=branch%3Arefs%2Fpull%2F115645%2Fmerge) might solve this?

@joostlek
Copy link
Member

I'm thinking that something in the new dependencies is causing this as dev is clean

@synesthesiam
Copy link
Contributor

I think we need to add an ignore line to the mypy config like:

[mypy-traitlets.*]
ignore_missing_imports = True

@joostlek joostlek marked this pull request as ready for review July 31, 2024 18:39
@home-assistant home-assistant bot requested a review from joostlek July 31, 2024 18:39
@joostlek joostlek merged commit 5fefa60 into home-assistant:dev Jul 31, 2024
36 checks passed
@joostlek
Copy link
Member

Can you send your discord username?

@Wazbat
Copy link

Wazbat commented Jul 31, 2024

Awesome to see this merged! Was it completed in time for the release?

@joostlek
Copy link
Member

Yes :)

@sorgfresser
Copy link
Contributor Author

Can you send your discord username?

I am not 100% sure whether you're asking me, if so, it's sorgfresser. If not, please ignore this message.

Btw thank you very much for the constant effort, I am very glad this is merged!

@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2024
@sorgfresser sorgfresser deleted the elevenlabs branch August 3, 2024 10:33
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comment in a new PR. Thanks!

) -> None:
"""Test tts service."""
tts_entity = hass.data[tts.DOMAIN].get_entity(service_data[ATTR_ENTITY_ID])
tts_entity._client.generate.reset_mock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to access the entity to access the client since we've patched the client. Use the client patch mock to assert things about the client.



@pytest.fixture(name="setup")
async def setup_fixture(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this fixture? We only set up via config entry and nothing else.

@home-assistant home-assistant unlocked this conversation Aug 25, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants