File size: 860 Bytes
2e850ab
 
 
496bbeb
 
2e850ab
 
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
import torch
from TTS.api import TTS

# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").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