File size: 969 Bytes
2e850ab
 
e6ca14c
538626e
2e850ab
edbebd6
496bbeb
 
edbebd6
496bbeb
 
2e850ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
from TTS.api import TTS
import os 
from TTS.utils.manage import ModelManager

os.environ["COQUI_TOS_AGREED"] = "1"
# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2",progress_bar=False).to(device) 

def Text_to_Speech(transcribe_data,lang,voice):
  # List available 🐸TTS models
  print(TTS().list_models())

  # Init TTS
  
  index=1
  voice_list=[]
  # Run TTS
  # ❗ Since this model is multi-lingual voice cloning model, we must set the target speaker_wav and language
  # Text to speech list of amplitude values as output
  # Text to speech to a file
  transcribe_data=list(filter(None,transcribe_data))
  for data in transcribe_data:
    if data is not None:
      if voice is not None:
        file_loc=tts.tts_to_file(text=data, speaker_wav=voice, language=lang, file_path=f"output{index}.wav")
        voice_list.append(file_loc)
        index+=1
  return voice_list