|
|
|
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 = 5000
|
|
|
|
self.voices = voices
|
|
|
|
|
|
|
|
def run(self, text, filepath, random_voice: bool = False):
|
|
|
|
if random_voice:
|
|
|
|
voice = self.randomvoice()
|
|
|
|
else:
|
|
|
|
if not settings.config["settings"]["tts"]["elevenlabs_voice_name"]:
|
|
|
|
print(f"Please set the config variable ELEVENLABS_VOICE_NAME to a valid voice. options are: {voices}. Using 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:
|
|
|
|
api_key = None
|
|
|
|
print("You didn't set an Elevenlabs API key! Trying without API key, but you'll probably hit an error.")
|
|
|
|
|
|
|
|
audio = generate(
|
|
|
|
api_key=api_key,
|
|
|
|
text=text,
|
|
|
|
voice=voice,
|
|
|
|
model="eleven_monolingual_v1"
|
|
|
|
)
|
|
|
|
save(
|
|
|
|
audio=audio,
|
|
|
|
filename=f"{filepath}"
|
|
|
|
)
|
|
|
|
|
|
|
|
def randomvoice(self):
|
|
|
|
return random.choice(self.voices)
|