Skip to content

community:langchain_community:tools:eleven_labs: Fix the tool #27130

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

Conversation

venkatram-dev
Copy link
Contributor

@venkatram-dev venkatram-dev commented Oct 5, 2024

Thank you for contributing to LangChain!

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/langchain_community/tools/eleven_labs/text2speech.py](https://localhost:8080/#) in _run(self, query, run_manager)
     58         try:
---> 59             speech = elevenlabs.generate(text=query, model=self.model)
     60             with tempfile.NamedTemporaryFile(

AttributeError: module 'elevenlabs' has no attribute 'generate'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
3 frames
[/usr/local/lib/python3.10/dist-packages/langchain_community/tools/eleven_labs/text2speech.py](https://localhost:8080/#) in _run(self, query, run_manager)
     64             return f.name
     65         except Exception as e:
---> 66             raise RuntimeError(f"Error while running ElevenLabsText2SpeechTool: {e}")
     67 
     68     def play(self, speech_file: str) -> None:

RuntimeError: Error while running ElevenLabsText2SpeechTool: module 'elevenlabs' has no attribute 'generate'
  • Add tests and docs: If you're adding a new integration, please include
    1. a test for the integration, preferably unit tests that do not rely on network access,
    2. an example notebook showing its use. It lives in docs/docs/integrations directory.

tested using below script

pip install --upgrade elevenlabs langchain-community


import getpass
import os
#ELEVEN_API_KEY = 'aaa'

from langchain_community.tools import ElevenLabsText2SpeechTool

text_to_speak = "Hello world! I am the real slim shady"

#tts = ElevenLabsText2SpeechTool(eleven_api_key=ELEVEN_API_KEY)
tts = ElevenLabsText2SpeechTool()
tts.name
print('tts.name',tts.name)


speech_file = tts.run(text_to_speak)
print('speech_file created')

tts.play(speech_file)
print('played speech file')

# Stream the text as speech
tts.stream_speech("This is a... streaming voice!!")

print('streaming test complete')

Ouput after the change

tts.name eleven_labs_text2speech
speech_file created
played speech file
streaming test complete

Additional guidelines:

  • Make sure optional dependencies are imported within a function.
  • Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests.
  • Most PRs should not touch more than one package.
  • Changes should be backwards compatible.
  • If you are adding something to community, do not re-import it in langchain.

If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

Copy link

vercel bot commented Oct 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Oct 5, 2024 1:34am

@dosubot dosubot bot added size:M bug Related to a bug, vulnerability, unexpected error with an existing feature labels Oct 5, 2024
@venkatram-dev
Copy link
Contributor Author

venkatram-dev commented Oct 5, 2024

Before the change, gives error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/langchain_community/tools/eleven_labs/text2speech.py](https://localhost:8080/#) in _run(self, query, run_manager)
     58         try:
---> 59             speech = elevenlabs.generate(text=query, model=self.model)
     60             with tempfile.NamedTemporaryFile(

AttributeError: module 'elevenlabs' has no attribute 'generate'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
3 frames
[/usr/local/lib/python3.10/dist-packages/langchain_community/tools/eleven_labs/text2speech.py](https://localhost:8080/#) in _run(self, query, run_manager)
     64             return f.name
     65         except Exception as e:
---> 66             raise RuntimeError(f"Error while running ElevenLabsText2SpeechTool: {e}")
     67 
     68     def play(self, speech_file: str) -> None:

RuntimeError: Error while running ElevenLabsText2SpeechTool: module 'elevenlabs' has no attribute 'generate'

After the change works good

pip install --upgrade elevenlabs langchain-community

import getpass
import os
#ELEVEN_API_KEY = 'aaa'

from langchain_community.tools import ElevenLabsText2SpeechTool

text_to_speak = "Hello world! I am the real slim shady"

#tts = ElevenLabsText2SpeechTool(eleven_api_key=ELEVEN_API_KEY)
tts = ElevenLabsText2SpeechTool()
tts.name
print('tts.name',tts.name)


speech_file = tts.run(text_to_speak)
print('speech_file created')

tts.play(speech_file)
print('played speech file')

# Stream the text as speech
tts.stream_speech("This is a... streaming voice!!")

print('streaming test complete')

Ouput after the change

tts.name eleven_labs_text2speech
speech_file created
played speech file
streaming test complete

@venkatram-dev venkatram-dev changed the title fix_community_elevenlabs_tool community:langchain_community:tools:eleven_labs: Fix the tool Oct 5, 2024
@venkatram-dev
Copy link
Contributor Author

Looks like the previous review request comment did not get saved properly. @ccurme , please review.

@efriis
Copy link
Contributor

efriis commented Dec 13, 2024

hey there! This one looks like it might be an interface change on the elevenlabs sdk side, which would be a breaking change in this package for people using this tool with the old sdk

Also, if you're interested in maintaining this integration without us in the loop, we'd love to get an integration package out! Future PRs against langchain would just be {docs updates, as well as registering your package in libs/packages.yml, deprecating this community integration in favor of your integration package}

Here's the guide, and if you have questions, feel free to leave them in the comments on those pages so others can see them! https://python.langchain.com/docs/contributing/how_to/integrations/ <-- this is the right way to handle these kinds of breaking changes moving forward

In the meantime, this change would unfortunately have to be re-implemented in a way that is compatible with both elevenlabs==0.x and elevenlabs==1.x. If you're interested in taking that on, let me know! Otherwise would recommend downgrading to 0.x to get it working

@efriis efriis closed this Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants