You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RedditVideoMakerBot/TTS/elevenlabs.py

53 lines
1.2 KiB

2 years ago
import random
from elevenlabs import generate, save
from utils import settings
voices = [
"Adam",
"Antoni",
"Arnold",
"Bella",
"Domi",
"Elli",
"Josh",
"Rachel",
"Sam",
]
2 years ago
class elevenlabs:
def __init__(self):
self.max_chars = 2500
self.voices = voices
2 years ago
def run(self, text, filepath, random_voice: bool = False):
2 years ago
if random_voice:
voice = self.randomvoice()
else:
else:
voice = str(
settings.config["settings"]["tts"]["elevenlabs_voice_name"]
).capitalize()
2 years ago
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."
)
2 years ago
audio = generate(
api_key=api_key,
text=text,
voice=voice,
2 years ago
model="eleven_monolingual_v1"
)
save(
audio=audio,
filename=filepath
2 years ago
)
def randomvoice(self):
return random.choice(self.voices)