Rehman1603 commited on
Commit
2e850ab
1 Parent(s): ad7ff93

Create Text_to_speech.py

Browse files
Files changed (1) hide show
  1. Text_to_speech.py +28 -0
Text_to_speech.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from TTS.api import TTS
3
+
4
+ tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
5
+ def Text_to_Speech(transcribe_data,lang,voice):
6
+ # Get device
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+
9
+ # List available 🐸TTS models
10
+ print(TTS().list_models())
11
+
12
+ # Init TTS
13
+
14
+ index=1
15
+ voice_list=[]
16
+ # Run TTS
17
+ # ❗ Since this model is multi-lingual voice cloning model, we must set the target speaker_wav and language
18
+ # Text to speech list of amplitude values as output
19
+ # Text to speech to a file
20
+ transcribe_data=list(filter(None,transcribe_data))
21
+ for data in transcribe_data:
22
+ if data is not None:
23
+ if voice is not None:
24
+ file_loc=tts.tts_to_file(text=data, speaker_wav=voice, language=lang, file_path=f"output{index}.wav")
25
+ voice_list.append(file_loc)
26
+ index+=1
27
+ return voice_list
28
+