-
Notifications
You must be signed in to change notification settings - Fork 14
/
tts.py
32 lines (28 loc) · 1.04 KB
/
tts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from elevenlabs import set_api_key, generate, voices, save
import os
class TTS:
def __init__(self, env):
self.env = env
set_api_key(env['ELEVENLABS_API_KEY'])
self.voices = voices()
self.Paola = self.findVoice(self.voices, "Paola")
self.Arthur = self.findVoice(self.voices, "Arthur")
def findVoice(self, voices, name):
for voice in voices:
if voice.name == name:
return voice
return None
def createAudio(self, text, gender, language="english"):
voice = self.Paola
if gender == "M":
voice = self.Arthur
if language == "english":
audio = generate(
text, voice=voice, model="eleven_monolingual_v1")
fileName = os.path.join('tts-audio-files', 'english.mp3')
else:
audio = generate(
text, voice=voice, model="eleven_multilingual_v1")
fileName = os.path.join('tts-audio-files', language+'.mp3')
save(audio, fileName)
return fileName