Skip to content

Commit 084e2fd

Browse files
committed
pick voice at random from a per-model list
1 parent 5c5f178 commit 084e2fd

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

models/eleven.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import os
2+
import random
3+
24
from elevenlabs import VoiceSettings
35
from elevenlabs.client import ElevenLabs
46

5-
DEFAULT_VOICE = "Xb7hH8MSUJpSbSDYk0k2"
7+
GOOD_VOICES = ["Xb7hH8MSUJpSbSDYk0k2", "XB0fDUnXU5powFXDhCwa", "onwK4e9ZLuTAKqWW03F9", "ThT5KcBeYPX3keUQqHPh"]
68

79

810
class ElevenLabsTTS:
9-
def __init__(self, text: str, output_filename: str, voice: str = DEFAULT_VOICE, _speed: float = 1.0):
11+
def __init__(
12+
self,
13+
text: str,
14+
output_filename: str,
15+
pick_random_voice: bool = False,
16+
voice: str = GOOD_VOICES[0],
17+
_speed: float = 1.0,
18+
):
1019
self.text = text
1120
self.output_filename = output_filename
12-
self.voice = voice
13-
self.model_id = "eleven_turbo_v2_5"
21+
if pick_random_voice:
22+
self.voice = random.choice(GOOD_VOICES)
23+
else:
24+
self.voice = voice
25+
self.model_id = "eleven_flash_v2_5"
1426
self.client = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY"))
1527

1628
def text_to_mp3(self):

models/kokoro.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@
66
from kokoro import KPipeline
77
import soundfile as sf
88

9-
DEFAULT_VOICE = "bf_emma"
9+
GOOD_VOICES = ["bf_emma", "af_bella", "af_nicole"]
1010

1111

1212
class KokoroTTS:
13-
def __init__(self, text: str, output_filename: str, voice: str = DEFAULT_VOICE, speed: float = 1.0):
13+
def __init__(
14+
self,
15+
text: str,
16+
output_filename: str,
17+
pick_random_voice: bool = False,
18+
voice: str = GOOD_VOICES[0],
19+
speed: float = 1.0,
20+
):
1421
self.text = text
1522
self.output_filename = output_filename
16-
self.voice = voice
23+
if pick_random_voice:
24+
self.voice = random.choice(GOOD_VOICES)
25+
else:
26+
self.voice = voice
1727
self.speed = speed
1828
self.wav_files = []
1929

tts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99

1010
def text_to_mp3(text: str, output_mp3: str, model_name: str, speed: float = 1.0):
11-
MODELS[model_name](text, output_mp3, speed=speed).text_to_mp3()
11+
MODELS[model_name](text, output_mp3, speed=speed, pick_random_voice=True).text_to_mp3()

0 commit comments

Comments
 (0)