2023-05-15 10:11:04 +02:00
from TTS . api import TTS
# Running a multi-speaker and multi-lingual model
# List available 🐸TTS models and choose the first one
model_best_multi = " tts_models/en/vctk/vits "
fakenames = {
" Alexander " : " p230 " ,
" Benjamin " : " p240 " ,
" Amelia " : " p270 " ,
2023-05-25 21:47:11 +02:00
" Katherine " : " p273 " ,
" Johanne " : " p347 " ,
2023-05-15 10:11:04 +02:00
}
2023-05-25 21:47:11 +02:00
voices = [ " Alexander " , " Benjamin " , " Amelia " , " Katherine " , " Johanne " ]
2023-05-15 10:11:04 +02:00
# Init TTS
def generate_voice ( path , text , speaker = " Alexander " ) :
2023-05-25 21:47:11 +02:00
model = model_best_multi
speaker = fakenames [ speaker ] if speaker in fakenames else speaker
print ( f " Generating voice for { model } with speaker { speaker } " )
2023-05-15 12:32:14 +02:00
try :
2023-05-25 21:47:11 +02:00
tts = TTS ( model , gpu = True )
2023-05-15 12:32:14 +02:00
except :
2023-05-25 21:47:11 +02:00
tts = TTS ( model , gpu = False )
tts . tts_to_file ( text = text , file_path = path , speaker = speaker , speed = 1 , emotion = " Happy " )
if __name__ == " __main__ " :
generate_voice ( " test/test.mp3 " , " This is a test. I like the words python, django and flask. Betty bought a bit of butter but the butter was bitter. So she bought some better butter to make the bitter butter better. " )