diff --git a/TTS/elevenlabs.py b/TTS/elevenlabs.py new file mode 100644 index 0000000..93c6b5c --- /dev/null +++ b/TTS/elevenlabs.py @@ -0,0 +1,51 @@ +import random + +from elevenlabs import generate, save + +from utils import settings + +voices = [ + "Adam", + "Antoni", + "Arnold", + "Bella", + "Domi", + "Elli", + "Josh", + "Rachel", + "Sam", +] + +class elevenlabs: + def __init__(self): + self.max_chars = 2500 + self.voices = voices + + def run(self, text, filepath, random_voice: bool = False): + if random_voice: + voice = self.randomvoice() + else: + voice = str( + settings.config["settings"]["tts"]["elevenlabs_voice_name"] + ).capitalize() + + if settings.config["settings"]["tts"]["elevenlabs_api_key"]: + api_key = settings.config["settings"]["tts"]["elevenlabs_api_key"] + else: + raise ValueError( + "You didn't set an Elevenlabs API key! Please set the config variable ELEVENLABS_API_KEY to a valid API key." + ) + + audio = generate( + api_key=api_key, + text=text, + voice=voice, + model="eleven_multilingual_v1" + ) + save( + audio=audio, + filename=filepath + ) + + def randomvoice(self): + return random.choice(self.voices) diff --git a/main.py b/main.py index 5624d87..ff76fe4 100755 --- a/main.py +++ b/main.py @@ -132,6 +132,7 @@ if __name__ == "__main__": shutdown() except Exception as err: config["settings"]["tts"]["tiktok_sessionid"] = "REDACTED" + config["settings"]["tts"]["elevenlabs_api_key"] = "REDACTED" print_step( f"Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community.\n" f"Version: {__VERSION__} \n" diff --git a/requirements.txt b/requirements.txt index fcdd273..4459bd1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,5 @@ spacy==3.4.1 torch==1.12.1 transformers==4.25.1 ffmpeg-python==0.2.0 +elevenlabs==0.2.10 yt-dlp==2023.3.4 \ No newline at end of file diff --git a/utils/.config.template.toml b/utils/.config.template.toml index ef2c1c6..c5ec3ba 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -44,8 +44,10 @@ background_thumbnail_font_size = { optional = true, type = "int", default = 96, background_thumbnail_font_color = { optional = true, default = "255,255,255", example = "255,255,255", explanation = "Font color in RGB format for the thumbnail text" } [settings.tts] -voice_choice = { optional = false, default = "streamlabspolly", options = ["streamlabspolly", "tiktok", "googletranslate", "awspolly", "pyttsx", ], example = "tiktok", explanation = "The voice platform used for TTS generation. This can be left blank and you will be prompted to choose at runtime." } +voice_choice = { optional = false, default = "tiktok", options = ["elevenlabs", "streamlabspolly", "tiktok", "googletranslate", "awspolly", "pyttsx", ], example = "tiktok", explanation = "The voice platform used for TTS generation. " } random_voice = { optional = false, default = true, example = true, options = [true, false,], explanation = "Randomizes the voice used for each comment" } +elevenlabs_voice_name = { optional = false, default = "Bella", example = "Bella", explanation = "The voice used for elevenlabs", options = ["Adam", "Antoni", "Arnold", "Bella", "Domi", "Elli", "Josh", "Rachel", "Sam", ] } +elevenlabs_api_key = { optional = true, example = "21f13f91f54d741e2ae27d2ab1b99d59", explanation = "Elevenlabs API key" } aws_polly_voice = { optional = false, default = "Matthew", example = "Matthew", explanation = "The voice used for AWS Polly" } streamlabs_polly_voice = { optional = false, default = "Matthew", example = "Matthew", explanation = "The voice used for Streamlabs Polly" } tiktok_voice = { optional = true, default = "en_us_001", example = "en_us_006", explanation = "The voice used for TikTok TTS" } diff --git a/video_creation/voices.py b/video_creation/voices.py index 425f589..cd75f06 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -7,6 +7,7 @@ from TTS.TikTok import TikTok from TTS.aws_polly import AWSPolly from TTS.engine_wrapper import TTSEngine from TTS.pyttsx import pyttsx +from TTS.elevenlabs import elevenlabs from TTS.streamlabs_polly import StreamlabsPolly from utils import settings from utils.console import print_table, print_step @@ -19,6 +20,7 @@ TTSProviders = { "StreamlabsPolly": StreamlabsPolly, "TikTok": TikTok, "pyttsx": pyttsx, + "ElevenLabs": elevenlabs }