3.8 KiB
ElevenLabsText2SpeechTool Documentation
Table of Contents
- Introduction
- Class Overview
- Installation
- Usage
- Exception Handling
- Advanced Usage
- Contributing
- References
1. Introduction
The ElevenLabsText2SpeechTool
is a Python class designed to simplify the process of converting text to speech using the Eleven Labs Text2Speech API. This tool is a wrapper around the API and provides a convenient interface for generating speech from text. It supports multiple languages, making it suitable for a wide range of applications, including voice assistants, audio content generation, and more.
2. Class Overview
Attributes
model
(Union[ElevenLabsModel, str]): The model to use for text to speech. Defaults toElevenLabsModel.MULTI_LINGUAL
.name
(str): The name of the tool. Defaults to"eleven_labs_text2speech"
.description
(str): A brief description of the tool. Defaults to a detailed explanation of its functionality.
3. Installation
To use the ElevenLabsText2SpeechTool
, you need to install the required dependencies and have access to the Eleven Labs Text2Speech API. Follow these steps:
-
Install the
elevenlabs
library:pip install elevenlabs
-
Install the
swarms
librarypip install swarms
-
Set up your API key by following the instructions at Eleven Labs Documentation.
4. Usage
Initialization
To get started, create an instance of the ElevenLabsText2SpeechTool
. You can customize the model
attribute if needed.
from swarms.models import ElevenLabsText2SpeechTool
stt = ElevenLabsText2SpeechTool(model=ElevenLabsModel.MONO_LINGUAL)
Converting Text to Speech
You can use the run
method to convert text to speech. It returns the path to the generated speech file.
speech_file = stt.run("Hello, this is a test.")
Playing and Streaming Speech
- Use the
play
method to play the generated speech file.
stt.play(speech_file)
- Use the
stream_speech
method to stream the text as speech. It plays the speech in real-time.
stt.stream_speech("Hello world!")
5. Exception Handling
The ElevenLabsText2SpeechTool
handles exceptions gracefully. If an error occurs during the conversion process, it raises a RuntimeError
with an informative error message.
6. Advanced Usage
- You can implement custom error handling and logging to further enhance the functionality of this tool.
- For advanced users, extending the class to support additional features or customization is possible.
7. Contributing
Contributions to this tool are welcome. Feel free to open issues, submit pull requests, or provide feedback to improve its functionality and documentation.
8. References
This documentation provides a comprehensive guide to using the ElevenLabsText2SpeechTool
. It covers installation, basic usage, advanced features, and contribution guidelines. Refer to the References section for additional resources.