Files
+2 902ff00cb0 chore: release 3.4.0 (#2426)
Co-authored-by: Jason Cameron <git@jasoncameron.dev>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: RequieMa <57754488+RequieMa@users.noreply.github.com>
Co-authored-by: prafful <praffulsharma1230@gmail.com>
Co-authored-by: M. Sanaullah <thebolly@gmail.com>
Co-authored-by: embee <emilien.bev.com@gmail.com>
Co-authored-by: Rodrigo <55567123+rodrigodasilv@users.noreply.github.com>
Co-authored-by: Emilien Bevierre <44171454+emilienbev@users.noreply.github.com>
Co-authored-by: tkhmielnitzky <tkhmielnitzky@gmail.com>
Co-authored-by: bnfone <89687390+bnfone@users.noreply.github.com>
Co-authored-by: Cyteon <129582290+Cyteon@users.noreply.github.com>
2025-10-28 19:53:18 -04:00

39 lines
1.2 KiB
Python

import random
from elevenlabs import save
from elevenlabs.client import ElevenLabs
from utils import settings
class elevenlabs:
def __init__(self):
self.max_chars = 2500
self.client: ElevenLabs = None
def run(self, text, filepath, random_voice: bool = False):
if self.client is None:
self.initialize()
if random_voice:
voice = self.randomvoice()
else:
voice = str(settings.config["settings"]["tts"]["elevenlabs_voice_name"]).capitalize()
audio = self.client.generate(text=text, voice=voice, model="eleven_multilingual_v1")
save(audio=audio, filename=filepath)
def initialize(self):
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."
)
self.client = ElevenLabs(api_key=api_key)
def randomvoice(self):
if self.client is None:
self.initialize()
return random.choice(self.client.voices.get_all().voices).name