This repository contains a simple Discord bot that integrates with Eleven Labs' Text-to-Speech API to provide high-quality voice responses in Discord voice channels. The bot supports commands for playing TTS messages, changing voice settings, and managing audio playback.
- Text-to-Speech: Generate and play audio from text using Eleven Labs' API.
- Voice Management: Fetch and cache available voices from Eleven Labs.
- User-Specific Voices: Set and customize voices for individual users.
- Audio Queue: Queue multiple TTS messages for sequential playback.
- Volume Control: Adjust the bot's playback volume.
- Voice Channel Management: Automatically connect, move, and disconnect from voice channels.
- Python 3.8 or higher
- Discord Bot Token
- Eleven Labs API Key
-
Clone the repository:
git clone https://github.com/AlessandroGrassi99/discord-elevenlabs-tts-bot.git cd discord-elevenlabs-tts-bot
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the root directory and add the following:DISCORD_TOKEN=<your_discord_token> ELEVENLABS_API_KEY=<your_elevenlabs_api_key> MY_GUILD=<your_guild_id>
Run the bot using the following command:
python main.py
Plays a text-to-speech response from Eleven Labs.
- Usage:
/say text:<message>
- Description: Converts the provided text into speech and plays it in the voice channel.
Sets the user's preferred voice for TTS.
- Usage:
/voice voice:<voice_name>
- Description: Changes the voice used for the user's TTS messages.
Changes the bot's playback volume.
- Usage:
/volume volume:<percentage>
- Description: Adjusts the playback volume. Accepts values from 0 to 100.
Stops and disconnects the bot from the voice channel.
- Usage:
/stop
- Description: Disconnects the bot from the current voice channel.
Contributions are welcome! Please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE
file for details.
- Discord.py for the Discord API wrapper.
- Loguru for logging.
- Eleven Labs API for the text-to-speech service.