File size: 623 Bytes
f6bbb30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import torch
from TTS.api import TTS


class CoquiTTS:
    def __init__(self, speaker_wave_file):
        self.device = "cuda" if torch.cuda.is_available() else "cpu"
        self.tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(self.device)
        self.speaker_wave_file = speaker_wave_file

    def speech_text_and_save_it(self, text, output_path, language = "en"):
        return self.tts.tts_to_file(text = text,
                                    speaker_wav = self.speaker_wave_file,
                                    language = language,
                                    file_path = output_path)